Skip to content

Commit

Permalink
Merge pull request Wilfred#11 from mskelton/fix-nodes
Browse files Browse the repository at this point in the history
Support `#include` directives in nodes
  • Loading branch information
joelspadin authored Nov 21, 2023
2 parents cc26cbf + 3fc8ed5 commit e876e2a
Show file tree
Hide file tree
Showing 5 changed files with 3,748 additions and 3,067 deletions.
10 changes: 8 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ module.exports = grammar({
$.omit_if_no_ref,
$.labeled_item,
$.node,
$.property
$.property,
$.preproc_include,
$.preproc_def,
$.preproc_function_def
),

// TODO: is delete-node allowed at top level?
Expand Down Expand Up @@ -391,7 +394,10 @@ module.exports = grammar({
});

function preprocessor(command) {
return alias(new RegExp('#[ \t]*' + command), '#' + command);
return alias(
token(prec(2, new RegExp('#[ \t]*' + command))),
'#' + command
);
}

function commaSep(rule) {
Expand Down
45 changes: 39 additions & 6 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,18 @@
{
"type": "SYMBOL",
"name": "property"
},
{
"type": "SYMBOL",
"name": "preproc_include"
},
{
"type": "SYMBOL",
"name": "preproc_def"
},
{
"type": "SYMBOL",
"name": "preproc_function_def"
}
]
},
Expand Down Expand Up @@ -1828,8 +1840,15 @@
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "#[ \t]*include"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 2,
"content": {
"type": "PATTERN",
"value": "#[ \t]*include"
}
}
},
"named": false,
"value": "#include"
Expand Down Expand Up @@ -1867,8 +1886,15 @@
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "#[ \t]*define"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 2,
"content": {
"type": "PATTERN",
"value": "#[ \t]*define"
}
}
},
"named": false,
"value": "#define"
Expand Down Expand Up @@ -1909,8 +1935,15 @@
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "#[ \t]*define"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 2,
"content": {
"type": "PATTERN",
"value": "#[ \t]*define"
}
}
},
"named": false,
"value": "#define"
Expand Down
12 changes: 12 additions & 0 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,18 @@
"type": "omit_if_no_ref",
"named": true
},
{
"type": "preproc_def",
"named": true
},
{
"type": "preproc_function_def",
"named": true
},
{
"type": "preproc_include",
"named": true
},
{
"type": "property",
"named": true
Expand Down
Loading

0 comments on commit e876e2a

Please sign in to comment.