Search in sources :

Example 31 with Lexer

use of org.antlr.v4.runtime.Lexer 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)

Example 32 with Lexer

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

the class SiddhiCompiler method parseTimeConstantDefinition.

public static TimeConstant parseTimeConstantDefinition(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.time_value();
    SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
    return (TimeConstant) eval.visit(tree);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) SiddhiQLBaseVisitorImpl(org.ballerinalang.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree) TimeConstant(org.ballerinalang.siddhi.query.api.expression.constant.TimeConstant)

Example 33 with Lexer

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

the class SiddhiCompiler method parsePartition.

public static Partition parsePartition(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.partition_final();
    SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
    return (Partition) eval.visit(tree);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) Partition(org.ballerinalang.siddhi.query.api.execution.partition.Partition) SiddhiQLBaseVisitorImpl(org.ballerinalang.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 34 with Lexer

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

the class SiddhiCompiler method parseFunctionDefinition.

public static FunctionDefinition parseFunctionDefinition(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_function_final();
    SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
    return (FunctionDefinition) eval.visit(tree);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) FunctionDefinition(org.ballerinalang.siddhi.query.api.definition.FunctionDefinition) SiddhiQLBaseVisitorImpl(org.ballerinalang.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 35 with Lexer

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

the class Parser method generateCompilationUnit.

private CompilationUnitNode generateCompilationUnit(PackageSourceEntry sourceEntry) {
    try {
        int prevErrCount = dlog.errorCount;
        BDiagnosticSource diagnosticSrc = getDiagnosticSource(sourceEntry);
        String entryName = sourceEntry.getEntryName();
        BLangCompilationUnit compUnit = (BLangCompilationUnit) TreeBuilder.createCompilationUnit();
        compUnit.setName(sourceEntry.getEntryName());
        compUnit.pos = new DiagnosticPos(diagnosticSrc, 1, 1, 1, 1);
        ANTLRInputStream ais = new ANTLRInputStream(new ByteArrayInputStream(sourceEntry.getCode()));
        ais.name = entryName;
        BallerinaLexer lexer = new BallerinaLexer(ais);
        lexer.removeErrorListeners();
        lexer.addErrorListener(new BallerinaParserErrorListener(context, diagnosticSrc));
        CommonTokenStream tokenStream = new CommonTokenStream(lexer);
        BallerinaParser parser = new BallerinaParser(tokenStream);
        parser.setErrorHandler(getErrorStrategy(diagnosticSrc));
        parser.addParseListener(newListener(tokenStream, compUnit, diagnosticSrc));
        parser.compilationUnit();
        return compUnit;
    } catch (IOException e) {
        throw new RuntimeException("Error in populating package model: " + e.getMessage(), e);
    }
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) BDiagnosticSource(org.wso2.ballerinalang.compiler.util.diagnotic.BDiagnosticSource) IOException(java.io.IOException) BallerinaParser(org.wso2.ballerinalang.compiler.parser.antlr4.BallerinaParser) DiagnosticPos(org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos) ByteArrayInputStream(java.io.ByteArrayInputStream) BallerinaParserErrorListener(org.wso2.ballerinalang.compiler.parser.antlr4.BallerinaParserErrorListener) BLangCompilationUnit(org.wso2.ballerinalang.compiler.tree.BLangCompilationUnit) BallerinaLexer(org.wso2.ballerinalang.compiler.parser.antlr4.BallerinaLexer) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream)

Aggregations

Test (org.junit.Test)427 LexerGrammar (org.antlr.v4.tool.LexerGrammar)407 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)279 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)143 Grammar (org.antlr.v4.tool.Grammar)125 LexerInterpreter (org.antlr.v4.runtime.LexerInterpreter)108 CharStream (org.antlr.v4.runtime.CharStream)103 ParseTree (org.antlr.v4.runtime.tree.ParseTree)91 TokenStreamRewriter (org.antlr.v4.runtime.TokenStreamRewriter)86 ATN (org.antlr.v4.runtime.atn.ATN)56 IOException (java.io.IOException)45 BaseJavaTest (org.antlr.v4.test.runtime.java.BaseJavaTest)43 Token (org.antlr.v4.runtime.Token)41 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)39 ArrayList (java.util.ArrayList)37 RecognitionException (org.antlr.v4.runtime.RecognitionException)26 StringReader (java.io.StringReader)23 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)23 TokenStream (org.antlr.v4.runtime.TokenStream)23 Lexer (org.antlr.v4.runtime.Lexer)22