added support for preprocessor
This commit is contained in:
parent
ece43957c9
commit
158683891c
5 changed files with 1058 additions and 708 deletions
|
|
@ -18,7 +18,7 @@ module.exports = grammar({
|
|||
|
||||
rules: {
|
||||
|
||||
program : $ => repeat($.definition),
|
||||
program : $ => repeat(choice($.definition, $.preprocess)),
|
||||
|
||||
identifier : $ => /[a-zA-Z_]\w*/,
|
||||
|
||||
|
|
@ -103,5 +103,11 @@ module.exports = grammar({
|
|||
';',
|
||||
),
|
||||
|
||||
preprocess : $ => seq($.command, $.post_command),
|
||||
|
||||
post_command : $ => /.+/,
|
||||
|
||||
command : $ => '@include',
|
||||
|
||||
}
|
||||
});
|
||||
|
|
|
|||
34
src/grammar.json
generated
34
src/grammar.json
generated
|
|
@ -4,8 +4,17 @@
|
|||
"program": {
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "definition"
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "definition"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "preprocess"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"identifier": {
|
||||
|
|
@ -374,6 +383,27 @@
|
|||
"value": ";"
|
||||
}
|
||||
]
|
||||
},
|
||||
"preprocess": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "command"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "post_command"
|
||||
}
|
||||
]
|
||||
},
|
||||
"post_command": {
|
||||
"type": "PATTERN",
|
||||
"value": ".+"
|
||||
},
|
||||
"command": {
|
||||
"type": "STRING",
|
||||
"value": "@include"
|
||||
}
|
||||
},
|
||||
"extras": [
|
||||
|
|
|
|||
31
src/node-types.json
generated
31
src/node-types.json
generated
|
|
@ -193,6 +193,25 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "preprocess",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "command",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "post_command",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "program",
|
||||
"named": true,
|
||||
|
|
@ -204,6 +223,10 @@
|
|||
{
|
||||
"type": "definition",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "preprocess",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -284,6 +307,10 @@
|
|||
"type": "block_comment",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "command",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "comment",
|
||||
"named": true
|
||||
|
|
@ -300,6 +327,10 @@
|
|||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "post_command",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "star",
|
||||
"named": true
|
||||
|
|
|
|||
1661
src/parser.c
generated
1661
src/parser.c
generated
File diff suppressed because it is too large
Load diff
32
test/corpus/include.txt
Normal file
32
test/corpus/include.txt
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
=======
|
||||
Include
|
||||
=======
|
||||
|
||||
@include foo.pg
|
||||
|
||||
baz : * := A;
|
||||
|
||||
@include bar.pg
|
||||
|
||||
---
|
||||
|
||||
(program
|
||||
(preprocess
|
||||
(command)
|
||||
(post_command))
|
||||
(definition
|
||||
(identifier)
|
||||
(ascription
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(star))))))
|
||||
(expr
|
||||
(app_term
|
||||
(app
|
||||
(term
|
||||
(identifier))))))
|
||||
(preprocess
|
||||
(command)
|
||||
(post_command)))
|
||||
Loading…
Reference in a new issue