support experimental lightweight function syntax
This commit is contained in:
parent
483fa6ec49
commit
63f0f27240
5 changed files with 3514 additions and 4756 deletions
17
grammar.js
17
grammar.js
|
|
@ -27,7 +27,7 @@ module.exports = grammar({
|
||||||
)),
|
)),
|
||||||
|
|
||||||
identifier : $ => /[a-zA-Z_]\w*/,
|
identifier : $ => /[a-zA-Z_]\w*/,
|
||||||
symbol : $ => /[!@#$%^&*-+=<>,./?\[\]{}\\|`~'\"∧∨⊙×≅]+/,
|
symbol : $ => /[!@#$%^&*-+=<>,./?{}\\|`~'\"∧∨⊙×≅]+/,
|
||||||
|
|
||||||
comment : $ => token(seq('--', /.*/)),
|
comment : $ => token(seq('--', /.*/)),
|
||||||
|
|
||||||
|
|
@ -75,15 +75,22 @@ module.exports = grammar({
|
||||||
labs : $ => seq(
|
labs : $ => seq(
|
||||||
choice('λ', 'fun'),
|
choice('λ', 'fun'),
|
||||||
repeat1($.param_block),
|
repeat1($.param_block),
|
||||||
optional($.ascription),
|
|
||||||
choice('=>', '⇒'),
|
choice('=>', '⇒'),
|
||||||
$.expr,
|
$.expr,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
labs_alt : $ => seq(
|
||||||
|
'[',
|
||||||
|
field('param', repeat1($.identifier)),
|
||||||
|
':',
|
||||||
|
field('type', $.expr),
|
||||||
|
']',
|
||||||
|
$.expr,
|
||||||
|
),
|
||||||
|
|
||||||
pabs : $ => seq(
|
pabs : $ => seq(
|
||||||
choice('∏', 'forall'),
|
choice('∏', 'forall'),
|
||||||
repeat1($.param_block),
|
repeat1($.param_block),
|
||||||
optional($.ascription),
|
|
||||||
',',
|
',',
|
||||||
$.expr,
|
$.expr,
|
||||||
),
|
),
|
||||||
|
|
@ -103,7 +110,8 @@ module.exports = grammar({
|
||||||
|
|
||||||
// HACK:
|
// HACK:
|
||||||
// completely ignore precedence and associativity for treesitter
|
// completely ignore precedence and associativity for treesitter
|
||||||
// this is enough to get the syntax highlighting right
|
// the syntax tree is completely wrong, but it's good enough for syntax
|
||||||
|
// highlighting
|
||||||
binex : $ => seq(
|
binex : $ => seq(
|
||||||
$.app,
|
$.app,
|
||||||
optional(seq($.symbol, $.binex)),
|
optional(seq($.symbol, $.binex)),
|
||||||
|
|
@ -137,6 +145,7 @@ module.exports = grammar({
|
||||||
|
|
||||||
app_term : $ => choice(
|
app_term : $ => choice(
|
||||||
$.labs,
|
$.labs,
|
||||||
|
$.labs_alt,
|
||||||
$.pabs,
|
$.pabs,
|
||||||
$.let,
|
$.let,
|
||||||
$.binex,
|
$.binex,
|
||||||
|
|
|
||||||
70
src/grammar.json
generated
70
src/grammar.json
generated
|
|
@ -39,7 +39,7 @@
|
||||||
},
|
},
|
||||||
"symbol": {
|
"symbol": {
|
||||||
"type": "PATTERN",
|
"type": "PATTERN",
|
||||||
"value": "[!@#$%^&*-+=<>,./?\\[\\]{}\\\\|`~'\\\"∧∨⊙×≅]+"
|
"value": "[!@#$%^&*-+=<>,./?{}\\\\|`~'\\\"∧∨⊙×≅]+"
|
||||||
},
|
},
|
||||||
"comment": {
|
"comment": {
|
||||||
"type": "TOKEN",
|
"type": "TOKEN",
|
||||||
|
|
@ -288,18 +288,6 @@
|
||||||
"name": "param_block"
|
"name": "param_block"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "ascription"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "BLANK"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "CHOICE",
|
"type": "CHOICE",
|
||||||
"members": [
|
"members": [
|
||||||
|
|
@ -319,6 +307,46 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"labs_alt": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "["
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "FIELD",
|
||||||
|
"name": "param",
|
||||||
|
"content": {
|
||||||
|
"type": "REPEAT1",
|
||||||
|
"content": {
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "identifier"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": ":"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "FIELD",
|
||||||
|
"name": "type",
|
||||||
|
"content": {
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "expr"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "expr"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"pabs": {
|
"pabs": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
|
|
@ -342,18 +370,6 @@
|
||||||
"name": "param_block"
|
"name": "param_block"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "ascription"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "BLANK"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "STRING",
|
||||||
"value": ","
|
"value": ","
|
||||||
|
|
@ -552,6 +568,10 @@
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "labs"
|
"name": "labs"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "labs_alt"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "pabs"
|
"name": "pabs"
|
||||||
|
|
|
||||||
56
src/node-types.json
generated
56
src/node-types.json
generated
|
|
@ -30,6 +30,10 @@
|
||||||
"type": "labs",
|
"type": "labs",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "labs_alt",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "let",
|
"type": "let",
|
||||||
"named": true
|
"named": true
|
||||||
|
|
@ -244,10 +248,6 @@
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": true,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
{
|
|
||||||
"type": "ascription",
|
|
||||||
"named": true
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "expr",
|
"type": "expr",
|
||||||
"named": true
|
"named": true
|
||||||
|
|
@ -259,6 +259,42 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "labs_alt",
|
||||||
|
"named": true,
|
||||||
|
"fields": {
|
||||||
|
"param": {
|
||||||
|
"multiple": true,
|
||||||
|
"required": true,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "identifier",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"multiple": false,
|
||||||
|
"required": true,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "expr",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"children": {
|
||||||
|
"multiple": false,
|
||||||
|
"required": true,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "expr",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "let",
|
"type": "let",
|
||||||
"named": true,
|
"named": true,
|
||||||
|
|
@ -301,10 +337,6 @@
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": true,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
{
|
|
||||||
"type": "ascription",
|
|
||||||
"named": true
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "expr",
|
"type": "expr",
|
||||||
"named": true
|
"named": true
|
||||||
|
|
@ -539,10 +571,18 @@
|
||||||
"type": "=>",
|
"type": "=>",
|
||||||
"named": false
|
"named": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "[",
|
||||||
|
"named": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "[]",
|
"type": "[]",
|
||||||
"named": false
|
"named": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "]",
|
||||||
|
"named": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "axiom",
|
"type": "axiom",
|
||||||
"named": false
|
"named": false
|
||||||
|
|
|
||||||
8078
src/parser.c
generated
8078
src/parser.c
generated
File diff suppressed because it is too large
Load diff
|
|
@ -2,7 +2,8 @@
|
||||||
Lambda Abstraction
|
Lambda Abstraction
|
||||||
==================
|
==================
|
||||||
|
|
||||||
def foo := fun (A : ★) (x : A) : A => x;
|
def foo := fun (A B : ★) (x : A) (y : B) => x;
|
||||||
|
def bar := [A B : ★][x : A][y : B] x;
|
||||||
|
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
|
@ -13,6 +14,7 @@ def foo := fun (A : ★) (x : A) : A => x;
|
||||||
(app_term
|
(app_term
|
||||||
(labs
|
(labs
|
||||||
(param_block
|
(param_block
|
||||||
|
(identifier)
|
||||||
(identifier)
|
(identifier)
|
||||||
(expr
|
(expr
|
||||||
(app_term
|
(app_term
|
||||||
|
|
@ -29,7 +31,8 @@ def foo := fun (A : ★) (x : A) : A => x;
|
||||||
(app
|
(app
|
||||||
(term
|
(term
|
||||||
(identifier)))))))
|
(identifier)))))))
|
||||||
(ascription
|
(param_block
|
||||||
|
(identifier)
|
||||||
(expr
|
(expr
|
||||||
(app_term
|
(app_term
|
||||||
(binex
|
(binex
|
||||||
|
|
@ -41,4 +44,44 @@ def foo := fun (A : ★) (x : A) : A => x;
|
||||||
(binex
|
(binex
|
||||||
(app
|
(app
|
||||||
(term
|
(term
|
||||||
(identifier)))))))))))
|
(identifier))))))))))
|
||||||
|
(definition
|
||||||
|
(identifier)
|
||||||
|
(expr
|
||||||
|
(app_term
|
||||||
|
(labs_alt
|
||||||
|
(identifier)
|
||||||
|
(identifier)
|
||||||
|
(expr
|
||||||
|
(app_term
|
||||||
|
(binex
|
||||||
|
(app
|
||||||
|
(term
|
||||||
|
(sort
|
||||||
|
(star)))))))
|
||||||
|
(expr
|
||||||
|
(app_term
|
||||||
|
(labs_alt
|
||||||
|
(identifier)
|
||||||
|
(expr
|
||||||
|
(app_term
|
||||||
|
(binex
|
||||||
|
(app
|
||||||
|
(term
|
||||||
|
(identifier))))))
|
||||||
|
(expr
|
||||||
|
(app_term
|
||||||
|
(labs_alt
|
||||||
|
(identifier)
|
||||||
|
(expr
|
||||||
|
(app_term
|
||||||
|
(binex
|
||||||
|
(app
|
||||||
|
(term
|
||||||
|
(identifier))))))
|
||||||
|
(expr
|
||||||
|
(app_term
|
||||||
|
(binex
|
||||||
|
(app
|
||||||
|
(term
|
||||||
|
(identifier)))))))))))))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue