Start extracting keywords in foreach command

This commit is contained in:
Uy Ha 2021-06-14 22:07:04 +02:00
parent d23b5a89fa
commit 6ccd073db5
5 changed files with 2161 additions and 1834 deletions

View file

@ -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))
)

View file

@ -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))))));
}

View file

@ -348,21 +348,19 @@
},
"arguments": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "argument"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_seperated_arguments"
}
}
]
},
"_seperated_arguments": {
"type": "PREC_LEFT",
"value": 0,
"content": {
@ -375,12 +373,17 @@
"name": "_seperation"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "argument"
}
]
},
{
"type": "BLANK"
@ -389,6 +392,9 @@
}
]
}
}
}
]
},
"foreach_command": {
"type": "SEQ",
@ -401,9 +407,63 @@
"type": "STRING",
"value": "("
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "arguments"
"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",

View file

@ -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

File diff suppressed because it is too large Load diff