Skip to content

Commit a96d3af

Browse files
committed
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.
1 parent 69f6baa commit a96d3af

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/main/java/com/laytonsmith/core/functions/ControlFlow.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,16 +1600,17 @@ public ParseTree postParseRewrite(ParseTree ast, Environment env,
16001600
if(isFunction(children.get(0), centry.NAME)) {
16011601
// This is what "@key: @value in @array" looks like initially.
16021602
// We'll refactor this so the next segment can take over properly.
1603-
ParseTree sconcatNode = new ParseTree(
1604-
new CFunction(sconcat.NAME, ast.getTarget()), ast.getFileOptions());
1605-
sconcatNode.addChild(children.get(0).getChildAt(0));
1603+
ParseTree statementsNode = new ParseTree(
1604+
new CFunction(__statements__.NAME, ast.getTarget()), ast.getFileOptions());
1605+
statementsNode.addChild(children.get(0).getChildAt(0));
16061606
for(int i = 0; i < children.get(0).getChildAt(1).numberOfChildren(); i++) {
1607-
sconcatNode.addChild(children.get(0).getChildAt(1).getChildAt(i));
1607+
statementsNode.addChild(children.get(0).getChildAt(1).getChildAt(i));
16081608
}
1609-
children.set(0, sconcatNode);
1609+
children.set(0, statementsNode);
16101610
}
16111611
if(children.get(0).getData() instanceof CFunction
1612-
&& children.get(0).getData().val().equals(sconcat.NAME)) {
1612+
&& (children.get(0).getData().val().equals(sconcat.NAME)
1613+
|| children.get(0).getData().val().equals(__statements__.NAME))) {
16131614
// We may be looking at a "@value in @array" or "@array as @value" type
16141615
// structure, so we need to re-arrange this into the standard format.
16151616
ParseTree array = null;

0 commit comments

Comments
 (0)