Search in sources :

Example 1 with AttributeReference

use of org.apache.asterix.external.classad.AttributeReference in project asterixdb by apache.

the class ClassAdParser method parsePostfixExpression.

// PostfixExpression .= PrimaryExpression
// | PostfixExpression '.' Identifier
// | PostfixExpression '[' Expression ']'
private boolean parsePostfixExpression(ExprTreeHolder tree) throws IOException {
    TokenType tt;
    if (!parsePrimaryExpression(tree)) {
        return false;
    }
    while ((tt = lexer.peekToken()) == TokenType.LEX_OPEN_BOX || tt == TokenType.LEX_SELECTION) {
        ExprTreeHolder treeL = tree;
        ExprTreeHolder treeR = objectPool.mutableExprPool.get();
        TokenValue tv = objectPool.tokenValuePool.get();
        lexer.consumeToken();
        if (tt == TokenType.LEX_OPEN_BOX) {
            // subscript operation
            parseExpression(treeR);
            if (treeL.getInnerTree() != null && treeR.getInnerTree() != null) {
                Operation newTree = objectPool.operationPool.get();
                Operation.createOperation(Operation.OpKind_SUBSCRIPT_OP, treeL, treeR, null, newTree);
                if (lexer.consumeToken() == TokenType.LEX_CLOSE_BOX) {
                    tree.setInnerTree(newTree);
                    continue;
                }
            }
            tree.setInnerTree(null);
            return false;
        } else if (tt == TokenType.LEX_SELECTION) {
            // field selection operation
            if ((tt = lexer.consumeToken(tv)) != TokenType.LEX_IDENTIFIER) {
                throw new HyracksDataException("second argument of selector must be an " + "identifier (got" + String.valueOf(Lexer.strLexToken(tt)) + ")");
            }
            AttributeReference newTree = objectPool.attrRefPool.get();
            AttributeReference.createAttributeReference(treeL, tv.getStrValue(), false, newTree);
            tree.setInnerTree(newTree);
        }
    }
    return true;
}
Also used : TokenType(org.apache.asterix.external.classad.Lexer.TokenType) ExprTreeHolder(org.apache.asterix.external.classad.ExprTreeHolder) AttributeReference(org.apache.asterix.external.classad.AttributeReference) Operation(org.apache.asterix.external.classad.Operation) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) TokenValue(org.apache.asterix.external.classad.TokenValue)

Aggregations

AttributeReference (org.apache.asterix.external.classad.AttributeReference)1 ExprTreeHolder (org.apache.asterix.external.classad.ExprTreeHolder)1 TokenType (org.apache.asterix.external.classad.Lexer.TokenType)1 Operation (org.apache.asterix.external.classad.Operation)1 TokenValue (org.apache.asterix.external.classad.TokenValue)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1