Skip to content

Commit

Permalink
Teiid 8 Parser updating to support 8.5-8.7
Browse files Browse the repository at this point in the history
* commit 'TEIID-247 exposing support for array types'
  • Loading branch information
Paul Richardson committed Mar 27, 2014
1 parent 97d92f4 commit 8027e03
Showing 1 changed file with 55 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4132,9 +4132,12 @@ Expression unsignedValueExpressionPrimary(ParseInfo info) :
Integer index = null;
Expression condition = null;
Expression indexExpr = null;
List<Expression> indexExprs = null;
Expression arrayExpression = null;
List<Expression> arrayExpressions = null;
}
{
(
(
// Reference
<QMARK> {return reference(info.incrementReferenceCount());}
|
Expand All @@ -4160,25 +4163,41 @@ Expression unsignedValueExpressionPrimary(ParseInfo info) :
if(isStringLiteral(symbolImage, info)) {
return constant(normalizeStringLiteral(symbolImage));
}
} | symbol=nonReserved())
(<LSBRACE> indexExpr = commonValueExpression(info) <RSBRACE>)?
} | symbol=nonReserved())
)
|
LOOKAHEAD(subquery(info)) subquery = subquery(info)
|
( <LPAREN>
expression = expression(info)
( <LPAREN>
[expression = expression(info)
(LOOKAHEAD(2) <COMMA> arrayExpression = expression(info) {
requires(versionAtLeast(Version.TEIID_8_5));
if (expression != null) {
arrayExpressions = arrayExpressions(arrayExpressions, expression);
expression = null;
}
arrayExpressions = arrayExpressions(arrayExpressions, arrayExpression); })*]
[<COMMA>
{
requires(versionAtLeast(Version.TEIID_8_5));
arrayExpressions = arrayExpressions(arrayExpressions, expression);
} ]
<RPAREN>
(<LSBRACE> indexExpr = commonValueExpression(info) <RSBRACE>)?
)
|
// Searched CASE expressions
LOOKAHEAD(2) expression = searchedCaseExpression(info)
|
// Non-searched CASE expressions
expression = caseExpression(info)
)

)

//array element reference expressions
(<LSBRACE> indexExpr = plusExpression(info) <RSBRACE> {
indexExprs = arrayExpressions(indexExprs, indexExpr);
}
)*

{
if(symbol != null) {
expression = elementSymbol(normalizeId(symbol.image));
Expand All @@ -4192,12 +4211,24 @@ Expression unsignedValueExpressionPrimary(ParseInfo info) :
((AggregateSymbol)expression).setCondition(condition);
}
}
if (indexExpr != null) {
Function function = createASTNode(ASTNodes.FUNCTION);
function.setName("array_get"); //$NON-NLS-1$
function.setArgs(new Expression[] {expression, indexExpr});
expression = function;
}

if (arrayExpressions != null) {
Array array = array();
array.setExpressions(arrayExpressions);
expression = array;
} else if (expression == null) {
Array array = array();
array.setExpressions(new ArrayList<Expression>(0));
expression = array;
}
if (indexExprs != null) {
for (Expression ex : indexExprs) {
Function function = createASTNode(ASTNodes.FUNCTION);
function.setName("array_get"); //$NON-NLS-1$
function.setArgs(new Expression[] {expression, ex});
expression = function;
}
}
return expression;
}
}
Expand Down Expand Up @@ -4819,6 +4850,7 @@ ParsedDataType parseDataType() :
Integer length = null;
Integer scale = null;
boolean precision = true;
int arraySuffixes = 0;
}
{
(
Expand Down Expand Up @@ -4849,15 +4881,20 @@ ParsedDataType parseDataType() :
typeToken = <XML>

)


(<LSBRACE><RSBRACE> { requires(versionAtLeast(Version.TEIID_8_5)); arraySuffixes++;})*
{
String typeName = typeToken.image;
if (arraySuffixes > 0) {
typeName += StringUtil.join(Collections.nCopies(arraySuffixes, "[]"), "");
}
if (scale != null){
return new ParsedDataType(typeToken.image, length, scale, precision);
return new ParsedDataType(typeName, length, scale, precision);
}
else if (length != null){
return new ParsedDataType(typeToken.image, length, precision);
return new ParsedDataType(typeName, length, precision);
}
return new ParsedDataType(typeToken.image);
return new ParsedDataType(typeName);
}
}

Expand Down

0 comments on commit 8027e03

Please sign in to comment.