Search in sources :

Example 1 with AntlrSourceInformation

use of org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation in project legend-pure by finos.

the class NavigationParser method initAntlrParser.

private org.finos.legend.pure.m3.inlinedsl.path.serialization.grammar.NavigationParser initAntlrParser(boolean fastParser, String code, String sourceName, int offsetLine, int offsetColumn, boolean addLines) {
    this.sourceInformation = new AntlrSourceInformation(offsetLine, offsetColumn, sourceName, addLines);
    AntlrDescriptiveErrorListener pureErrorListener = new AntlrDescriptiveErrorListener(this.sourceInformation);
    NavigationLexer lexer = new NavigationLexer(new ANTLRInputStream(code));
    lexer.removeErrorListeners();
    lexer.addErrorListener(pureErrorListener);
    org.finos.legend.pure.m3.inlinedsl.path.serialization.grammar.NavigationParser parser = new org.finos.legend.pure.m3.inlinedsl.path.serialization.grammar.NavigationParser(new CommonTokenStream(lexer));
    parser.removeErrorListeners();
    parser.addErrorListener(pureErrorListener);
    parser.setErrorHandler(new PureAntlrErrorStrategy(this.sourceInformation));
    parser.getInterpreter().setPredictionMode(fastParser ? PredictionMode.SLL : PredictionMode.LL);
    return parser;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) AntlrDescriptiveErrorListener(org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrDescriptiveErrorListener) PureAntlrErrorStrategy(org.finos.legend.pure.m4.serialization.grammar.antlr.PureAntlrErrorStrategy) NavigationLexer(org.finos.legend.pure.m3.inlinedsl.path.serialization.grammar.NavigationLexer) AntlrSourceInformation(org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream)

Example 2 with AntlrSourceInformation

use of org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation in project legend-pure by finos.

the class GraphAntlrParser method initializeParser.

private GraphParser initializeParser(AntlrSourceInformation sourceInformation, boolean fastParser, String code) {
    AntlrDescriptiveErrorListener pureErrorListener = new AntlrDescriptiveErrorListener(sourceInformation);
    GraphLexer graphLexer = new GraphLexer(new ANTLRInputStream(code));
    graphLexer.removeErrorListeners();
    graphLexer.addErrorListener(pureErrorListener);
    GraphParser graphParser = new GraphParser(new CommonTokenStream(graphLexer));
    graphParser.removeErrorListeners();
    graphParser.addErrorListener(pureErrorListener);
    graphParser.setErrorHandler(new PureAntlrErrorStrategy(sourceInformation));
    graphParser.getInterpreter().setPredictionMode(fastParser ? PredictionMode.SLL : PredictionMode.LL);
    return graphParser;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) AntlrDescriptiveErrorListener(org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrDescriptiveErrorListener) GraphLexer(org.finos.legend.pure.m3.inlinedsl.graph.serialization.grammar.GraphLexer) GraphParser(org.finos.legend.pure.m3.inlinedsl.graph.serialization.grammar.GraphParser) PureAntlrErrorStrategy(org.finos.legend.pure.m4.serialization.grammar.antlr.PureAntlrErrorStrategy) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream)

Example 3 with AntlrSourceInformation

use of org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation 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 4 with AntlrSourceInformation

use of org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation in project legend-pure by finos.

the class M3AntlrParser method parseMappingInfo.

public TemporaryPureSetImplementation parseMappingInfo(String content, String classPath, AntlrContextToM3CoreInstance.LambdaContext lambdaContext, String sourceName, int offset, String importId, ModelRepository repository, ProcessorSupport processorSupport, final Context context) {
    AntlrSourceInformation sourceInformation = new AntlrSourceInformation(offset, 0, sourceName, true);
    org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser parser = initAntlrParser(true, content, sourceInformation);
    ImportGroup grp = (ImportGroup) processorSupport.package_getByUserPath("system::imports::" + importId);
    M3AntlrTreeWalker visitor = new M3AntlrTreeWalker(classPath, sourceInformation, this.inlineDSLLibrary, repository, null, null, context, grp, 0, null);
    return visitor.walkMapping(parser.mapping(), lambdaContext);
}
Also used : AntlrSourceInformation(org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation) ImportGroup(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportGroup)

Example 5 with AntlrSourceInformation

use of org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation in project legend-pure by finos.

the class M3AntlrParser method parseProperties.

private void parseProperties(boolean useFastParser, String code, String fileName, MutableList<Property<? extends CoreInstance, ?>> properties, MutableList<QualifiedProperty<? extends CoreInstance>> qualifiedProperties, ImportStub typeOwner, ImportGroup importId, boolean addLines, ModelRepository repository, Context context, int startingQualifiedPropertyIndex) throws PureParserException {
    try {
        AntlrSourceInformation sourceInformation = new AntlrSourceInformation(this.offsetLine, 0, fileName, addLines);
        org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser parser = initAntlrParser(useFastParser, code, sourceInformation);
        M3AntlrPropertiesWalker visitor = new M3AntlrPropertiesWalker(sourceInformation, this.inlineDSLLibrary, repository, context, importId, properties, qualifiedProperties, typeOwner, startingQualifiedPropertyIndex);
        visitor.visit(parser.properties());
    } catch (Exception e) {
        if (isAntlrRecognitionExceptionUsingFastParser(useFastParser, e)) {
            // System.err.println("Error using fast Antlr Parser: " + ExceptionUtils.getStackTrace(e));
            this.parseProperties(false, code, fileName, properties, qualifiedProperties, typeOwner, importId, addLines, repository, context, startingQualifiedPropertyIndex);
        } else {
            throw e;
        }
    }
}
Also used : AntlrSourceInformation(org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation) PureParserException(org.finos.legend.pure.m4.serialization.grammar.antlr.PureParserException) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Aggregations

AntlrSourceInformation (org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrSourceInformation)19 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)11 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)11 AntlrDescriptiveErrorListener (org.finos.legend.pure.m4.serialization.grammar.antlr.AntlrDescriptiveErrorListener)11 PureAntlrErrorStrategy (org.finos.legend.pure.m4.serialization.grammar.antlr.PureAntlrErrorStrategy)11 PureParserException (org.finos.legend.pure.m4.serialization.grammar.antlr.PureParserException)11 RecognitionException (org.antlr.v4.runtime.RecognitionException)6 ImportGroup (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel._import.ImportGroup)3 GraphParser (org.finos.legend.pure.m3.inlinedsl.graph.serialization.grammar.GraphParser)2 Token (org.antlr.v4.runtime.Token)1 DiagramStoreGraphBuilder (org.finos.legend.pure.m2.dsl.diagram.serialization.grammar.antlr.DiagramStoreGraphBuilder)1 AggregationAwareLexer (org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.AggregationAwareLexer)1 EnumerationMappingLexer (org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.EnumerationMappingLexer)1 MappingLexer (org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.MappingLexer)1 OperationLexer (org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.OperationLexer)1 AggregationAwareGraphBuilder (org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.antlr.AggregationAwareGraphBuilder)1 EnumerationMappingGraphBuilder (org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.antlr.EnumerationMappingGraphBuilder)1 MappingGraphBuilder (org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.antlr.MappingGraphBuilder)1 OperationGraphBuilder (org.finos.legend.pure.m2.dsl.mapping.serialization.grammar.v1.antlr.OperationGraphBuilder)1 GraphLexer (org.finos.legend.pure.m3.inlinedsl.graph.serialization.grammar.GraphLexer)1