getting closer?

This commit is contained in:
William Ball 2024-11-20 21:46:51 -08:00
parent ec8579d599
commit 3db7a588ad
10 changed files with 759 additions and 655 deletions

View file

@ -21,32 +21,26 @@ module.exports = grammar({
comment : $ => token(seq('--', /.*/)),
param : $ => $.identifier,
param_block : $ => seq(
'(',
repeat($.param),
field('param', repeat($.identifier)),
':',
$.type,
field('type', $.expr),
')'
),
type : $ => $.expr,
star : $ => "*",
square : $ => choice('□', '[]'),
lambda : $ => choice('λ', 'fun'),
pi : $ => choice('∏', 'forall'),
labs : $ => seq(
$.lambda,
choice('λ', 'fun'),
repeat1($.param_block),
choice('=>', '⇒'),
$.expr,
),
pabs : $ => seq(
$.pi,
choice('∏', 'forall'),
repeat1($.param_block),
',',
$.expr,
@ -82,11 +76,11 @@ module.exports = grammar({
ascription : $ => seq(
':',
$.type,
field('type', $.expr),
),
definition : $ => seq(
$.identifier,
field('name', $.identifier),
repeat($.param_block),
optional($.ascription),
':=',

55
src/grammar.json generated
View file

@ -1,5 +1,4 @@
{
"$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json",
"name": "perga",
"rules": {
"program": {
@ -46,19 +45,27 @@
"value": "("
},
{
"type": "FIELD",
"name": "param",
"content": {
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "expr"
}
},
{
"type": "STRING",
@ -83,7 +90,10 @@
}
]
},
"lambda": {
"labs": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
@ -96,26 +106,6 @@
}
]
},
"pi": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "∏"
},
{
"type": "STRING",
"value": "forall"
}
]
},
"labs": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "lambda"
},
{
"type": "REPEAT1",
"content": {
@ -146,8 +136,17 @@
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "pi"
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "∏"
},
{
"type": "STRING",
"value": "forall"
}
]
},
{
"type": "REPEAT1",
@ -279,17 +278,25 @@
"value": ":"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "expr"
}
}
]
},
"definition": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "REPEAT",

60
src/node-types.json generated
View file

@ -59,8 +59,8 @@
{
"type": "ascription",
"named": true,
"fields": {},
"children": {
"fields": {
"type": {
"multiple": false,
"required": true,
"types": [
@ -70,11 +70,23 @@
}
]
}
}
},
{
"type": "definition",
"named": true,
"fields": {},
"fields": {
"name": {
"multiple": false,
"required": true,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
"children": {
"multiple": true,
"required": true,
@ -91,10 +103,6 @@
"type": "expr",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "param_block",
"named": true
@ -133,10 +141,6 @@
"type": "expr",
"named": true
},
{
"type": "lambda",
"named": true
},
{
"type": "param_block",
"named": true
@ -144,11 +148,6 @@
]
}
},
{
"type": "lambda",
"named": true,
"fields": {}
},
{
"type": "pabs",
"named": true,
@ -164,10 +163,6 @@
{
"type": "param_block",
"named": true
},
{
"type": "pi",
"named": true
}
]
}
@ -175,31 +170,32 @@
{
"type": "param_block",
"named": true,
"fields": {},
"children": {
"fields": {
"param": {
"multiple": true,
"required": true,
"required": false,
"types": [
{
"type": "expr",
"named": true
},
{
"type": "identifier",
"named": true
}
]
}
},
"type": {
"multiple": false,
"required": true,
"types": [
{
"type": "pi",
"named": true,
"fields": {}
"type": "expr",
"named": true
}
]
}
}
},
{
"type": "program",
"named": true,
"root": true,
"fields": {},
"children": {
"multiple": true,

1011
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -12,10 +12,10 @@ extern "C" {
// Allow clients to override allocation functions
#ifdef TREE_SITTER_REUSE_ALLOCATOR
extern void *(*ts_current_malloc)(size_t size);
extern void *(*ts_current_calloc)(size_t count, size_t size);
extern void *(*ts_current_realloc)(void *ptr, size_t size);
extern void (*ts_current_free)(void *ptr);
extern void *(*ts_current_malloc)(size_t);
extern void *(*ts_current_calloc)(size_t, size_t);
extern void *(*ts_current_realloc)(void *, size_t);
extern void (*ts_current_free)(void *);
#ifndef ts_malloc
#define ts_malloc ts_current_malloc

View file

@ -10,15 +10,20 @@ foo (A B : *) (f : A -> A -> B) (x : A) := f x x;
(definition
(identifier)
(param_block
(identifier)
(identifier)
(param
(identifier))
(param
(identifier))
(type
(expr
(app_term
(app
(term
(star))))))
(star)))))))
(param_block
(identifier)
(param
(identifier))
(type
(expr
(arrow
(app_term
@ -35,14 +40,16 @@ foo (A B : *) (f : A -> A -> B) (x : A) := f x x;
(app_term
(app
(term
(identifier))))))))))
(identifier)))))))))))
(param_block
(identifier)
(param
(identifier))
(type
(expr
(app_term
(app
(term
(identifier))))))
(identifier)))))))
(expr
(app_term
(app

View file

@ -10,9 +10,10 @@ nat : * := axiom;
(definition
(identifier)
(ascription
(type
(expr
(app_term
(app
(term
(star))))))
(star)))))))
(axiom)))

View file

@ -14,19 +14,23 @@ foo := fun (A : *) (x : A) => x;
(labs
(lambda)
(param_block
(identifier)
(param
(identifier))
(type
(expr
(app_term
(app
(term
(star))))))
(star)))))))
(param_block
(identifier)
(param
(identifier))
(type
(expr
(app_term
(app
(term
(identifier))))))
(identifier)))))))
(expr
(app_term
(app

View file

@ -14,19 +14,23 @@ rel := forall (A : *) (x : A), *;
(pabs
(pi)
(param_block
(identifier)
(param
(identifier))
(type
(expr
(app_term
(app
(term
(star))))))
(star)))))))
(param_block
(identifier)
(param
(identifier))
(type
(expr
(app_term
(app
(term
(identifier))))))
(identifier)))))))
(expr
(app_term
(app

View file

@ -10,21 +10,27 @@ foo (A : *) (x y z : A) := x;
(definition
(identifier)
(param_block
(identifier)
(param
(identifier))
(type
(expr
(app_term
(app
(term
(star))))))
(star)))))))
(param_block
(identifier)
(identifier)
(identifier)
(expr
(app_term
(app
(term
(identifier))))))
(param
(identifier))
(param
(identifier))
(param
(identifier))
(type
(expr
(app_term
(app
(term
(identifier)))))))
(expr
(app_term
(app