use of org.finos.legend.engine.language.pure.grammar.from.antlr4.graphFetchTree.GraphFetchTreeLexerGrammar in project legend-engine by finos.
the class DomainParseTreeWalker method visitGraphFetchTree.
// TODO: add another island mode in M3 for this when we support path (which starts with #/)
public ListIterable<ValueSpecification> visitGraphFetchTree(DomainParserGrammar.DslGraphFetchContext ctx) {
// NOTE: we want to preserve the spacing so we can correctly produce source information in the dispatched parser
StringBuilder graphFetchStringBuilder = new StringBuilder();
for (DomainParserGrammar.DslContentContext fragment : ctx.dslContent()) {
graphFetchStringBuilder.append(fragment.getText());
}
String graphFetchString = graphFetchStringBuilder.length() > 0 ? graphFetchStringBuilder.substring(0, graphFetchStringBuilder.length() - 2) : graphFetchStringBuilder.toString();
if (graphFetchString.isEmpty()) {
throw new EngineException("Graph fetch tree must not be empty", walkerSourceInformation.getSourceInformation(ctx), EngineErrorType.PARSER);
}
// prepare island grammar walker source information
int startLine = ctx.ISLAND_OPEN().getSymbol().getLine();
int lineOffset = walkerSourceInformation.getLineOffset() + startLine - 1;
// only add current walker source information column offset if this is the first line
int columnOffset = (startLine == 1 ? walkerSourceInformation.getColumnOffset() : 0) + ctx.ISLAND_OPEN().getSymbol().getCharPositionInLine() + ctx.ISLAND_OPEN().getText().length();
ParseTreeWalkerSourceInformation graphFetchWalkerSourceInformation = new ParseTreeWalkerSourceInformation.Builder(this.walkerSourceInformation.getSourceId(), lineOffset, columnOffset).withReturnSourceInfo(this.walkerSourceInformation.getReturnSourceInfo()).build();
ParserErrorListener errorListener = new ParserErrorListener(graphFetchWalkerSourceInformation);
GraphFetchTreeLexerGrammar graphLexer = new GraphFetchTreeLexerGrammar(CharStreams.fromString(graphFetchString));
graphLexer.removeErrorListeners();
graphLexer.addErrorListener(errorListener);
GraphFetchTreeParserGrammar graphParser = new GraphFetchTreeParserGrammar(new CommonTokenStream(graphLexer));
graphParser.removeErrorListeners();
graphParser.addErrorListener(errorListener);
graphParser.getInterpreter().setPredictionMode(PredictionMode.SLL);
return Lists.mutable.with(new GraphFetchTreeParseTreeWalker(graphFetchWalkerSourceInformation).visitDefinition(graphParser.definition()));
}
Aggregations