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;
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations