use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.
the class ClassAdParser method parseLogicalORExpression.
// LogicalORExpression .= LogicalANDExpression
// | LogicalORExpression '||' LogicalANDExpression
private boolean parseLogicalORExpression(ExprTreeHolder tree) throws IOException {
if (!parseLogicalANDExpression(tree)) {
return false;
}
while ((lexer.peekToken()) == TokenType.LEX_LOGICAL_OR) {
ExprTreeHolder treeL = tree;
ExprTreeHolder treeR = objectPool.mutableExprPool.get();
lexer.consumeToken();
parseLogicalANDExpression(treeR);
if (treeL.getInnerTree() != null && treeR.getInnerTree() != null) {
Operation newTree = objectPool.operationPool.get();
Operation.createOperation(Operation.OpKind_LOGICAL_OR_OP, treeL, treeR, null, newTree);
tree.setInnerTree(newTree);
} else {
tree.setInnerTree(null);
return false;
}
}
return true;
}
use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.
the class ClassAdParser method parsePrimaryExpression.
// PrimaryExpression .= Identifier
// | FunctionCall
// | '.' Identifier
// | '(' Expression ')'
// | Literal
// FunctionCall .= Identifier ArgumentList
// ( Constant may be
// boolean,undefined,error,string,integer,real,classad,list )
// ( ArgumentList non-terminal includes parentheses )
private boolean parsePrimaryExpression(ExprTreeHolder tree) throws IOException {
ExprTreeHolder treeL;
TokenValue tv = objectPool.tokenValuePool.get();
TokenType tt;
tree.setInnerTree(null);
switch((tt = lexer.peekToken(tv))) {
// identifiers
case LEX_IDENTIFIER:
isExpr = true;
lexer.consumeToken();
// check for funcion call
if ((tt = lexer.peekToken()) == TokenType.LEX_OPEN_PAREN) {
ExprList argList = objectPool.exprListPool.get();
if (!parseArgumentList(argList)) {
tree.setInnerTree(null);
return false;
}
;
// string literal
if (shouldEvaluateAtParseTime(tv.getStrValue().toString(), argList)) {
tree.setInnerTree(evaluateFunction(tv.getStrValue().toString(), argList));
} else {
tree.setInnerTree(FunctionCall.createFunctionCall(tv.getStrValue().toString(), argList, objectPool));
}
} else {
// I don't think this is ever hit
tree.setInnerTree(AttributeReference.createAttributeReference(null, tv.getStrValue(), false, objectPool));
}
return (tree.getInnerTree() != null);
case LEX_SELECTION:
isExpr = true;
lexer.consumeToken();
if ((tt = lexer.consumeToken(tv)) == TokenType.LEX_IDENTIFIER) {
// the boolean final arg signifies that reference is absolute
tree.setInnerTree(AttributeReference.createAttributeReference(null, tv.getStrValue(), true, objectPool));
return (tree.size() != 0);
}
// not an identifier following the '.'
throw new HyracksDataException("need identifier in selection expression (got" + Lexer.strLexToken(tt) + ")");
// parenthesized expression
case LEX_OPEN_PAREN:
{
isExpr = true;
lexer.consumeToken();
treeL = objectPool.mutableExprPool.get();
parseExpression(treeL);
if (treeL.getInnerTree() == null) {
tree.resetExprTree(null);
return false;
}
if ((tt = lexer.consumeToken()) != TokenType.LEX_CLOSE_PAREN) {
throw new HyracksDataException("exptected LEX_CLOSE_PAREN, but got " + Lexer.strLexToken(tt));
// tree.resetExprTree(null);
// return false;
}
// assume make operation will return a new tree
tree.setInnerTree(Operation.createOperation(Operation.OpKind_PARENTHESES_OP, treeL, objectPool));
return (tree.size() != 0);
}
// constants
case LEX_OPEN_BOX:
{
isExpr = true;
ClassAd newAd = objectPool.classAdPool.get();
if (!parseClassAd(newAd)) {
tree.resetExprTree(null);
return false;
}
tree.setInnerTree(newAd);
}
return true;
case LEX_OPEN_BRACE:
{
isExpr = true;
ExprList newList = objectPool.exprListPool.get();
if (!parseExprList(newList)) {
tree.setInnerTree(null);
return false;
}
tree.setInnerTree(newList);
}
return true;
case LEX_UNDEFINED_VALUE:
{
Value val = objectPool.valuePool.get();
lexer.consumeToken();
val.setUndefinedValue();
tree.setInnerTree(Literal.createLiteral(val, objectPool));
return (tree.getInnerTree() != null);
}
case LEX_ERROR_VALUE:
{
Value val = objectPool.valuePool.get();
lexer.consumeToken();
val.setErrorValue();
tree.setInnerTree(Literal.createLiteral(val, objectPool));
return (tree.getInnerTree() != null);
}
case LEX_BOOLEAN_VALUE:
{
Value val = objectPool.valuePool.get();
MutableBoolean b = new MutableBoolean();
tv.getBoolValue(b);
lexer.consumeToken();
val.setBooleanValue(b);
tree.setInnerTree(Literal.createLiteral(val, objectPool));
return (tree.getInnerTree() != null);
}
case LEX_INTEGER_VALUE:
{
Value val = objectPool.valuePool.get();
lexer.consumeToken();
val.setIntegerValue(tv.getIntValue());
tree.setInnerTree(Literal.createLiteral(val, tv.getFactor(), objectPool));
return (tree.getInnerTree() != null);
}
case LEX_REAL_VALUE:
{
Value val = objectPool.valuePool.get();
lexer.consumeToken();
val.setRealValue(tv.getRealValue());
tree.setInnerTree(Literal.createLiteral(val, tv.getFactor(), objectPool));
return (tree.getInnerTree() != null);
}
case LEX_STRING_VALUE:
{
Value val = objectPool.valuePool.get();
lexer.consumeToken();
val.setStringValue(tv.getStrValue());
tree.setInnerTree(Literal.createLiteral(val, objectPool));
return (tree.getInnerTree() != null);
}
case LEX_ABSOLUTE_TIME_VALUE:
{
Value val = objectPool.valuePool.get();
lexer.consumeToken();
val.setAbsoluteTimeValue(tv.getTimeValue());
tree.setInnerTree(Literal.createLiteral(val, objectPool));
return (tree.getInnerTree() != null);
}
case LEX_RELATIVE_TIME_VALUE:
{
Value val = objectPool.valuePool.get();
lexer.consumeToken();
val.setRelativeTimeValue(tv.getTimeValue().getRelativeTime());
tree.setInnerTree(Literal.createLiteral(val, objectPool));
return (tree.getInnerTree() != null);
}
default:
tree.setInnerTree(null);
return false;
}
}
use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.
the class ClassAdParser method parseEqualityExpression.
// EqualityExpression .= RelationalExpression
// | EqualityExpression '==' RelationalExpression
// | EqualityExpression '!=' RelationalExpression
// | EqualityExpression '=?=' RelationalExpression
// | EqualityExpression '=!=' RelationalExpression
private boolean parseEqualityExpression(ExprTreeHolder tree) throws IOException {
TokenType tt;
int op = Operation.OpKind_NO_OP;
if (!parseRelationalExpression(tree)) {
return false;
}
tt = lexer.peekToken();
while (tt == TokenType.LEX_EQUAL || tt == TokenType.LEX_NOT_EQUAL || tt == TokenType.LEX_META_EQUAL || tt == TokenType.LEX_META_NOT_EQUAL) {
ExprTreeHolder treeL = tree;
ExprTreeHolder treeR = objectPool.mutableExprPool.get();
lexer.consumeToken();
parseRelationalExpression(treeR);
switch(tt) {
case LEX_EQUAL:
op = Operation.OpKind_EQUAL_OP;
break;
case LEX_NOT_EQUAL:
op = Operation.OpKind_NOT_EQUAL_OP;
break;
case LEX_META_EQUAL:
op = Operation.OpKind_META_EQUAL_OP;
break;
case LEX_META_NOT_EQUAL:
op = Operation.OpKind_META_NOT_EQUAL_OP;
break;
default:
throw new HyracksDataException("ClassAd: Should not reach here");
}
if (treeL.getInnerTree() != null && treeR.getInnerTree() != null) {
Operation newTree = objectPool.operationPool.get();
Operation.createOperation(op, treeL, treeR, null, newTree);
tree.setInnerTree(newTree);
} else {
tree.setInnerTree(null);
return false;
}
tt = lexer.peekToken();
}
return true;
}
use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.
the class ClassAdParser method parseExpression.
private boolean parseExpression(ExprTreeHolder tree, boolean full) throws IOException {
TokenType tt;
if (!parseLogicalORExpression(tree)) {
return false;
}
if ((tt = lexer.peekToken()) == TokenType.LEX_QMARK) {
lexer.consumeToken();
ExprTreeHolder treeL = tree;
ExprTreeHolder treeM = objectPool.mutableExprPool.get();
ExprTreeHolder treeR = objectPool.mutableExprPool.get();
parseExpression(treeM);
if ((tt = lexer.consumeToken()) != TokenType.LEX_COLON) {
throw new HyracksDataException("expected LEX_COLON, but got " + Lexer.strLexToken(tt));
}
parseExpression(treeR);
if (treeL.getInnerTree() != null && treeM.getInnerTree() != null && treeR.getInnerTree() != null) {
Operation newTree = objectPool.operationPool.get();
Operation.createOperation(Operation.OpKind_TERNARY_OP, treeL, treeM, treeR, newTree);
tree.setInnerTree(newTree);
return (true);
}
tree.setInnerTree(null);
return false;
}
// if a full parse was requested, ensure that input is exhausted
if (full && (lexer.consumeToken() != TokenType.LEX_END_OF_INPUT)) {
throw new HyracksDataException("expected LEX_END_OF_INPUT on full parse, but got " + String.valueOf(Lexer.strLexToken(tt)));
}
return true;
}
use of org.apache.asterix.external.classad.ExprTreeHolder in project asterixdb by apache.
the class ClassAdParser method parseNextExpression.
public ExprTree parseNextExpression() throws IOException {
if (!lexer.wasInitialized()) {
return null;
} else {
ExprTreeHolder expr = objectPool.mutableExprPool.get();
parseExpression(expr, false);
ExprTree innerTree = expr.getInnerTree();
return innerTree;
}
}
Aggregations