new syntax, also block comments are totally broken
This commit is contained in:
parent
6e1878db5d
commit
6de6e3d801
13 changed files with 1786 additions and 1761 deletions
27
grammar.js
27
grammar.js
|
|
@ -12,30 +12,17 @@ module.exports = grammar({
|
||||||
|
|
||||||
extras: $ => [
|
extras: $ => [
|
||||||
$.comment,
|
$.comment,
|
||||||
$.block_comment,
|
|
||||||
/\s/,
|
/\s/,
|
||||||
],
|
],
|
||||||
|
|
||||||
rules: {
|
rules: {
|
||||||
|
|
||||||
program : $ => repeat(choice($.definition, $.preprocess)),
|
program : $ => repeat(choice($.definition, $.preprocess, $.axiom)),
|
||||||
|
|
||||||
identifier : $ => /[a-zA-Z_]\w*/,
|
identifier : $ => /[a-zA-Z_]\w*/,
|
||||||
|
|
||||||
comment : $ => token(seq('--', /.*/)),
|
comment : $ => token(seq('--', /.*/)),
|
||||||
|
|
||||||
block_comment: $ => token(seq(
|
|
||||||
'[*',
|
|
||||||
repeat(choice(
|
|
||||||
/[^\[\]*]/,
|
|
||||||
/\[[^*]/,
|
|
||||||
/\*[^\]]/,
|
|
||||||
/\[\*/,
|
|
||||||
/\*\]/,
|
|
||||||
)),
|
|
||||||
'*]'
|
|
||||||
)),
|
|
||||||
|
|
||||||
param_block : $ => seq(
|
param_block : $ => seq(
|
||||||
'(',
|
'(',
|
||||||
field('param', repeat1($.identifier)),
|
field('param', repeat1($.identifier)),
|
||||||
|
|
@ -72,6 +59,7 @@ module.exports = grammar({
|
||||||
'(',
|
'(',
|
||||||
$.identifier,
|
$.identifier,
|
||||||
repeat($.param_block),
|
repeat($.param_block),
|
||||||
|
optional($.ascription),
|
||||||
':=',
|
':=',
|
||||||
$.expr,
|
$.expr,
|
||||||
')',
|
')',
|
||||||
|
|
@ -112,12 +100,21 @@ module.exports = grammar({
|
||||||
field('type', $.expr),
|
field('type', $.expr),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
axiom : $ => seq(
|
||||||
|
'axiom',
|
||||||
|
field('name', $.identifier),
|
||||||
|
repeat($.param_block),
|
||||||
|
$.ascription,
|
||||||
|
';'
|
||||||
|
),
|
||||||
|
|
||||||
definition : $ => seq(
|
definition : $ => seq(
|
||||||
|
'def',
|
||||||
field('name', $.identifier),
|
field('name', $.identifier),
|
||||||
repeat($.param_block),
|
repeat($.param_block),
|
||||||
optional($.ascription),
|
optional($.ascription),
|
||||||
':=',
|
':=',
|
||||||
choice($.expr, $.axiom),
|
choice($.expr),
|
||||||
';',
|
';',
|
||||||
),
|
),
|
||||||
|
|
||||||
|
|
|
||||||
104
src/grammar.json
generated
104
src/grammar.json
generated
|
|
@ -13,6 +13,10 @@
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "preprocess"
|
"name": "preprocess"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "axiom"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -37,50 +41,6 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"block_comment": {
|
|
||||||
"type": "TOKEN",
|
|
||||||
"content": {
|
|
||||||
"type": "SEQ",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "STRING",
|
|
||||||
"value": "[*"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "REPEAT",
|
|
||||||
"content": {
|
|
||||||
"type": "CHOICE",
|
|
||||||
"members": [
|
|
||||||
{
|
|
||||||
"type": "PATTERN",
|
|
||||||
"value": "[^\\[\\]*]"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "PATTERN",
|
|
||||||
"value": "\\[[^*]"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "PATTERN",
|
|
||||||
"value": "\\*[^\\]]"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "PATTERN",
|
|
||||||
"value": "\\[\\*"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "PATTERN",
|
|
||||||
"value": "\\*\\]"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "STRING",
|
|
||||||
"value": "*]"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"param_block": {
|
"param_block": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
|
|
@ -261,6 +221,18 @@
|
||||||
"name": "param_block"
|
"name": "param_block"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "ascription"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "BLANK"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "STRING",
|
||||||
"value": ":="
|
"value": ":="
|
||||||
|
|
@ -311,8 +283,36 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"axiom": {
|
"axiom": {
|
||||||
"type": "STRING",
|
"type": "SEQ",
|
||||||
"value": "axiom"
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "axiom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "FIELD",
|
||||||
|
"name": "name",
|
||||||
|
"content": {
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "identifier"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "REPEAT",
|
||||||
|
"content": {
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "param_block"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "ascription"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": ";"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"arrow": {
|
"arrow": {
|
||||||
"type": "PREC_LEFT",
|
"type": "PREC_LEFT",
|
||||||
|
|
@ -398,6 +398,10 @@
|
||||||
"definition": {
|
"definition": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "def"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "FIELD",
|
"type": "FIELD",
|
||||||
"name": "name",
|
"name": "name",
|
||||||
|
|
@ -435,10 +439,6 @@
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "expr"
|
"name": "expr"
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "axiom"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -475,10 +475,6 @@
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "comment"
|
"name": "comment"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "block_comment"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "PATTERN",
|
"type": "PATTERN",
|
||||||
"value": "\\s"
|
"value": "\\s"
|
||||||
|
|
|
||||||
52
src/node-types.json
generated
52
src/node-types.json
generated
|
|
@ -76,6 +76,36 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "axiom",
|
||||||
|
"named": true,
|
||||||
|
"fields": {
|
||||||
|
"name": {
|
||||||
|
"multiple": false,
|
||||||
|
"required": true,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "identifier",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"children": {
|
||||||
|
"multiple": true,
|
||||||
|
"required": true,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "ascription",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "param_block",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "binding",
|
"type": "binding",
|
||||||
"named": true,
|
"named": true,
|
||||||
|
|
@ -84,6 +114,10 @@
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": true,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "ascription",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "expr",
|
"type": "expr",
|
||||||
"named": true
|
"named": true
|
||||||
|
|
@ -122,10 +156,6 @@
|
||||||
"type": "ascription",
|
"type": "ascription",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"type": "axiom",
|
|
||||||
"named": true
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "expr",
|
"type": "expr",
|
||||||
"named": true
|
"named": true
|
||||||
|
|
@ -266,6 +296,10 @@
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": false,
|
"required": false,
|
||||||
"types": [
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "axiom",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "definition",
|
"type": "definition",
|
||||||
"named": true
|
"named": true
|
||||||
|
|
@ -347,11 +381,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "axiom",
|
"type": "axiom",
|
||||||
"named": true
|
"named": false
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "block_comment",
|
|
||||||
"named": true
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
|
|
@ -361,6 +391,10 @@
|
||||||
"type": "comment",
|
"type": "comment",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "def",
|
||||||
|
"named": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "end",
|
"type": "end",
|
||||||
"named": false
|
"named": false
|
||||||
|
|
|
||||||
3305
src/parser.c
generated
3305
src/parser.c
generated
File diff suppressed because it is too large
Load diff
|
|
@ -2,10 +2,11 @@
|
||||||
Application
|
Application
|
||||||
===========
|
===========
|
||||||
|
|
||||||
foo (A B : *) (f : A -> B) (x : A) :=
|
def foo (A B : *) (f : A -> B) (x : A) :=
|
||||||
(fun (x : B) => x) (f x);
|
(fun (x : B) => x) (f x);
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
(program
|
(program
|
||||||
(definition
|
(definition
|
||||||
(identifier)
|
(identifier)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
Arrows
|
Arrows
|
||||||
======
|
======
|
||||||
|
|
||||||
foo (A B : *) (f : A -> A -> B) (x : A) := f x x;
|
def foo (A B : *) (f : A -> A -> B) (x : A) := f x x;
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,16 @@
|
||||||
Axioms
|
Axioms
|
||||||
======
|
======
|
||||||
|
|
||||||
nat : * := axiom;
|
axiom nat : *;
|
||||||
|
|
||||||
-----
|
-----
|
||||||
|
|
||||||
(program
|
(program
|
||||||
(definition
|
(axiom
|
||||||
(identifier)
|
(identifier)
|
||||||
(ascription
|
(ascription
|
||||||
(expr
|
(expr
|
||||||
(app_term
|
(app_term
|
||||||
(app
|
(app
|
||||||
(term
|
(term
|
||||||
(star))))))
|
(star))))))))
|
||||||
(axiom)))
|
|
||||||
|
|
|
||||||
|
|
@ -2,23 +2,9 @@
|
||||||
Comments
|
Comments
|
||||||
========
|
========
|
||||||
|
|
||||||
-- here's a comment
|
[* foo [* nested *] *]
|
||||||
|
axiom nat : *;
|
||||||
foo :=
|
[* bar *]
|
||||||
-- and a comment in the middle
|
|
||||||
[* and a [* nested *] block comment *]
|
|
||||||
*;
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
(program
|
|
||||||
(comment)
|
|
||||||
(definition
|
|
||||||
(identifier)
|
|
||||||
(comment)
|
|
||||||
(block_comment)
|
|
||||||
(expr
|
|
||||||
(app_term
|
|
||||||
(app
|
|
||||||
(term
|
|
||||||
(star)))))))
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ Include
|
||||||
|
|
||||||
@include foo.pg
|
@include foo.pg
|
||||||
|
|
||||||
baz : * := A;
|
def baz : * := A;
|
||||||
|
|
||||||
@include bar.pg
|
@include bar.pg
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
Lambda Abstraction
|
Lambda Abstraction
|
||||||
==================
|
==================
|
||||||
|
|
||||||
foo := fun (A : *) (x : A) => x;
|
def foo := fun (A : *) (x : A) => x;
|
||||||
|
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,13 @@
|
||||||
Let
|
Let
|
||||||
===
|
===
|
||||||
|
|
||||||
foo := let (x := a)
|
def foo :=
|
||||||
(y := x)
|
let (x : bar := a)
|
||||||
(f (x : A) := x)
|
(y := x)
|
||||||
in
|
(f (x : A) := x)
|
||||||
x
|
in
|
||||||
end;
|
x
|
||||||
|
end;
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
@ -19,6 +20,12 @@ foo := let (x := a)
|
||||||
(let
|
(let
|
||||||
(binding
|
(binding
|
||||||
(identifier)
|
(identifier)
|
||||||
|
(ascription
|
||||||
|
(expr
|
||||||
|
(app_term
|
||||||
|
(app
|
||||||
|
(term
|
||||||
|
(identifier))))))
|
||||||
(expr
|
(expr
|
||||||
(app_term
|
(app_term
|
||||||
(app
|
(app
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
Pi Abstraction
|
Pi Abstraction
|
||||||
==============
|
==============
|
||||||
|
|
||||||
rel := forall (A : *) (x : A), *;
|
def rel := forall (A : *) (x : A), *;
|
||||||
|
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
Definition
|
Definition
|
||||||
==========
|
==========
|
||||||
|
|
||||||
foo (A : *) (x y z : A) := x;
|
def foo (A : *) (x y z : A) := x;
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue