Skip to content


Browse files Browse the repository at this point in the history
Fix sugared foreach() syntax parsing
- Fix `foreach(... in ...)` and `foreach(... as ...)` syntax parsing. Bug was introduced in build 4024.
- Make `foreach` use `__statements__` as in-between rewrite node instead of `sconcat`. No functional changes.
  • Loading branch information
Pieter12345 committed Dec 1, 2020
1 parent 69f6baa commit a96d3af
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/main/java/com/laytonsmith/core/functions/
Expand Up @@ -1600,16 +1600,17 @@ public ParseTree postParseRewrite(ParseTree ast, Environment env,
if(isFunction(children.get(0), centry.NAME)) {
// This is what "@key: @value in @array" looks like initially.
// We'll refactor this so the next segment can take over properly.
ParseTree sconcatNode = new ParseTree(
new CFunction(sconcat.NAME, ast.getTarget()), ast.getFileOptions());
ParseTree statementsNode = new ParseTree(
new CFunction(__statements__.NAME, ast.getTarget()), ast.getFileOptions());
for(int i = 0; i < children.get(0).getChildAt(1).numberOfChildren(); i++) {
children.set(0, sconcatNode);
children.set(0, statementsNode);
if(children.get(0).getData() instanceof CFunction
&& children.get(0).getData().val().equals(sconcat.NAME)) {
&& (children.get(0).getData().val().equals(sconcat.NAME)
|| children.get(0).getData().val().equals(__statements__.NAME))) {
// We may be looking at a "@value in @array" or "@array as @value" type
// structure, so we need to re-arrange this into the standard format.
ParseTree array = null;
Expand Down

0 comments on commit a96d3af

Please sign in to comment.