Search in sources :

Example 1 with TokenKind

use of com.google.devtools.build.lib.query2.engine.Lexer.TokenKind in project bazel by bazelbuild.

the class QueryParser method parseBinaryOperatorTail.

/**
   * tail ::= ( <op> <primary> )*
   * All operators have equal precedence.
   * This factoring is required for left-associative binary operators in LL(1).
   */
private QueryExpression parseBinaryOperatorTail(QueryExpression lhs) throws QueryException {
    if (!BINARY_OPERATORS.contains(token.kind)) {
        return lhs;
    }
    List<QueryExpression> operands = new ArrayList<>();
    operands.add(lhs);
    TokenKind lastOperator = token.kind;
    while (BINARY_OPERATORS.contains(token.kind)) {
        TokenKind operator = token.kind;
        consume(operator);
        if (operator != lastOperator) {
            lhs = new BinaryOperatorExpression(lastOperator, operands);
            operands.clear();
            operands.add(lhs);
            lastOperator = operator;
        }
        QueryExpression rhs = parsePrimary();
        operands.add(rhs);
    }
    return new BinaryOperatorExpression(lastOperator, operands);
}
Also used : TokenKind(com.google.devtools.build.lib.query2.engine.Lexer.TokenKind) ArrayList(java.util.ArrayList)

Aggregations

TokenKind (com.google.devtools.build.lib.query2.engine.Lexer.TokenKind)1 ArrayList (java.util.ArrayList)1