Search in sources :

Example 6 with ExprLexer

use of org.apache.drill.common.expression.parser.ExprLexer in project drill by apache.

the class LogicalExpressionParser method parse.

/**
 * Initializes logical expression lexer and parser, add error listener that converts all
 * syntax error into {@link org.apache.drill.common.exceptions.ExpressionParsingException}.
 * Parses given expression into logical expression instance.
 *
 * @param expr expression to be parsed
 * @return logical expression instance
 */
public static LogicalExpression parse(String expr) {
    ExprLexer lexer = new ExprLexer(CharStreams.fromString(expr));
    // need to remove since default listener will output warning
    lexer.removeErrorListeners();
    lexer.addErrorListener(ErrorListener.INSTANCE);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ExprParser parser = new ExprParser(tokens);
    // need to remove since default listener will output warning
    parser.removeErrorListeners();
    parser.addErrorListener(ErrorListener.INSTANCE);
    ExprParser.ParseContext parseContext = parser.parse();
    logger.trace("Tokens: [{}]. Parsing details: [{}].", tokens.getText(), parseContext.toInfoString(parser));
    return parseContext.e;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) ExprLexer(org.apache.drill.common.expression.parser.ExprLexer) ExprParser(org.apache.drill.common.expression.parser.ExprParser)

Example 7 with ExprLexer

use of org.apache.drill.common.expression.parser.ExprLexer in project drill by apache.

the class PhysicalOpUnitTestBase method parseExpr.

@Override
protected LogicalExpression parseExpr(String expr) {
    ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ExprParser parser = new ExprParser(tokens);
    try {
        return parser.parse().e;
    } catch (RecognitionException e) {
        throw new RuntimeException("Error parsing expression: " + expr);
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) ExprLexer(org.apache.drill.common.expression.parser.ExprLexer) ExprParser(org.apache.drill.common.expression.parser.ExprParser) RecognitionException(org.antlr.runtime.RecognitionException)

Example 8 with ExprLexer

use of org.apache.drill.common.expression.parser.ExprLexer in project drill by apache.

the class TestEvaluationVisitor method getExpr.

private LogicalExpression getExpr(String expr) throws Exception {
    ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    //    tokens.fill();
    //    for(Token t : (List<Token>) tokens.getTokens()){
    //      System.out.println(t + "" + t.getType());
    //    }
    //    tokens.rewind();
    ExprParser parser = new ExprParser(tokens);
    parse_return ret = parser.parse();
    return ret.e;
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) ExprLexer(org.apache.drill.common.expression.parser.ExprLexer) ExprParser.parse_return(org.apache.drill.common.expression.parser.ExprParser.parse_return) ExprParser(org.apache.drill.common.expression.parser.ExprParser)

Example 9 with ExprLexer

use of org.apache.drill.common.expression.parser.ExprLexer in project drill by apache.

the class ExecTest method parseExpr.

protected LogicalExpression parseExpr(String expr) throws RecognitionException {
    final ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
    final CommonTokenStream tokens = new CommonTokenStream(lexer);
    final ExprParser parser = new ExprParser(tokens);
    final ExprParser.parse_return ret = parser.parse();
    return ret.e;
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) ExprLexer(org.apache.drill.common.expression.parser.ExprLexer) ExprParser(org.apache.drill.common.expression.parser.ExprParser)

Example 10 with ExprLexer

use of org.apache.drill.common.expression.parser.ExprLexer in project drill by axbaretto.

the class TestEvaluationVisitor method getExpr.

private LogicalExpression getExpr(String expr) throws Exception {
    ExprLexer lexer = new ExprLexer(new ANTLRStringStream(expr));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ExprParser parser = new ExprParser(tokens);
    parse_return ret = parser.parse();
    return ret.e;
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) ExprLexer(org.apache.drill.common.expression.parser.ExprLexer) ExprParser.parse_return(org.apache.drill.common.expression.parser.ExprParser.parse_return) ExprParser(org.apache.drill.common.expression.parser.ExprParser)

Aggregations

ExprLexer (org.apache.drill.common.expression.parser.ExprLexer)11 ExprParser (org.apache.drill.common.expression.parser.ExprParser)11 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)10 CommonTokenStream (org.antlr.runtime.CommonTokenStream)10 RecognitionException (org.antlr.runtime.RecognitionException)6 SchemaPath (org.apache.drill.common.expression.SchemaPath)3 ExprParser.parse_return (org.apache.drill.common.expression.parser.ExprParser.parse_return)3 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1