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;
}
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;
}
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;
}
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);
}
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;
}
}
}
Aggregations