Search in sources :

Example 71 with Tree

use of org.antlr.v4.runtime.tree.Tree in project hive by apache.

the class Exec method include.

/**
 * Execute statements from an include file
 */
void include(String content) throws Exception {
    InputStream input = new ByteArrayInputStream(content.getBytes("UTF-8"));
    HplsqlLexer lexer = new HplsqlLexer(new ANTLRInputStream(input));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    HplsqlParser parser = new HplsqlParser(tokens);
    ParseTree tree = parser.program();
    visit(tree);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 72 with Tree

use of org.antlr.v4.runtime.tree.Tree in project metron by apache.

the class WindowProcessor method syntaxTree.

/**
 * Create a textual representation of the syntax tree.  This is useful for those intrepid souls
 * who wish to extend the window selector language.  God speed.
 * @param statement
 * @return  A string representation of the syntax tree.
 */
public static String syntaxTree(String statement) {
    TokenStream tokens = createTokenStream(statement);
    if (tokens == null) {
        return null;
    }
    WindowParser parser = createParser(tokens, Optional.empty());
    ParseTree tree = parser.window();
    return GrammarUtils.toSyntaxTree(tree);
}
Also used : WindowParser(org.apache.metron.profiler.client.window.generated.WindowParser) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 73 with Tree

use of org.antlr.v4.runtime.tree.Tree in project grakn by graknlabs.

the class TemplateParser method parseGraqlTemplate.

private ParseTree parseGraqlTemplate(CommonTokenStream tokens, GraqlErrorListener errorListener) {
    GraqlTemplateParser parser = new GraqlTemplateParser(tokens);
    parser.setBuildParseTree(true);
    parser.removeErrorListeners();
    parser.addErrorListener(errorListener);
    ParseTree tree = parser.template();
    if (errorListener.hasErrors()) {
        throw GraqlSyntaxException.create(errorListener.toString());
    }
    return tree;
}
Also used : GraqlTemplateParser(ai.grakn.graql.internal.antlr.GraqlTemplateParser) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 74 with Tree

use of org.antlr.v4.runtime.tree.Tree in project drools by kiegroup.

the class FEELImpl method compile.

@Override
public CompiledExpression compile(String expression, CompilerContext ctx) {
    FEEL_1_1Parser parser = FEELParser.parse(getEventsManager(ctx.getListeners()), expression, ctx.getInputVariableTypes(), ctx.getInputVariables(), ctx.getFEELFunctions(), profiles);
    ParseTree tree = parser.compilation_unit();
    ASTBuilderVisitor v = new ASTBuilderVisitor(ctx.getInputVariableTypes());
    BaseNode expr = v.visit(tree);
    CompiledExpression ce = new CompiledExpressionImpl(expr);
    return ce;
}
Also used : ASTBuilderVisitor(org.kie.dmn.feel.parser.feel11.ASTBuilderVisitor) BaseNode(org.kie.dmn.feel.lang.ast.BaseNode) FEEL_1_1Parser(org.kie.dmn.feel.parser.feel11.FEEL_1_1Parser) ParseTree(org.antlr.v4.runtime.tree.ParseTree) CompiledExpression(org.kie.dmn.feel.lang.CompiledExpression)

Aggregations

ParseTree (org.antlr.v4.runtime.tree.ParseTree)30 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)21 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)15 GrammarAST (org.antlr.v4.tool.ast.GrammarAST)12 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)9 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 BailErrorStrategy (org.antlr.v4.runtime.BailErrorStrategy)6 Tree (org.antlr.v4.runtime.tree.Tree)6 IOException (java.io.IOException)5 Tree (org.antlr.runtime.tree.Tree)4 ParserInterpreter (org.antlr.v4.runtime.ParserInterpreter)4 RecognitionException (org.antlr.v4.runtime.RecognitionException)4 Rectangle2D (java.awt.geom.Rectangle2D)3 FileInputStream (java.io.FileInputStream)3 Method (java.lang.reflect.Method)3 Map (java.util.Map)3 GrammarASTAdaptor (org.antlr.v4.parse.GrammarASTAdaptor)3