Search in sources :

Example 1 with TopAntlrParser

use of org.finos.legend.pure.m3.serialization.grammar.top.antlr.TopAntlrParser in project legend-pure by finos.

the class TopParser method initAntlrParser.

private TopAntlrParser initAntlrParser(boolean fastParser, String code, String sourceName) {
    AntlrSourceInformation sourceInformation = new AntlrSourceInformation(0, 0, sourceName);
    AntlrDescriptiveErrorListener pureErrorListener = new AntlrDescriptiveErrorListener(sourceInformation);
    TopAntlrLexer lexer = new TopAntlrLexer(new ANTLRInputStream(code));
    lexer.removeErrorListeners();
    lexer.addErrorListener(pureErrorListener);
    TopAntlrParser parser = new TopAntlrParser(new CommonTokenStream(lexer));
    parser.removeErrorListeners();
    parser.addErrorListener(pureErrorListener);
    parser.setErrorHandler(new PureAntlrErrorStrategy(sourceInformation));
    parser.getInterpreter().setPredictionMode(fastParser ? PredictionMode.SLL : PredictionMode.LL);
    return parser;
}
Also used : TopAntlrParser(org.finos.legend.pure.m3.serialization.grammar.top.antlr.TopAntlrParser) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) AntlrDescriptiveErrorListener(org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrDescriptiveErrorListener) TopAntlrLexer(org.finos.legend.pure.m3.serialization.grammar.top.antlr.TopAntlrLexer) PureAntlrErrorStrategy(org.finos.legend.pure.m4.serialization.grammar.antlr.PureAntlrErrorStrategy) AntlrSourceInformation(org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream)

Example 2 with TopAntlrParser

use of org.finos.legend.pure.m3.serialization.grammar.top.antlr.TopAntlrParser in project legend-pure by finos.

the class TopParser method parseDefinition.

private MutableListMultimap<Parser, CoreInstance> parseDefinition(boolean useFastParser, String code, String sourceName, ModelRepository repository, ParserLibrary parserLibrary, M3M4StateListener listener, Context context, SourceState oldState) {
    TopAntlrParser parser = this.initAntlrParser(useFastParser, "\u005cn###Pure\u005cn" + code, sourceName);
    TopGraphBuilder visitor = new TopGraphBuilder(sourceName, repository, listener, context, parserLibrary, oldState);
    TopAntlrParser.DefinitionContext c = parser.definition();
    return visitor.visitDefinition(c);
}
Also used : TopAntlrParser(org.finos.legend.pure.m3.serialization.grammar.top.antlr.TopAntlrParser)

Aggregations

TopAntlrParser (org.finos.legend.pure.m3.serialization.grammar.top.antlr.TopAntlrParser)2 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 TopAntlrLexer (org.finos.legend.pure.m3.serialization.grammar.top.antlr.TopAntlrLexer)1 AntlrDescriptiveErrorListener (org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrDescriptiveErrorListener)1 AntlrSourceInformation (org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation)1 PureAntlrErrorStrategy (org.finos.legend.pure.m4.serialization.grammar.antlr.PureAntlrErrorStrategy)1