Add basic support for foreach
This commit is contained in:
parent
265b10cf72
commit
3ff964a361
34
corpus/foreach.txt
Normal file
34
corpus/foreach.txt
Normal file
|
@ -0,0 +1,34 @@
|
|||
==========================================
|
||||
[foreach, lowercase, empty_for, empty_end]
|
||||
==========================================
|
||||
|
||||
foreach(var)
|
||||
endforeach()
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(command_invocation
|
||||
(foreach_loop
|
||||
(variable)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
==============================================
|
||||
[foreach, lowercase, empty_for, non_empty_end]
|
||||
==============================================
|
||||
|
||||
foreach(var)
|
||||
endforeach(var)
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(command_invocation
|
||||
(foreach_loop
|
||||
(variable)
|
||||
(variable)
|
||||
)
|
||||
)
|
||||
)
|
18
grammar.js
18
grammar.js
|
@ -40,24 +40,20 @@ module.exports = grammar({
|
|||
|
||||
foreach_loop: ($) =>
|
||||
seq(
|
||||
repeat($.space),
|
||||
/foreach/i,
|
||||
"foreach",
|
||||
repeat($.space),
|
||||
"(",
|
||||
$.variable,
|
||||
repeat($.seperation),
|
||||
optional($.arguments),
|
||||
")",
|
||||
"endforeach",
|
||||
"(",
|
||||
optional($.variable),
|
||||
")"
|
||||
),
|
||||
normal_command: ($) =>
|
||||
seq(
|
||||
repeat($.space),
|
||||
$.identifier,
|
||||
repeat($.space),
|
||||
"(",
|
||||
repeat($.seperation),
|
||||
optional($.arguments),
|
||||
")"
|
||||
),
|
||||
seq($.identifier, repeat($.space), "(", repeat($.seperation), optional($.arguments), ")"),
|
||||
|
||||
command_invocation: ($) => choice($.normal_command, $.foreach_loop),
|
||||
},
|
||||
|
|
|
@ -386,14 +386,7 @@
|
|||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "space"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"type": "STRING",
|
||||
"value": "foreach"
|
||||
},
|
||||
{
|
||||
|
@ -407,6 +400,10 @@
|
|||
"type": "STRING",
|
||||
"value": "("
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "variable"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
|
@ -426,6 +423,30 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ")"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "endforeach"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "("
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "variable"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ")"
|
||||
|
@ -435,13 +456,6 @@
|
|||
"normal_command": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "space"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
|
|
|
@ -121,7 +121,7 @@
|
|||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "arguments",
|
||||
|
@ -134,6 +134,10 @@
|
|||
{
|
||||
"type": "space",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "variable",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -376,6 +380,14 @@
|
|||
"type": "]",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "endforeach",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "foreach",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
|
|
3756
src/parser.c
3756
src/parser.c
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue