Search in sources :

Example 1 with RelationalParserGrammar

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);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) RelationalLexerGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.RelationalLexerGrammar) RelationalParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.RelationalParserGrammar) CharStream(org.antlr.v4.runtime.CharStream)

Example 2 with RelationalParserGrammar

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);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) RelationalLexerGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.RelationalLexerGrammar) RelationalParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.RelationalParserGrammar) CharStream(org.antlr.v4.runtime.CharStream)

Example 3 with RelationalParserGrammar

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);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) RelationalLexerGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.RelationalLexerGrammar) RelationalParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.RelationalParserGrammar) CharStream(org.antlr.v4.runtime.CharStream)

Example 4 with RelationalParserGrammar

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());
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) RelationalLexerGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.RelationalLexerGrammar) RelationalParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.RelationalParserGrammar) CharStream(org.antlr.v4.runtime.CharStream)

Aggregations

CharStream (org.antlr.v4.runtime.CharStream)4 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)4 RelationalLexerGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.RelationalLexerGrammar)4 RelationalParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.RelationalParserGrammar)4 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)1