sections
This commit is contained in:
parent
bed94f3d41
commit
3834eb6f0a
5 changed files with 2873 additions and 1872 deletions
14
grammar.js
14
grammar.js
|
|
@ -17,12 +17,24 @@ module.exports = grammar({
|
||||||
|
|
||||||
rules: {
|
rules: {
|
||||||
|
|
||||||
program : $ => repeat(choice($.definition, $.preprocess, $.axiom)),
|
program : $ => repeat1(choice($.definition, $.preprocess, $.axiom, $.section, $.variable)),
|
||||||
|
|
||||||
identifier : $ => /[a-zA-Z_]\w*/,
|
identifier : $ => /[a-zA-Z_]\w*/,
|
||||||
|
|
||||||
comment : $ => token(seq('--', /.*/)),
|
comment : $ => token(seq('--', /.*/)),
|
||||||
|
|
||||||
|
section : $ => seq(
|
||||||
|
'section', $.identifier,
|
||||||
|
$.program,
|
||||||
|
'end', $.identifier,
|
||||||
|
),
|
||||||
|
|
||||||
|
variable : $ => seq(
|
||||||
|
choice('variable', 'hypothesis'),
|
||||||
|
repeat1($.param_block),
|
||||||
|
';'
|
||||||
|
),
|
||||||
|
|
||||||
param_block : $ => seq(
|
param_block : $ => seq(
|
||||||
'(',
|
'(',
|
||||||
field('param', repeat1($.identifier)),
|
field('param', repeat1($.identifier)),
|
||||||
|
|
|
||||||
64
src/grammar.json
generated
64
src/grammar.json
generated
|
|
@ -2,7 +2,7 @@
|
||||||
"name": "perga",
|
"name": "perga",
|
||||||
"rules": {
|
"rules": {
|
||||||
"program": {
|
"program": {
|
||||||
"type": "REPEAT",
|
"type": "REPEAT1",
|
||||||
"content": {
|
"content": {
|
||||||
"type": "CHOICE",
|
"type": "CHOICE",
|
||||||
"members": [
|
"members": [
|
||||||
|
|
@ -17,6 +17,14 @@
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "axiom"
|
"name": "axiom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "section"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "variable"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -41,6 +49,60 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"section": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "section"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "identifier"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "program"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "end"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "identifier"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"variable": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "variable"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "hypothesis"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "REPEAT1",
|
||||||
|
"content": {
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "param_block"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": ";"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"param_block": {
|
"param_block": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
|
|
|
||||||
56
src/node-types.json
generated
56
src/node-types.json
generated
|
|
@ -302,7 +302,7 @@
|
||||||
"fields": {},
|
"fields": {},
|
||||||
"children": {
|
"children": {
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": false,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
{
|
{
|
||||||
"type": "axiom",
|
"type": "axiom",
|
||||||
|
|
@ -315,6 +315,33 @@
|
||||||
{
|
{
|
||||||
"type": "preprocess",
|
"type": "preprocess",
|
||||||
"named": true
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "section",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "variable",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "section",
|
||||||
|
"named": true,
|
||||||
|
"fields": {},
|
||||||
|
"children": {
|
||||||
|
"multiple": true,
|
||||||
|
"required": true,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "identifier",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "program",
|
||||||
|
"named": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -366,6 +393,21 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "variable",
|
||||||
|
"named": true,
|
||||||
|
"fields": {},
|
||||||
|
"children": {
|
||||||
|
"multiple": true,
|
||||||
|
"required": true,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "param_block",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "(",
|
"type": "(",
|
||||||
"named": false
|
"named": false
|
||||||
|
|
@ -430,6 +472,10 @@
|
||||||
"type": "fun",
|
"type": "fun",
|
||||||
"named": false
|
"named": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "hypothesis",
|
||||||
|
"named": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "identifier",
|
"type": "identifier",
|
||||||
"named": true
|
"named": true
|
||||||
|
|
@ -446,10 +492,18 @@
|
||||||
"type": "post_command",
|
"type": "post_command",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "section",
|
||||||
|
"named": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "star",
|
"type": "star",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "variable",
|
||||||
|
"named": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "λ",
|
"type": "λ",
|
||||||
"named": false
|
"named": false
|
||||||
|
|
|
||||||
4539
src/parser.c
generated
4539
src/parser.c
generated
File diff suppressed because it is too large
Load diff
72
test/corpus/section.txt
Normal file
72
test/corpus/section.txt
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
========
|
||||||
|
Sections
|
||||||
|
========
|
||||||
|
|
||||||
|
section Test
|
||||||
|
variable (A B C : *);
|
||||||
|
hypothesis (x : A) (y : B) (z1 z2 : C);
|
||||||
|
|
||||||
|
section Nested
|
||||||
|
def foo (x : A) := y;
|
||||||
|
end Nested
|
||||||
|
end Test
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
(program
|
||||||
|
(section
|
||||||
|
(identifier)
|
||||||
|
(program
|
||||||
|
(variable
|
||||||
|
(param_block
|
||||||
|
(identifier)
|
||||||
|
(identifier)
|
||||||
|
(identifier)
|
||||||
|
(expr
|
||||||
|
(app_term
|
||||||
|
(app
|
||||||
|
(term
|
||||||
|
(sort
|
||||||
|
(star))))))))
|
||||||
|
(variable
|
||||||
|
(param_block
|
||||||
|
(identifier)
|
||||||
|
(expr
|
||||||
|
(app_term
|
||||||
|
(app
|
||||||
|
(term
|
||||||
|
(identifier))))))
|
||||||
|
(param_block
|
||||||
|
(identifier)
|
||||||
|
(expr
|
||||||
|
(app_term
|
||||||
|
(app
|
||||||
|
(term
|
||||||
|
(identifier))))))
|
||||||
|
(param_block
|
||||||
|
(identifier)
|
||||||
|
(identifier)
|
||||||
|
(expr
|
||||||
|
(app_term
|
||||||
|
(app
|
||||||
|
(term
|
||||||
|
(identifier)))))))
|
||||||
|
(section
|
||||||
|
(identifier)
|
||||||
|
(program
|
||||||
|
(definition
|
||||||
|
(identifier)
|
||||||
|
(param_block
|
||||||
|
(identifier)
|
||||||
|
(expr
|
||||||
|
(app_term
|
||||||
|
(app
|
||||||
|
(term
|
||||||
|
(identifier))))))
|
||||||
|
(expr
|
||||||
|
(app_term
|
||||||
|
(app
|
||||||
|
(term
|
||||||
|
(identifier)))))))
|
||||||
|
(identifier)))
|
||||||
|
(identifier)))
|
||||||
Loading…
Reference in a new issue