Extract foreach loop

This commit is contained in:
Uy Ha 2021-06-08 00:07:49 +02:00
parent 9e0798cc16
commit bcb9e4ccfb
5 changed files with 1646 additions and 1327 deletions

View file

@ -8,12 +8,14 @@ endforeach()
--- ---
(source_file (source_file
(foreach_command (foreach_loop
(foreach) (foreach_command
(variable) (foreach)
) (variable)
(endforeach_command )
(endforeach) (endforeach_command
(endforeach)
)
) )
) )
@ -27,15 +29,17 @@ endforeach(var)
--- ---
(source_file (source_file
(foreach_command (foreach_loop
(foreach) (foreach_command
(variable) (foreach)
(variable)
)
(endforeach_command
(endforeach)
(variable)
)
) )
(endforeach_command
(endforeach)
(variable)
) )
)
=========================== ===========================
Uppercase foreach [foreach] Uppercase foreach [foreach]
@ -47,12 +51,14 @@ ENDFOREACH()
--- ---
(source_file (source_file
(foreach_command (foreach_loop
(foreach) (foreach_command
(variable) (foreach)
) (variable)
(endforeach_command )
(endforeach) (endforeach_command
(endforeach)
)
) )
) )
@ -66,11 +72,13 @@ endForEach()
--- ---
(source_file (source_file
(foreach_command (foreach_loop
(foreach) (foreach_command
(variable) (foreach)
) (variable)
(endforeach_command )
(endforeach) (endforeach_command
(endforeach)
)
) )
) )

View file

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

View file

@ -13,32 +13,25 @@
"name": "newline" "name": "newline"
}, },
"seperation": { "seperation": {
"type": "PREC_LEFT", "type": "CHOICE",
"value": 0, "members": [
"content": { {
"type": "REPEAT1", "type": "SYMBOL",
"content": { "name": "space"
"type": "CHOICE", },
"members": [ {
{ "type": "SYMBOL",
"type": "SYMBOL", "name": "line_ending"
"name": "space"
},
{
"type": "SYMBOL",
"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"
} }
] ]
} }

View file

@ -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
}, },
{ {

File diff suppressed because it is too large Load diff