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_loop
(foreach_command (foreach_command
(foreach) (foreach)
(arguments (argument (unquoted_argument))) (argument (unquoted_argument))
) )
(endforeach_command (endforeach)) (endforeach_command (endforeach))
) )
@ -30,7 +30,7 @@ endforeach(var)
(foreach_loop (foreach_loop
(foreach_command (foreach_command
(foreach) (foreach)
(arguments (argument (unquoted_argument))) (argument (unquoted_argument))
) )
(endforeach_command (endforeach_command
(endforeach) (endforeach)
@ -51,7 +51,7 @@ ENDFOREACH()
(foreach_loop (foreach_loop
(foreach_command (foreach_command
(foreach) (foreach)
(arguments (argument (unquoted_argument))) (argument (unquoted_argument))
) )
(endforeach_command (endforeach)) (endforeach_command (endforeach))
) )
@ -70,7 +70,7 @@ endForEach()
(foreach_loop (foreach_loop
(foreach_command (foreach_command
(foreach) (foreach)
(arguments (argument (unquoted_argument))) (argument (unquoted_argument))
) )
(endforeach_command (endforeach)) (endforeach_command (endforeach))
) )

View file

@ -36,10 +36,9 @@ module.exports = grammar({
unquoted_argument: ($) => repeat1(choice($.variable_ref, /[^ ()#\"\\]/, $.escape_sequence)), unquoted_argument: ($) => repeat1(choice($.variable_ref, /[^ ()#\"\\]/, $.escape_sequence)),
arguments: ($) => seq($.argument, repeat($._seperated_arguments)), arguments: ($) => args($, $.argument),
_seperated_arguments: ($) => prec.left(seq(repeat1($._seperation), optional($.argument))),
foreach_command: ($) => seq($.foreach, "(", $.arguments, ")"), foreach_command: ($) => seq($.foreach, "(", args($, $.argument, "IN"), ")"),
endforeach_command: ($) => endforeach_command: ($) =>
seq($.endforeach, "(", repeat($._seperation), optional($.argument), ")"), seq($.endforeach, "(", repeat($._seperation), optional($.argument), ")"),
foreach_loop: ($) => foreach_loop: ($) =>
@ -64,3 +63,7 @@ function commandName(name) {
function commands(...names) { function commands(...names) {
return Object.assign({}, ...names.map(commandName)); return Object.assign({}, ...names.map(commandName));
} }
function args($, ...rules) {
return seq(choice(...rules), repeat(prec.left(seq(repeat1($._seperation), optional(choice(...rules))))));
}

View file

@ -350,46 +350,52 @@
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "CHOICE",
"name": "argument" "members": [
{
"type": "SYMBOL",
"name": "argument"
}
]
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
"content": { "content": {
"type": "SYMBOL", "type": "PREC_LEFT",
"name": "_seperated_arguments" "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": { "foreach_command": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -402,8 +408,62 @@
"value": "(" "value": "("
}, },
{ {
"type": "SYMBOL", "type": "SEQ",
"name": "arguments" "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", "type": "STRING",

View file

@ -120,7 +120,7 @@
"required": true, "required": true,
"types": [ "types": [
{ {
"type": "arguments", "type": "argument",
"named": true "named": true
}, },
{ {
@ -329,6 +329,10 @@
"type": "=", "type": "=",
"named": false "named": false
}, },
{
"type": "IN",
"named": false
},
{ {
"type": "[", "type": "[",
"named": false "named": false

File diff suppressed because it is too large Load diff