Start extracting keywords in foreach command
This commit is contained in:
parent
d23b5a89fa
commit
6ccd073db5
|
@ -11,7 +11,7 @@ endforeach()
|
|||
(foreach_loop
|
||||
(foreach_command
|
||||
(foreach)
|
||||
(arguments (argument (unquoted_argument)))
|
||||
(argument (unquoted_argument))
|
||||
)
|
||||
(endforeach_command (endforeach))
|
||||
)
|
||||
|
@ -30,7 +30,7 @@ endforeach(var)
|
|||
(foreach_loop
|
||||
(foreach_command
|
||||
(foreach)
|
||||
(arguments (argument (unquoted_argument)))
|
||||
(argument (unquoted_argument))
|
||||
)
|
||||
(endforeach_command
|
||||
(endforeach)
|
||||
|
@ -51,7 +51,7 @@ ENDFOREACH()
|
|||
(foreach_loop
|
||||
(foreach_command
|
||||
(foreach)
|
||||
(arguments (argument (unquoted_argument)))
|
||||
(argument (unquoted_argument))
|
||||
)
|
||||
(endforeach_command (endforeach))
|
||||
)
|
||||
|
@ -70,7 +70,7 @@ endForEach()
|
|||
(foreach_loop
|
||||
(foreach_command
|
||||
(foreach)
|
||||
(arguments (argument (unquoted_argument)))
|
||||
(argument (unquoted_argument))
|
||||
)
|
||||
(endforeach_command (endforeach))
|
||||
)
|
||||
|
|
|
@ -36,10 +36,9 @@ module.exports = grammar({
|
|||
|
||||
unquoted_argument: ($) => repeat1(choice($.variable_ref, /[^ ()#\"\\]/, $.escape_sequence)),
|
||||
|
||||
arguments: ($) => seq($.argument, repeat($._seperated_arguments)),
|
||||
_seperated_arguments: ($) => prec.left(seq(repeat1($._seperation), optional($.argument))),
|
||||
arguments: ($) => args($, $.argument),
|
||||
|
||||
foreach_command: ($) => seq($.foreach, "(", $.arguments, ")"),
|
||||
foreach_command: ($) => seq($.foreach, "(", args($, $.argument, "IN"), ")"),
|
||||
endforeach_command: ($) =>
|
||||
seq($.endforeach, "(", repeat($._seperation), optional($.argument), ")"),
|
||||
foreach_loop: ($) =>
|
||||
|
@ -64,3 +63,7 @@ function commandName(name) {
|
|||
function commands(...names) {
|
||||
return Object.assign({}, ...names.map(commandName));
|
||||
}
|
||||
|
||||
function args($, ...rules) {
|
||||
return seq(choice(...rules), repeat(prec.left(seq(repeat1($._seperation), optional(choice(...rules))))));
|
||||
}
|
||||
|
|
128
src/grammar.json
128
src/grammar.json
|
@ -350,46 +350,52 @@
|
|||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_seperated_arguments"
|
||||
"type": "PREC_LEFT",
|
||||
"value": 0,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "REPEAT1",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_seperation"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"_seperated_arguments": {
|
||||
"type": "PREC_LEFT",
|
||||
"value": 0,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "REPEAT1",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_seperation"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"foreach_command": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
|
@ -402,8 +408,62 @@
|
|||
"value": "("
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "arguments"
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "IN"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "PREC_LEFT",
|
||||
"value": 0,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "REPEAT1",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_seperation"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "argument"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "IN"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
|
|
|
@ -120,7 +120,7 @@
|
|||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "arguments",
|
||||
"type": "argument",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
|
@ -329,6 +329,10 @@
|
|||
"type": "=",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "IN",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "[",
|
||||
"named": false
|
||||
|
|
3844
src/parser.c
3844
src/parser.c
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue