Extract foreach loop
This commit is contained in:
parent
9e0798cc16
commit
bcb9e4ccfb
|
@ -8,6 +8,7 @@ endforeach()
|
|||
---
|
||||
|
||||
(source_file
|
||||
(foreach_loop
|
||||
(foreach_command
|
||||
(foreach)
|
||||
(variable)
|
||||
|
@ -16,6 +17,7 @@ endforeach()
|
|||
(endforeach)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
=========================================================
|
||||
Empty foreach loop with one argument endforeach [foreach]
|
||||
|
@ -27,6 +29,7 @@ endforeach(var)
|
|||
---
|
||||
|
||||
(source_file
|
||||
(foreach_loop
|
||||
(foreach_command
|
||||
(foreach)
|
||||
(variable)
|
||||
|
@ -36,6 +39,7 @@ endforeach(var)
|
|||
(variable)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
===========================
|
||||
Uppercase foreach [foreach]
|
||||
|
@ -47,6 +51,7 @@ ENDFOREACH()
|
|||
---
|
||||
|
||||
(source_file
|
||||
(foreach_loop
|
||||
(foreach_command
|
||||
(foreach)
|
||||
(variable)
|
||||
|
@ -55,6 +60,7 @@ ENDFOREACH()
|
|||
(endforeach)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
============================
|
||||
Mixed case foreach [foreach]
|
||||
|
@ -66,6 +72,7 @@ endForEach()
|
|||
---
|
||||
|
||||
(source_file
|
||||
(foreach_loop
|
||||
(foreach_command
|
||||
(foreach)
|
||||
(variable)
|
||||
|
@ -74,3 +81,4 @@ endForEach()
|
|||
(endforeach)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
10
grammar.js
10
grammar.js
|
@ -39,14 +39,14 @@ module.exports = grammar({
|
|||
arguments: ($) => seq($.argument, repeat($._seperated_arguments)),
|
||||
_seperated_arguments: ($) => prec.left(seq(repeat1($.seperation), optional($.argument))),
|
||||
|
||||
foreach_command: ($) =>
|
||||
seq($.foreach, "(", repeat($.seperation), $.variable, ")"),
|
||||
foreach_command: ($) => seq($.foreach, "(", repeat($.seperation), $.variable, ")"),
|
||||
endforeach_command: ($) =>
|
||||
seq($.endforeach, "(", repeat($.seperation), optional($.variable), ")"),
|
||||
normal_command: ($) =>
|
||||
seq($.identifier, "(", repeat($.seperation), optional($.arguments), ")"),
|
||||
foreach_loop: ($) =>
|
||||
seq($.foreach_command, repeat($._command_invocation), $.endforeach_command),
|
||||
normal_command: ($) => seq($.identifier, "(", repeat($.seperation), optional($.arguments), ")"),
|
||||
|
||||
_command_invocation: ($) => choice($.normal_command, $.foreach_command, $.endforeach_command),
|
||||
_command_invocation: ($) => choice($.normal_command, $.foreach_loop),
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -13,11 +13,6 @@
|
|||
"name": "newline"
|
||||
},
|
||||
"seperation": {
|
||||
"type": "PREC_LEFT",
|
||||
"value": 0,
|
||||
"content": {
|
||||
"type": "REPEAT1",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
|
@ -29,16 +24,14 @@
|
|||
"name": "line_ending"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"space": {
|
||||
"type": "PATTERN",
|
||||
"value": "[ \\t]"
|
||||
"value": "[ \\t]+"
|
||||
},
|
||||
"newline": {
|
||||
"type": "PATTERN",
|
||||
"value": "\\n"
|
||||
"value": "\\n+"
|
||||
},
|
||||
"foreach": {
|
||||
"type": "PATTERN",
|
||||
|
@ -461,6 +454,26 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"foreach_loop": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "foreach_command"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_command_invocation"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "endforeach_command"
|
||||
}
|
||||
]
|
||||
},
|
||||
"normal_command": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
|
@ -506,11 +519,7 @@
|
|||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "foreach_command"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "endforeach_command"
|
||||
"name": "foreach_loop"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -142,6 +142,33 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "foreach_loop",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "endforeach_command",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "foreach_command",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "foreach_loop",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "normal_command",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "line_ending",
|
||||
"named": true,
|
||||
|
@ -238,7 +265,7 @@
|
|||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
|
@ -261,11 +288,7 @@
|
|||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "endforeach_command",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "foreach_command",
|
||||
"type": "foreach_loop",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
|
|
2813
src/parser.c
2813
src/parser.c
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue