use of org.apache.druid.math.expr.antlr.ExprLexer in project druid by druid-io.
the class Parser method parse.
@VisibleForTesting
public static Expr parse(String in, ExprMacroTable macroTable, boolean withFlatten) {
ExprLexer lexer = new ExprLexer(new ANTLRInputStream(in));
CommonTokenStream tokens = new CommonTokenStream(lexer);
ExprParser parser = new ExprParser(tokens);
parser.setBuildParseTree(true);
ParseTree parseTree = parser.expr();
ParseTreeWalker walker = new ParseTreeWalker();
ExprListenerImpl listener = new ExprListenerImpl(parseTree, macroTable);
walker.walk(listener, parseTree);
Expr parsed = listener.getAST();
if (parsed == null) {
throw new RE("Failed to parse expression: %s", in);
}
return withFlatten ? flatten(parsed) : parsed;
}
Aggregations