Fix grammar for allowing white space to appear everywher
This commit is contained in:
parent
e3dfc2cdca
commit
b8c45d2a2b
|
@ -41,7 +41,8 @@ Line comment [comment]
|
|||
Message with Line comment [comment]
|
||||
===================================
|
||||
message(STATUS #Some line comment
|
||||
message #Some other line comment
|
||||
|
||||
Second #Some other line comment
|
||||
)
|
||||
|
||||
---
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
====================
|
||||
Empty if [condition]
|
||||
====================
|
||||
if(cond)
|
||||
if ( cond )
|
||||
endif()
|
||||
|
||||
---
|
||||
|
|
|
@ -90,6 +90,7 @@ endforeach()
|
|||
(foreach_command
|
||||
(foreach)
|
||||
(argument (unquoted_argument))
|
||||
(argument (unquoted_argument))
|
||||
)
|
||||
(endforeach_command (endforeach))
|
||||
)
|
||||
|
@ -109,6 +110,7 @@ endforeach()
|
|||
(foreach_command
|
||||
(foreach)
|
||||
(argument (unquoted_argument))
|
||||
(argument (unquoted_argument))
|
||||
)
|
||||
(endforeach_command (endforeach))
|
||||
)
|
||||
|
|
|
@ -75,3 +75,19 @@ message(STATUS
|
|||
(argument (bracket_argument))
|
||||
)
|
||||
)
|
||||
|
||||
======================================================
|
||||
Message with STATUS and an unquoted argument [message]
|
||||
======================================================
|
||||
|
||||
message(STATUS argument)
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(normal_command
|
||||
(identifier)
|
||||
(argument (unquoted_argument))
|
||||
(argument (unquoted_argument))
|
||||
)
|
||||
)
|
||||
|
|
|
@ -25,6 +25,7 @@ message(STATUS Hello)
|
|||
(normal_command
|
||||
(identifier)
|
||||
(argument (unquoted_argument))
|
||||
(argument (unquoted_argument))
|
||||
)
|
||||
)
|
||||
|
||||
|
|
48
grammar.js
48
grammar.js
|
@ -17,10 +17,10 @@ module.exports = grammar({
|
|||
name: "cmake",
|
||||
|
||||
externals: ($) => [$.bracket_argument, $.bracket_comment, $.line_comment],
|
||||
extras: ($) => [/[\s\n\r]/, $.bracket_comment, $.line_comment],
|
||||
extras: ($) => [$.bracket_comment, $.line_comment],
|
||||
|
||||
rules: {
|
||||
source_file: ($) => repeat($._command_invocation),
|
||||
source_file: ($) => repeat($._untrimmed_command_invocation),
|
||||
|
||||
escape_sequence: ($) => choice($._escape_identity, $._escape_encoded, $._escape_semicolon),
|
||||
_escape_identity: (_) => /\\[^A-Za-z0-9;]/,
|
||||
|
@ -34,39 +34,45 @@ module.exports = grammar({
|
|||
cache_var: ($) => seq("$CACHE", "{", $.variable, "}"),
|
||||
|
||||
argument: ($) => choice($.bracket_argument, $.quoted_argument, $.unquoted_argument),
|
||||
_untrimmed_argument: ($) => choice(/\s/, $.argument),
|
||||
|
||||
quoted_argument: ($) => seq('"', optional($.quoted_element), '"'),
|
||||
quoted_element: ($) => repeat1(choice($.variable_ref, /[^\\"]/, $.escape_sequence)),
|
||||
|
||||
unquoted_argument: ($) => prec.right(repeat1(choice($.variable_ref, /[^\s\n\r()#\"\\]/, $.escape_sequence))),
|
||||
unquoted_argument: ($) => prec.right(repeat1(choice($.variable_ref, /[^\s()#\"\\]/, $.escape_sequence))),
|
||||
|
||||
if_command: ($) => command($.if, repeat(choice($.argument))),
|
||||
elseif_command: ($) => command($.elseif, repeat(choice($.argument))),
|
||||
else_command: ($) => command($.else, optional(choice($.argument))),
|
||||
endif_command: ($) => command($.endif, optional(choice($.argument))),
|
||||
if_command: ($) => command($.if, repeat($._untrimmed_argument)),
|
||||
elseif_command: ($) => command($.elseif, repeat($._untrimmed_argument)),
|
||||
else_command: ($) => command($.else, optional(seq(/\s*/, $.argument, /\s*/))),
|
||||
endif_command: ($) => command($.endif, optional(seq(/\s*/, $.argument, /\s*/))),
|
||||
if_condition: ($) =>
|
||||
seq($.if_command, repeat(choice($._command_invocation, $.elseif_command, $.else_command)), $.endif_command),
|
||||
seq(
|
||||
$.if_command,
|
||||
repeat(choice($._untrimmed_command_invocation, $.elseif_command, $.else_command)),
|
||||
$.endif_command
|
||||
),
|
||||
|
||||
foreach_command: ($) => command($.foreach, repeat(choice($.argument))),
|
||||
foreach_command: ($) => command($.foreach, repeat($._untrimmed_argument)),
|
||||
endforeach_command: ($) => command($.endforeach, optional($.argument)),
|
||||
foreach_loop: ($) => seq($.foreach_command, repeat($._command_invocation), $.endforeach_command),
|
||||
foreach_loop: ($) => seq($.foreach_command, repeat($._untrimmed_command_invocation), $.endforeach_command),
|
||||
|
||||
while_command: ($) => command($.while, repeat(choice($.argument))),
|
||||
endwhile_command: ($) => command($.endwhile, optional(choice($.argument))),
|
||||
while_loop: ($) => seq($.while_command, repeat($._command_invocation), $.endwhile_command),
|
||||
while_command: ($) => command($.while, repeat($._untrimmed_argument)),
|
||||
endwhile_command: ($) => command($.endwhile, optional(seq(/\s*/, $.argument, /\s*/))),
|
||||
while_loop: ($) => seq($.while_command, repeat($._untrimmed_command_invocation), $.endwhile_command),
|
||||
|
||||
function_command: ($) => command($.function, repeat($.argument)),
|
||||
endfunction_command: ($) => command($.endfunction, repeat($.argument)),
|
||||
function_def: ($) => seq($.function_command, repeat($._command_invocation), $.endfunction_command),
|
||||
function_command: ($) => command($.function, repeat($._untrimmed_argument)),
|
||||
endfunction_command: ($) => command($.endfunction, repeat($._untrimmed_argument)),
|
||||
function_def: ($) => seq($.function_command, repeat($._untrimmed_command_invocation), $.endfunction_command),
|
||||
|
||||
macro_command: ($) => command($.macro, repeat($.argument)),
|
||||
endmacro_command: ($) => command($.endmacro, repeat($.argument)),
|
||||
macro_def: ($) => seq($.macro_command, repeat($._command_invocation), $.endmacro_command),
|
||||
macro_command: ($) => command($.macro, repeat($._untrimmed_argument)),
|
||||
endmacro_command: ($) => command($.endmacro, repeat($._untrimmed_argument)),
|
||||
macro_def: ($) => seq($.macro_command, repeat($._untrimmed_command_invocation), $.endmacro_command),
|
||||
|
||||
normal_command: ($) => command($.identifier, repeat($.argument)),
|
||||
normal_command: ($) => command($.identifier, repeat($._untrimmed_argument)),
|
||||
|
||||
_command_invocation: ($) =>
|
||||
choice($.normal_command, $.if_condition, $.foreach_loop, $.while_loop, $.function_def, $.macro_def),
|
||||
_untrimmed_command_invocation: ($) => choice(/\s/, $._command_invocation),
|
||||
|
||||
...commandNames(...commands),
|
||||
identifier: (_) => /[A-Za-z_][A-Za-z0-9_]*/,
|
||||
|
@ -87,5 +93,5 @@ function commandNames(...names) {
|
|||
}
|
||||
|
||||
function command(name_rule, arg_rule) {
|
||||
return seq(name_rule, "(", arg_rule, ")");
|
||||
return seq(name_rule, repeat(/[\t ]/), "(", arg_rule, ")");
|
||||
}
|
||||
|
|
211
src/grammar.json
211
src/grammar.json
|
@ -5,7 +5,7 @@
|
|||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_command_invocation"
|
||||
"name": "_untrimmed_command_invocation"
|
||||
}
|
||||
},
|
||||
"escape_sequence": {
|
||||
|
@ -163,6 +163,19 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"_untrimmed_argument": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\s"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
}
|
||||
]
|
||||
},
|
||||
"quoted_argument": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
|
@ -222,7 +235,7 @@
|
|||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[^\\s\\n\\r()#\\\"\\\\]"
|
||||
"value": "[^\\s()#\\\"\\\\]"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
|
@ -239,6 +252,13 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "if"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[\\t ]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
|
@ -246,13 +266,8 @@
|
|||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
}
|
||||
]
|
||||
"type": "SYMBOL",
|
||||
"name": "_untrimmed_argument"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -268,6 +283,13 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "elseif"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[\\t ]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
|
@ -275,13 +297,8 @@
|
|||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
}
|
||||
]
|
||||
"type": "SYMBOL",
|
||||
"name": "_untrimmed_argument"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -297,6 +314,13 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "else"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[\\t ]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
|
@ -305,11 +329,19 @@
|
|||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\s*"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\s*"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -331,6 +363,13 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "endif"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[\\t ]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
|
@ -339,11 +378,19 @@
|
|||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\s*"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\s*"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -372,7 +419,7 @@
|
|||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_command_invocation"
|
||||
"name": "_untrimmed_command_invocation"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
|
@ -398,6 +445,13 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "foreach"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[\\t ]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
|
@ -405,13 +459,8 @@
|
|||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
}
|
||||
]
|
||||
"type": "SYMBOL",
|
||||
"name": "_untrimmed_argument"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -427,6 +476,13 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "endforeach"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[\\t ]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
|
@ -460,7 +516,7 @@
|
|||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_command_invocation"
|
||||
"name": "_untrimmed_command_invocation"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -476,6 +532,13 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "while"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[\\t ]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
|
@ -483,13 +546,8 @@
|
|||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
}
|
||||
]
|
||||
"type": "SYMBOL",
|
||||
"name": "_untrimmed_argument"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -505,6 +563,13 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "endwhile"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[\\t ]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
|
@ -513,11 +578,19 @@
|
|||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\s*"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\s*"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -543,7 +616,7 @@
|
|||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_command_invocation"
|
||||
"name": "_untrimmed_command_invocation"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -559,6 +632,13 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "function"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[\\t ]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
|
@ -567,7 +647,7 @@
|
|||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
"name": "_untrimmed_argument"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -583,6 +663,13 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "endfunction"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[\\t ]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
|
@ -591,7 +678,7 @@
|
|||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
"name": "_untrimmed_argument"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -611,7 +698,7 @@
|
|||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_command_invocation"
|
||||
"name": "_untrimmed_command_invocation"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -627,6 +714,13 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "macro"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[\\t ]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
|
@ -635,7 +729,7 @@
|
|||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
"name": "_untrimmed_argument"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -651,6 +745,13 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "endmacro"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[\\t ]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
|
@ -659,7 +760,7 @@
|
|||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
"name": "_untrimmed_argument"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -679,7 +780,7 @@
|
|||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_command_invocation"
|
||||
"name": "_untrimmed_command_invocation"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -695,6 +796,13 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[\\t ]"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
|
@ -703,7 +811,7 @@
|
|||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
"name": "_untrimmed_argument"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -741,6 +849,19 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"_untrimmed_command_invocation": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "\\s"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_command_invocation"
|
||||
}
|
||||
]
|
||||
},
|
||||
"if": {
|
||||
"type": "PATTERN",
|
||||
"value": "[iI][fF]"
|
||||
|
@ -799,10 +920,6 @@
|
|||
}
|
||||
},
|
||||
"extras": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[\\s\\n\\r]"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "bracket_comment"
|
||||
|
|
24985
src/parser.c
24985
src/parser.c
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue