From 70b7caa98bc87c8b113993309f0adf9201f62671 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Tue, 27 Dec 2016 16:30:02 +0200 Subject: [PATCH] Reverted if-without-else feature in SCL Removed possibility to have if-then -construct without else, because the implementation changed parsing rules and some existing code was broken. The feature might be added in future, if better implementation is found. refs #6894 related to change (refs #6888) Change-Id: I1c729c4176cfaf867ba3dbf13fd73fbc14f41e61 --- .../internal/parsing/parser/SCLPostLexer.java | 17 +++++++++++------ .../compiler/tests/ModuleRegressionTests.java | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLPostLexer.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLPostLexer.java index 3d3b7b2f5..efc799322 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLPostLexer.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/parsing/parser/SCLPostLexer.java @@ -37,6 +37,7 @@ public class SCLPostLexer { NO_SEMICOLON_BEFORE.add(SCLTerminals.EOF); NO_SEMICOLON_BEFORE.add(SCLTerminals.SYMBOL); NO_SEMICOLON_BEFORE.add(SCLTerminals.THEN); + NO_SEMICOLON_BEFORE.add(SCLTerminals.ELSE); NO_SEMICOLON_BEFORE.add(SCLTerminals.IN); NO_SEMICOLON_BEFORE.add(SCLTerminals.RBRACE); NO_SEMICOLON_BEFORE.add(SCLTerminals.RBRACKET); @@ -145,7 +146,7 @@ public class SCLPostLexer { int loc = Locations.endOf(prevToken.location); push(new Token(SCLTerminals.RBRACE, loc, loc, "implicit }")); } - if(indentations.get(indentations.size()-1) == level && symbolId != SCLTerminals.ELSE) + if(indentations.get(indentations.size()-1) == level) push(new Token(SCLTerminals.SEMICOLON, symbolStart, symbolStart, "implicit ;")); } } @@ -175,7 +176,7 @@ public class SCLPostLexer { case SCLTerminals.RBRACE: case SCLTerminals.RPAREN: case SCLTerminals.RBRACKET: - //case SCLTerminals.ELSE: + case SCLTerminals.ELSE: case SCLTerminals.IN: int removedToken = SCLTerminals.EOF; while(!indentations.isEmpty()) { @@ -188,11 +189,15 @@ public class SCLPostLexer { } if(indentations.isEmpty()) throw error(symbolStart, symbolEnd, "No corresponding opening parenthesis for '" + symbol.text + "'."); - if(symbolId == SCLTerminals.THEN && removedToken == SCLTerminals.WHEN) - curToken = symbol = new Token(SCLTerminals.THEN_AFTER_WHEN, symbol.location, symbol.text); + if(symbolId == SCLTerminals.THEN) { + if(removedToken == SCLTerminals.WHEN) + curToken = symbol = new Token(SCLTerminals.THEN_AFTER_WHEN, symbol.location, symbol.text); + else { + indentations.add(-1); + indentationTokens.add(SCLTerminals.THEN); + } + } push(symbol); - //if(symbolId == SCLTerminals.THEN) - // indentations.add(-1); return; case SCLTerminals.EOF: while(indentations.size() > 1 && indentations.get(indentations.size()-1) >= 0) { diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java index 527744c00..347191a3f 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ModuleRegressionTests.java @@ -77,7 +77,7 @@ public class ModuleRegressionTests extends TestBase { @Test public void Guards1() { test(); } @Test public void Guards2() { test(); } @Test public void IdAsOperator() { test(); } - @Test public void IfWithoutElse() { test(); } + //@Test public void IfWithoutElse() { test(); } @Test public void IllegalChar() { test(); } @Test public void ImportJavaConstructor() { test(); } @Test public void ImportRef() { test(); } -- 2.47.1