Extract foreach loop
This commit is contained in:
parent
9e0798cc16
commit
bcb9e4ccfb
|
@ -8,6 +8,7 @@ endforeach()
|
||||||
---
|
---
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
|
(foreach_loop
|
||||||
(foreach_command
|
(foreach_command
|
||||||
(foreach)
|
(foreach)
|
||||||
(variable)
|
(variable)
|
||||||
|
@ -16,6 +17,7 @@ endforeach()
|
||||||
(endforeach)
|
(endforeach)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
=========================================================
|
=========================================================
|
||||||
Empty foreach loop with one argument endforeach [foreach]
|
Empty foreach loop with one argument endforeach [foreach]
|
||||||
|
@ -27,6 +29,7 @@ endforeach(var)
|
||||||
---
|
---
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
|
(foreach_loop
|
||||||
(foreach_command
|
(foreach_command
|
||||||
(foreach)
|
(foreach)
|
||||||
(variable)
|
(variable)
|
||||||
|
@ -36,6 +39,7 @@ endforeach(var)
|
||||||
(variable)
|
(variable)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
===========================
|
===========================
|
||||||
Uppercase foreach [foreach]
|
Uppercase foreach [foreach]
|
||||||
|
@ -47,6 +51,7 @@ ENDFOREACH()
|
||||||
---
|
---
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
|
(foreach_loop
|
||||||
(foreach_command
|
(foreach_command
|
||||||
(foreach)
|
(foreach)
|
||||||
(variable)
|
(variable)
|
||||||
|
@ -55,6 +60,7 @@ ENDFOREACH()
|
||||||
(endforeach)
|
(endforeach)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
============================
|
============================
|
||||||
Mixed case foreach [foreach]
|
Mixed case foreach [foreach]
|
||||||
|
@ -66,6 +72,7 @@ endForEach()
|
||||||
---
|
---
|
||||||
|
|
||||||
(source_file
|
(source_file
|
||||||
|
(foreach_loop
|
||||||
(foreach_command
|
(foreach_command
|
||||||
(foreach)
|
(foreach)
|
||||||
(variable)
|
(variable)
|
||||||
|
@ -74,3 +81,4 @@ endForEach()
|
||||||
(endforeach)
|
(endforeach)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
10
grammar.js
10
grammar.js
|
@ -39,14 +39,14 @@ module.exports = grammar({
|
||||||
arguments: ($) => seq($.argument, repeat($._seperated_arguments)),
|
arguments: ($) => seq($.argument, repeat($._seperated_arguments)),
|
||||||
_seperated_arguments: ($) => prec.left(seq(repeat1($.seperation), optional($.argument))),
|
_seperated_arguments: ($) => prec.left(seq(repeat1($.seperation), optional($.argument))),
|
||||||
|
|
||||||
foreach_command: ($) =>
|
foreach_command: ($) => seq($.foreach, "(", repeat($.seperation), $.variable, ")"),
|
||||||
seq($.foreach, "(", repeat($.seperation), $.variable, ")"),
|
|
||||||
endforeach_command: ($) =>
|
endforeach_command: ($) =>
|
||||||
seq($.endforeach, "(", repeat($.seperation), optional($.variable), ")"),
|
seq($.endforeach, "(", repeat($.seperation), optional($.variable), ")"),
|
||||||
normal_command: ($) =>
|
foreach_loop: ($) =>
|
||||||
seq($.identifier, "(", repeat($.seperation), optional($.arguments), ")"),
|
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"
|
"name": "newline"
|
||||||
},
|
},
|
||||||
"seperation": {
|
"seperation": {
|
||||||
"type": "PREC_LEFT",
|
|
||||||
"value": 0,
|
|
||||||
"content": {
|
|
||||||
"type": "REPEAT1",
|
|
||||||
"content": {
|
|
||||||
"type": "CHOICE",
|
"type": "CHOICE",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
|
@ -29,16 +24,14 @@
|
||||||
"name": "line_ending"
|
"name": "line_ending"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"space": {
|
"space": {
|
||||||
"type": "PATTERN",
|
"type": "PATTERN",
|
||||||
"value": "[ \\t]"
|
"value": "[ \\t]+"
|
||||||
},
|
},
|
||||||
"newline": {
|
"newline": {
|
||||||
"type": "PATTERN",
|
"type": "PATTERN",
|
||||||
"value": "\\n"
|
"value": "\\n+"
|
||||||
},
|
},
|
||||||
"foreach": {
|
"foreach": {
|
||||||
"type": "PATTERN",
|
"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": {
|
"normal_command": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
|
@ -506,11 +519,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "foreach_command"
|
"name": "foreach_loop"
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "endforeach_command"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -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",
|
"type": "line_ending",
|
||||||
"named": true,
|
"named": true,
|
||||||
|
@ -238,7 +265,7 @@
|
||||||
"named": true,
|
"named": true,
|
||||||
"fields": {},
|
"fields": {},
|
||||||
"children": {
|
"children": {
|
||||||
"multiple": true,
|
"multiple": false,
|
||||||
"required": true,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
{
|
{
|
||||||
|
@ -261,11 +288,7 @@
|
||||||
"required": false,
|
"required": false,
|
||||||
"types": [
|
"types": [
|
||||||
{
|
{
|
||||||
"type": "endforeach_command",
|
"type": "foreach_loop",
|
||||||
"named": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "foreach_command",
|
|
||||||
"named": true
|
"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