getting closer?
This commit is contained in:
parent
ec8579d599
commit
3db7a588ad
10 changed files with 759 additions and 655 deletions
18
grammar.js
18
grammar.js
|
|
@ -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),
|
||||
':=',
|
||||
|
|
|
|||
87
src/grammar.json
generated
87
src/grammar.json
generated
|
|
@ -1,5 +1,4 @@
|
|||
{
|
||||
"$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json",
|
||||
"name": "perga",
|
||||
"rules": {
|
||||
"program": {
|
||||
|
|
@ -46,10 +45,14 @@
|
|||
"value": "("
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"type": "FIELD",
|
||||
"name": "param",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -57,8 +60,12 @@
|
|||
"value": ":"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expr"
|
||||
"type": "FIELD",
|
||||
"name": "type",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "expr"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
|
|
@ -83,38 +90,21 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"lambda": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "λ"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "fun"
|
||||
}
|
||||
]
|
||||
},
|
||||
"pi": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "∏"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "forall"
|
||||
}
|
||||
]
|
||||
},
|
||||
"labs": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "lambda"
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "λ"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "fun"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "REPEAT1",
|
||||
|
|
@ -146,8 +136,17 @@
|
|||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "pi"
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "∏"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "forall"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "REPEAT1",
|
||||
|
|
@ -279,8 +278,12 @@
|
|||
"value": ":"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expr"
|
||||
"type": "FIELD",
|
||||
"name": "type",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "expr"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
@ -288,8 +291,12 @@
|
|||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
"type": "FIELD",
|
||||
"name": "name",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
|
|
|
|||
92
src/node-types.json
generated
92
src/node-types.json
generated
|
|
@ -59,22 +59,34 @@
|
|||
{
|
||||
"type": "ascription",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expr",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
"fields": {
|
||||
"type": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expr",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"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": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expr",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
"fields": {
|
||||
"param": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "expr",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "pi",
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "program",
|
||||
"named": true,
|
||||
"root": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
|
|
|
|||
1011
src/parser.c
generated
1011
src/parser.c
generated
File diff suppressed because it is too large
Load diff
8
src/tree_sitter/alloc.h
generated
8
src/tree_sitter/alloc.h
generated
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -7,48 +7,55 @@ foo (A B : *) (f : A -> A -> B) (x : A) := f x x;
|
|||
---
|
||||
|
||||
(program
|
||||
(definition
|
||||
(identifier)
|
||||
(param_block
|
||||
(identifier)
|
||||
(identifier)
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(star))))))
|
||||
(param_block
|
||||
(identifier)
|
||||
(expr
|
||||
(arrow
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(identifier))))
|
||||
(expr
|
||||
(arrow
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(identifier))))
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(identifier))))))))))
|
||||
(param_block
|
||||
(identifier)
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(identifier))))))
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(identifier))
|
||||
(term
|
||||
(identifier))
|
||||
(term
|
||||
(identifier)))))))
|
||||
(definition
|
||||
(identifier)
|
||||
(param_block
|
||||
(param
|
||||
(identifier))
|
||||
(param
|
||||
(identifier))
|
||||
(type
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(star)))))))
|
||||
(param_block
|
||||
(param
|
||||
(identifier))
|
||||
(type
|
||||
(expr
|
||||
(arrow
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(identifier))))
|
||||
(expr
|
||||
(arrow
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(identifier))))
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(identifier)))))))))))
|
||||
(param_block
|
||||
(param
|
||||
(identifier))
|
||||
(type
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(identifier)))))))
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(identifier))
|
||||
(term
|
||||
(identifier))
|
||||
(term
|
||||
(identifier)))))))
|
||||
|
|
|
|||
|
|
@ -10,9 +10,10 @@ nat : * := axiom;
|
|||
(definition
|
||||
(identifier)
|
||||
(ascription
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(star))))))
|
||||
(type
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(star)))))))
|
||||
(axiom)))
|
||||
|
|
|
|||
|
|
@ -14,19 +14,23 @@ foo := fun (A : *) (x : A) => x;
|
|||
(labs
|
||||
(lambda)
|
||||
(param_block
|
||||
(identifier)
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(star))))))
|
||||
(param
|
||||
(identifier))
|
||||
(type
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(star)))))))
|
||||
(param_block
|
||||
(identifier)
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(identifier))))))
|
||||
(param
|
||||
(identifier))
|
||||
(type
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(identifier)))))))
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
|
|
|
|||
|
|
@ -14,19 +14,23 @@ rel := forall (A : *) (x : A), *;
|
|||
(pabs
|
||||
(pi)
|
||||
(param_block
|
||||
(identifier)
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(star))))))
|
||||
(param
|
||||
(identifier))
|
||||
(type
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(star)))))))
|
||||
(param_block
|
||||
(identifier)
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(identifier))))))
|
||||
(param
|
||||
(identifier))
|
||||
(type
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(identifier)))))))
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
|
|
|
|||
|
|
@ -10,21 +10,27 @@ foo (A : *) (x y z : A) := x;
|
|||
(definition
|
||||
(identifier)
|
||||
(param_block
|
||||
(identifier)
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(star))))))
|
||||
(param
|
||||
(identifier))
|
||||
(type
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(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
|
||||
|
|
|
|||
Loading…
Reference in a new issue