Search in sources :

Example 1 with ExprParser

use of io.druid.math.expr.antlr.ExprParser in project druid by druid-io.

the class Parser method parse.

public static Expr parse(String in, 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);
    walker.walk(listener, parseTree);
    return withFlatten ? flatten(listener.getAST()) : listener.getAST();
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) ExprLexer(io.druid.math.expr.antlr.ExprLexer) ExprParser(io.druid.math.expr.antlr.ExprParser) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker)

Aggregations

ExprLexer (io.druid.math.expr.antlr.ExprLexer)1 ExprParser (io.druid.math.expr.antlr.ExprParser)1 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)1