Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYvan Lussaud2017-09-20 12:04:52 +0000
committerYvan Lussaud2017-12-11 08:39:27 +0000
commit318f4eacbf11b138fc06112b67f45ecba07c0abe (patch)
tree1f81c1f6a461a7707974340018c01462d902e259
parent7da4f7e9ad6646d81a5e239dddeed4368297ad87 (diff)
downloadorg.eclipse.acceleo-318f4eacbf11b138fc06112b67f45ecba07c0abe.tar.gz
org.eclipse.acceleo-318f4eacbf11b138fc06112b67f45ecba07c0abe.tar.xz
org.eclipse.acceleo-318f4eacbf11b138fc06112b67f45ecba07c0abe.zip
Fixed parsing of Let without body.
-rw-r--r--query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/parser/AstBuilderListener.java22
-rw-r--r--query/tests/org.eclipse.acceleo.query.tests/src/org/eclipse/acceleo/query/parser/tests/BuildTest.java11
2 files changed, 27 insertions, 6 deletions
diff --git a/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/parser/AstBuilderListener.java b/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/parser/AstBuilderListener.java
index d3dba955d..d494e921a 100644
--- a/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/parser/AstBuilderListener.java
+++ b/query/plugins/org.eclipse.acceleo.query/src/org/eclipse/acceleo/query/parser/AstBuilderListener.java
@@ -983,6 +983,8 @@ public class AstBuilderListener extends QueryBaseListener {
if (!stack.isEmpty() && stack.peek() instanceof ErrorExpression) {
final ErrorExpression error = (ErrorExpression)pop();
errors.remove(error);
+ startPositions.remove(error);
+ endPositions.remove(error);
diagnostics.remove(diagnostics.size() - 1);
}
}
@@ -1674,18 +1676,26 @@ public class AstBuilderListener extends QueryBaseListener {
*/
@Override
public void exitLetExpr(LetExprContext ctx) {
- Expression body;
+ final Expression body;
+ final Binding[] bindings;
+
if (!(ctx.getChild(ctx.getChildCount() - 1) instanceof ExpressionContext)) {
+ popErrorExpression();
body = builder.errorExpression();
startPositions.put(body, Integer.valueOf(ctx.stop.getStopIndex() + 1));
endPositions.put(body, Integer.valueOf(ctx.stop.getStopIndex() + 1));
+ final List<Binding> bindingList = new ArrayList<Binding>();
+ while (!stack.isEmpty() && stack.peek() instanceof Binding) {
+ bindingList.add(popBinding());
+ }
+ bindings = bindingList.toArray(new Binding[bindingList.size()]);
} else {
body = popExpression();
- }
- int bindingNumber = 1 + (ctx.getChildCount() - 3) / 2;
- Binding[] bindings = new Binding[bindingNumber];
- for (int i = bindingNumber - 1; i >= 0; i--) {
- bindings[i] = popBinding();
+ int bindingNumber = 1 + (ctx.getChildCount() - 3) / 2;
+ bindings = new Binding[bindingNumber];
+ for (int i = bindingNumber - 1; i >= 0; i--) {
+ bindings[i] = popBinding();
+ }
}
final Let let = builder.let(body, bindings);
diff --git a/query/tests/org.eclipse.acceleo.query.tests/src/org/eclipse/acceleo/query/parser/tests/BuildTest.java b/query/tests/org.eclipse.acceleo.query.tests/src/org/eclipse/acceleo/query/parser/tests/BuildTest.java
index 7706e0d20..dff4cdf14 100644
--- a/query/tests/org.eclipse.acceleo.query.tests/src/org/eclipse/acceleo/query/parser/tests/BuildTest.java
+++ b/query/tests/org.eclipse.acceleo.query.tests/src/org/eclipse/acceleo/query/parser/tests/BuildTest.java
@@ -1157,6 +1157,17 @@ public class BuildTest {
}
@Test
+ public void LetNoIn() {
+ IQueryBuilderEngine.AstResult build = engine.build("let v = self.name");
+ final Expression ast = build.getAst();
+
+ assertExpression(build, Let.class, 0, 17, ast);
+ assertEquals(1, ((Let)ast).getBindings().size());
+ assertEquals("v", ((Let)ast).getBindings().get(0).getName());
+ assertExpression(build, ErrorExpression.class, 17, 17, ((Let)ast).getBody());
+ }
+
+ @Test
public void nullTest() {
IQueryBuilderEngine.AstResult build = engine.build(null);
Expression ast = build.getAst();

Back to the top