use of org.finos.legend.engine.language.pure.grammar.from.antlr4.RelationalParserGrammar in project legend-engine by finos.
the class RelationalGrammarParserExtension method getRelationalMappingElementParserInfo.
private static SourceCodeParserInfo getRelationalMappingElementParserInfo(MappingElementSourceCode mappingElementSourceCode) {
CharStream input = CharStreams.fromString(mappingElementSourceCode.code);
ParserErrorListener errorListener = new ParserErrorListener(mappingElementSourceCode.mappingElementParseTreeWalkerSourceInformation);
RelationalLexerGrammar lexer = new RelationalLexerGrammar(CharStreams.fromString(mappingElementSourceCode.code));
lexer.removeErrorListeners();
lexer.addErrorListener(errorListener);
RelationalParserGrammar parser = new RelationalParserGrammar(new CommonTokenStream(lexer));
parser.removeErrorListeners();
parser.addErrorListener(errorListener);
RelationalParserGrammar.MappingContext mappingContext = parser.mapping();
ParserRuleContext associationMappingCtx = mappingContext.associationMapping();
ParserRuleContext classMappingCtx = mappingContext.classMapping();
return new SourceCodeParserInfo(mappingElementSourceCode.code, input, mappingElementSourceCode.mappingParseTreeWalkerSourceInformation.getSourceInformation(mappingElementSourceCode.mappingElementParserRuleContext), mappingElementSourceCode.mappingElementParseTreeWalkerSourceInformation, lexer, parser, associationMappingCtx != null ? associationMappingCtx : classMappingCtx);
}
use of org.finos.legend.engine.language.pure.grammar.from.antlr4.RelationalParserGrammar in project legend-engine by finos.
the class RelationalGrammarParserExtension method parseMilestoning.
private Milestoning parseMilestoning(MilestoningSpecificationSourceCode code, Function<RelationalParserGrammar, Milestoning> func) {
CharStream input = CharStreams.fromString(code.getCode());
ParserErrorListener errorListener = new ParserErrorListener(code.getWalkerSourceInformation());
RelationalLexerGrammar lexer = new RelationalLexerGrammar(input);
RelationalParserGrammar parser = new RelationalParserGrammar(new CommonTokenStream(lexer));
lexer.removeErrorListeners();
lexer.addErrorListener(errorListener);
parser.removeErrorListeners();
parser.addErrorListener(errorListener);
return func.apply(parser);
}
use of org.finos.legend.engine.language.pure.grammar.from.antlr4.RelationalParserGrammar in project legend-engine by finos.
the class RelationalGrammarParserExtension method parseRelationalOperationElement.
public static RelationalOperationElement parseRelationalOperationElement(String code, boolean returnSourceInfo) {
CharStream input = CharStreams.fromString(code);
ParseTreeWalkerSourceInformation parseTreeWalkerSourceInformation = new ParseTreeWalkerSourceInformation.Builder("", 0, 0).withReturnSourceInfo(returnSourceInfo).build();
ParserErrorListener errorListener = new ParserErrorListener(parseTreeWalkerSourceInformation);
RelationalLexerGrammar lexer = new RelationalLexerGrammar(input);
lexer.removeErrorListeners();
lexer.addErrorListener(errorListener);
RelationalParserGrammar parser = new RelationalParserGrammar(new CommonTokenStream(lexer));
parser.removeErrorListeners();
parser.addErrorListener(errorListener);
RelationalParseTreeWalker walker = new RelationalParseTreeWalker(parseTreeWalkerSourceInformation);
return walker.visitOperation(parser.operation(), null);
}
use of org.finos.legend.engine.language.pure.grammar.from.antlr4.RelationalParserGrammar in project legend-engine by finos.
the class RelationalGrammarParserExtension method getRelationalParserInfo.
private static SourceCodeParserInfo getRelationalParserInfo(SectionSourceCode sectionSourceCode) {
CharStream input = CharStreams.fromString(sectionSourceCode.code);
ParserErrorListener errorListener = new ParserErrorListener(sectionSourceCode.walkerSourceInformation);
RelationalLexerGrammar lexer = new RelationalLexerGrammar(input);
lexer.removeErrorListeners();
lexer.addErrorListener(errorListener);
RelationalParserGrammar parser = new RelationalParserGrammar(new CommonTokenStream(lexer));
parser.removeErrorListeners();
parser.addErrorListener(errorListener);
return new SourceCodeParserInfo(sectionSourceCode.code, input, sectionSourceCode.sourceInformation, sectionSourceCode.walkerSourceInformation, lexer, parser, parser.definition());
}
Aggregations