Search in sources :

Example 1 with SourceCodeParserInfo

use of org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo in project legend-engine by finos.

the class GenerationParserExtension method getFileGenerationParserInfo.

private static SourceCodeParserInfo getFileGenerationParserInfo(SectionSourceCode sectionSourceCode) {
    CharStream input = CharStreams.fromString(sectionSourceCode.code);
    ParserErrorListener errorListener = new ParserErrorListener(sectionSourceCode.walkerSourceInformation);
    FileGenerationLexerGrammar lexer = new FileGenerationLexerGrammar(input);
    lexer.removeErrorListeners();
    lexer.addErrorListener(errorListener);
    FileGenerationParserGrammar parser = new FileGenerationParserGrammar(new CommonTokenStream(lexer));
    parser.removeErrorListeners();
    parser.addErrorListener(errorListener);
    return new SourceCodeParserInfo(sectionSourceCode.code, input, sectionSourceCode.sourceInformation, sectionSourceCode.walkerSourceInformation, lexer, parser, parser.definition());
}
Also used : SourceCodeParserInfo(org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) FileGenerationParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.FileGenerationParserGrammar) CharStream(org.antlr.v4.runtime.CharStream) FileGenerationLexerGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.FileGenerationLexerGrammar) ParserErrorListener(org.finos.legend.engine.language.pure.grammar.from.ParserErrorListener)

Example 2 with SourceCodeParserInfo

use of org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo in project legend-engine by finos.

the class DataSpaceParserExtension method getDataSpaceParserInfo.

private static SourceCodeParserInfo getDataSpaceParserInfo(SectionSourceCode sectionSourceCode) {
    CharStream input = CharStreams.fromString(sectionSourceCode.code);
    ParserErrorListener errorListener = new ParserErrorListener(sectionSourceCode.walkerSourceInformation);
    DataSpaceLexerGrammar lexer = new DataSpaceLexerGrammar(input);
    lexer.removeErrorListeners();
    lexer.addErrorListener(errorListener);
    DataSpaceParserGrammar parser = new DataSpaceParserGrammar(new CommonTokenStream(lexer));
    parser.removeErrorListeners();
    parser.addErrorListener(errorListener);
    return new SourceCodeParserInfo(sectionSourceCode.code, input, sectionSourceCode.sourceInformation, sectionSourceCode.walkerSourceInformation, lexer, parser, parser.definition());
}
Also used : SourceCodeParserInfo(org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) DataSpaceLexerGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.DataSpaceLexerGrammar) DataSpaceParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.DataSpaceParserGrammar) CharStream(org.antlr.v4.runtime.CharStream) ParserErrorListener(org.finos.legend.engine.language.pure.grammar.from.ParserErrorListener)

Example 3 with SourceCodeParserInfo

use of org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo in project legend-engine by finos.

the class PersistenceParserExtension method parseSection.

private static Section parseSection(SectionSourceCode sectionSourceCode, Consumer<PackageableElement> elementConsumer, PureGrammarParserContext context) {
    SourceCodeParserInfo parserInfo = getPersistenceParserInfo(sectionSourceCode);
    ImportAwareCodeSection section = new ImportAwareCodeSection();
    section.parserName = sectionSourceCode.sectionType;
    section.sourceInformation = parserInfo.sourceInformation;
    PersistenceParseTreeWalker walker = new PersistenceParseTreeWalker(parserInfo.walkerSourceInformation, elementConsumer, section);
    walker.visit((PersistenceParserGrammar.DefinitionContext) parserInfo.rootContext);
    return section;
}
Also used : SourceCodeParserInfo(org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo) ImportAwareCodeSection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection) PersistenceParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.PersistenceParserGrammar)

Example 4 with SourceCodeParserInfo

use of org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo in project legend-engine by finos.

the class DiagramParserExtension method getDiagramParserInfo.

private static SourceCodeParserInfo getDiagramParserInfo(SectionSourceCode sectionSourceCode) {
    CharStream input = CharStreams.fromString(sectionSourceCode.code);
    ParserErrorListener errorListener = new ParserErrorListener(sectionSourceCode.walkerSourceInformation);
    DiagramLexerGrammar lexer = new DiagramLexerGrammar(input);
    lexer.removeErrorListeners();
    lexer.addErrorListener(errorListener);
    DiagramParserGrammar parser = new DiagramParserGrammar(new CommonTokenStream(lexer));
    parser.removeErrorListeners();
    parser.addErrorListener(errorListener);
    return new SourceCodeParserInfo(sectionSourceCode.code, input, sectionSourceCode.sourceInformation, sectionSourceCode.walkerSourceInformation, lexer, parser, parser.definition());
}
Also used : SourceCodeParserInfo(org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) DiagramLexerGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.DiagramLexerGrammar) DiagramParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.DiagramParserGrammar) CharStream(org.antlr.v4.runtime.CharStream) ParserErrorListener(org.finos.legend.engine.language.pure.grammar.from.ParserErrorListener)

Example 5 with SourceCodeParserInfo

use of org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo in project legend-engine by finos.

the class DiagramParserExtension method parseSection.

private static Section parseSection(SectionSourceCode sectionSourceCode, Consumer<PackageableElement> elementConsumer, PureGrammarParserContext pureGrammarParserContext) {
    SourceCodeParserInfo parserInfo = getDiagramParserInfo(sectionSourceCode);
    ImportAwareCodeSection section = new ImportAwareCodeSection();
    section.parserName = sectionSourceCode.sectionType;
    section.sourceInformation = parserInfo.sourceInformation;
    DiagramParseTreeWalker walker = new DiagramParseTreeWalker(parserInfo.walkerSourceInformation, elementConsumer, section);
    walker.visit((DiagramParserGrammar.DefinitionContext) parserInfo.rootContext);
    return section;
}
Also used : SourceCodeParserInfo(org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo) ImportAwareCodeSection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection) DiagramParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.DiagramParserGrammar)

Aggregations

SourceCodeParserInfo (org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo)29 CharStream (org.antlr.v4.runtime.CharStream)14 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)14 ParserErrorListener (org.finos.legend.engine.language.pure.grammar.from.ParserErrorListener)14 ParseTreeWalkerSourceInformation (org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation)4 ImportAwareCodeSection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection)4 DomainParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.domain.DomainParserGrammar)3 ArrayList (java.util.ArrayList)2 DataSpaceParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.DataSpaceParserGrammar)2 DiagramParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.DiagramParserGrammar)2 FileGenerationParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.FileGenerationParserGrammar)2 GenerationSpecificationParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.GenerationSpecificationParserGrammar)2 PersistenceParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.PersistenceParserGrammar)2 TextParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.TextParserGrammar)2 BinaryDataParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.data.embedded.binary.BinaryDataParserGrammar)2 PureCollectionDataParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.data.embedded.pureCollection.PureCollectionDataParserGrammar)2 TextDataParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.data.embedded.text.TextDataParserGrammar)2 DefaultCodeSection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.DefaultCodeSection)2 PureGrammarParserContext (org.finos.legend.engine.language.pure.grammar.from.PureGrammarParserContext)1 DataSpaceLexerGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.DataSpaceLexerGrammar)1