Complete list of keywords for foreach

This commit is contained in:
Uy Ha 2021-06-14 22:12:45 +02:00
parent 6ccd073db5
commit c5affb3570
5 changed files with 1130 additions and 934 deletions

View file

@ -1,5 +1,5 @@
==================================
Empty foreach loop [foreach_empty]
Empty foreach loop [foreach]
==================================
foreach(var)
@ -18,7 +18,7 @@ endforeach()
)
===============================================================
Empty foreach loop with one argument endforeach [foreach_empty]
Empty foreach loop with one argument endforeach [foreach]
===============================================================
foreach(var)
@ -39,7 +39,7 @@ endforeach(var)
))
=================================
Uppercase foreach [foreach_empty]
Uppercase foreach [foreach]
=================================
FOREACH(var)
@ -58,7 +58,7 @@ ENDFOREACH()
)
==================================
Mixed case foreach [foreach_empty]
Mixed case foreach [foreach]
==================================
forEach(var)
@ -75,3 +75,41 @@ endForEach()
(endforeach_command (endforeach))
)
)
==================================
Empty IN [foreach]
==================================
foreach(var IN)
endforeach()
---
(source_file
(foreach_loop
(foreach_command
(foreach)
(argument (unquoted_argument))
)
(endforeach_command (endforeach))
)
)
==================================
Empty RANGE [foreach]
==================================
foreach(var RANGE)
endforeach()
---
(source_file
(foreach_loop
(foreach_command
(foreach)
(argument (unquoted_argument))
)
(endforeach_command (endforeach))
)
)

View file

@ -38,7 +38,8 @@ module.exports = grammar({
arguments: ($) => args($, $.argument),
foreach_command: ($) => seq($.foreach, "(", args($, $.argument, "IN"), ")"),
foreach_command: ($) =>
seq($.foreach, "(", args($, $.argument, "IN", "ZIP_LIST", "RANGE", "LISTS", "ITEMS"), ")"),
endforeach_command: ($) =>
seq($.endforeach, "(", repeat($._seperation), optional($.argument), ")"),
foreach_loop: ($) =>
@ -65,5 +66,8 @@ function commands(...names) {
}
function args($, ...rules) {
return seq(choice(...rules), repeat(prec.left(seq(repeat1($._seperation), optional(choice(...rules))))));
return seq(
choice(...rules),
repeat(prec.left(seq(repeat1($._seperation), optional(choice(...rules)))))
);
}

View file

@ -420,6 +420,22 @@
{
"type": "STRING",
"value": "IN"
},
{
"type": "STRING",
"value": "ZIP_LIST"
},
{
"type": "STRING",
"value": "RANGE"
},
{
"type": "STRING",
"value": "LISTS"
},
{
"type": "STRING",
"value": "ITEMS"
}
]
},
@ -451,6 +467,22 @@
{
"type": "STRING",
"value": "IN"
},
{
"type": "STRING",
"value": "ZIP_LIST"
},
{
"type": "STRING",
"value": "RANGE"
},
{
"type": "STRING",
"value": "LISTS"
},
{
"type": "STRING",
"value": "ITEMS"
}
]
},

View file

@ -333,6 +333,22 @@
"type": "IN",
"named": false
},
{
"type": "ITEMS",
"named": false
},
{
"type": "LISTS",
"named": false
},
{
"type": "RANGE",
"named": false
},
{
"type": "ZIP_LIST",
"named": false
},
{
"type": "[",
"named": false

File diff suppressed because it is too large Load diff