Adding support for accessing an item in list using non constant index
diff --git a/asterix-algebra/src/main/javacc/AQLPlus.jj b/asterix-algebra/src/main/javacc/AQLPlus.jj
index 95c6b2d..dd72de4 100644
--- a/asterix-algebra/src/main/javacc/AQLPlus.jj
+++ b/asterix-algebra/src/main/javacc/AQLPlus.jj
@@ -699,7 +699,7 @@
Expression expr = null;
Identifier ident = null;
AbstractAccessor fa = null;
- int index;
+ Expression indexExpr = null;
}
{
@@ -719,12 +719,12 @@
}
)
| (
- index = Index()
+ indexExpr = Index()
{
if(fa == null)
- fa = new IndexAccessor(expr, index);
+ fa = new IndexAccessor(expr, indexExpr);
else
- fa = new IndexAccessor(fa, index);
+ fa = new IndexAccessor(fa, indexExpr);
}
)
)*
@@ -751,10 +751,9 @@
}
}
-int Index() throws ParseException:
+Expression Index() throws ParseException:
{
Expression expr = null;
- int idx = -2;
}
{
"[" ( expr = Expression()
@@ -762,20 +761,15 @@
if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
{
Literal lit = ((LiteralExpr)expr).getValue();
- if(lit.getLiteralType() == Literal.Type.INTEGER ||
- lit.getLiteralType() == Literal.Type.LONG) {
- idx = Integer.valueOf(lit.getStringValue());
- }
- else {
+ if(lit.getLiteralType() != Literal.Type.INTEGER &&
+ lit.getLiteralType() != Literal.Type.LONG) {
throw new ParseException("Index should be an INTEGER");
}
}
-
}
| "?"
{
- idx = IndexAccessor.ANY;
// ANY
}
@@ -783,7 +777,7 @@
"]"
{
- return idx;
+ return expr;
}
}