Search in sources :

Example 31 with CommonTokenStream

use of org.antlr.v4.runtime.CommonTokenStream in project syncope by apache.

the class SearchCondConverter method convert.

public static SearchCond convert(final SearchCondVisitor visitor, final String filter) {
    SCIMFilterParser parser = new SCIMFilterParser(new CommonTokenStream(new SCIMFilterLexer(CharStreams.fromString(filter))));
    parser.setBuildParseTree(true);
    parser.setTrimParseTree(true);
    parser.setProfile(true);
    parser.removeErrorListeners();
    parser.setErrorHandler(new SCIMFilterErrorHandler());
    try {
        return visitor.visit(parser.scimFilter());
    } catch (Exception e) {
        LOG.error("Could not parse '{}'", filter, e);
        throw new BadRequestException(ErrorType.invalidFilter, "Could not parse '" + filter + "'");
    }
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) BadRequestException(org.apache.syncope.ext.scimv2.api.BadRequestException) BadRequestException(org.apache.syncope.ext.scimv2.api.BadRequestException)

Example 32 with CommonTokenStream

use of org.antlr.v4.runtime.CommonTokenStream in project ballerina by ballerina-lang.

the class SiddhiCompiler method parse.

public static SiddhiApp parse(String source) {
    ANTLRInputStream input = new ANTLRInputStream(source);
    SiddhiQLLexer lexer = new SiddhiQLLexer(input);
    lexer.removeErrorListeners();
    lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    SiddhiQLParser parser = new SiddhiQLParser(tokens);
    // parser.setErrorHandler(new BailErrorStrategy());
    parser.removeErrorListeners();
    parser.addErrorListener(SiddhiErrorListener.INSTANCE);
    ParseTree tree = parser.parse();
    SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
    return (SiddhiApp) eval.visit(tree);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) SiddhiApp(org.ballerinalang.siddhi.query.api.SiddhiApp) SiddhiQLBaseVisitorImpl(org.ballerinalang.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 33 with CommonTokenStream

use of org.antlr.v4.runtime.CommonTokenStream in project ballerina by ballerina-lang.

the class SiddhiCompiler method parseStoreQuery.

public static StoreQuery parseStoreQuery(String storeQuery) throws SiddhiParserException {
    ANTLRInputStream input = new ANTLRInputStream(storeQuery);
    SiddhiQLLexer lexer = new SiddhiQLLexer(input);
    lexer.removeErrorListeners();
    lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    SiddhiQLParser parser = new SiddhiQLParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(SiddhiErrorListener.INSTANCE);
    ParseTree tree = parser.store_query_final();
    SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
    return (StoreQuery) eval.visit(tree);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) StoreQuery(org.ballerinalang.siddhi.query.api.execution.query.StoreQuery) SiddhiQLBaseVisitorImpl(org.ballerinalang.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 34 with CommonTokenStream

use of org.antlr.v4.runtime.CommonTokenStream in project ballerina by ballerina-lang.

the class SiddhiCompiler method parseQuery.

public static Query parseQuery(String source) throws SiddhiParserException {
    ANTLRInputStream input = new ANTLRInputStream(source);
    SiddhiQLLexer lexer = new SiddhiQLLexer(input);
    lexer.removeErrorListeners();
    lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    SiddhiQLParser parser = new SiddhiQLParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(SiddhiErrorListener.INSTANCE);
    ParseTree tree = parser.query_final();
    SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
    return (Query) eval.visit(tree);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) Query(org.ballerinalang.siddhi.query.api.execution.query.Query) StoreQuery(org.ballerinalang.siddhi.query.api.execution.query.StoreQuery) SiddhiQLBaseVisitorImpl(org.ballerinalang.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 35 with CommonTokenStream

use of org.antlr.v4.runtime.CommonTokenStream in project ballerina by ballerina-lang.

the class SiddhiCompiler method parseTableDefinition.

public static TableDefinition parseTableDefinition(String source) throws SiddhiParserException {
    ANTLRInputStream input = new ANTLRInputStream(source);
    SiddhiQLLexer lexer = new SiddhiQLLexer(input);
    lexer.removeErrorListeners();
    lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    SiddhiQLParser parser = new SiddhiQLParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(SiddhiErrorListener.INSTANCE);
    ParseTree tree = parser.definition_table_final();
    SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
    return (TableDefinition) eval.visit(tree);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) TableDefinition(org.ballerinalang.siddhi.query.api.definition.TableDefinition) SiddhiQLBaseVisitorImpl(org.ballerinalang.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Aggregations

CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)339 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)144 Test (org.junit.Test)110 LexerInterpreter (org.antlr.v4.runtime.LexerInterpreter)104 ParseTree (org.antlr.v4.runtime.tree.ParseTree)97 TokenStreamRewriter (org.antlr.v4.runtime.TokenStreamRewriter)90 LexerGrammar (org.antlr.v4.tool.LexerGrammar)88 CharStream (org.antlr.v4.runtime.CharStream)69 BaseJavaTest (org.antlr.v4.test.runtime.java.BaseJavaTest)43 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)38 IOException (java.io.IOException)29 RecognitionException (org.antlr.v4.runtime.RecognitionException)27 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)26 Token (org.antlr.v4.runtime.Token)24 ParseCancellationException (org.antlr.v4.runtime.misc.ParseCancellationException)22 ConsoleErrorListener (org.antlr.v4.runtime.ConsoleErrorListener)21 CancellationException (java.util.concurrent.CancellationException)20 ByteArrayInputStream (java.io.ByteArrayInputStream)16 Utils.toCharStream (clawfc.Utils.toCharStream)15 ArrayList (java.util.ArrayList)15