Search in sources :

Example 1 with CodeParserGrammar

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

the class PureGrammarParser method parse.

private PureModelContextData parse(String code, DEPRECATED_PureGrammarParserLibrary parserLibrary, boolean returnSourceInfo) {
    String fullCode = DEFAULT_SECTION_BEGIN + code;
    PureGrammarParserContext parserContext = new PureGrammarParserContext(this.extensions);
    ParseTreeWalkerSourceInformation walkerSourceInformation = ParseTreeWalkerSourceInformation.DEFAULT_WALKER_SOURCE_INFORMATION(returnSourceInfo);
    // init the parser
    ParserErrorListener errorListener = new ParserErrorListener(walkerSourceInformation);
    CodeLexerGrammar lexer = new CodeLexerGrammar(CharStreams.fromString(fullCode));
    lexer.removeErrorListeners();
    lexer.addErrorListener(errorListener);
    CodeParserGrammar parser = new CodeParserGrammar(new CommonTokenStream(lexer));
    parser.removeErrorListeners();
    parser.addErrorListener(errorListener);
    // create the PureModelContextData builder
    PureModelContextData.Builder builder = new PureModelContextData.Builder();
    // create the section index
    SectionIndex sectionIndex = new SectionIndex();
    // NOTE: we intentionally set section index name and package like this since we don't want to expose this feature yet to end user
    // in the consumer, we should ensure this does not leak and gets persisted to SDLC or Services per se
    sectionIndex.name = "SectionIndex";
    sectionIndex._package = "__internal__";
    sectionIndex.sections = ListIterate.collect(parser.definition().section(), sectionCtx -> this.visitSection(sectionCtx, parserLibrary, walkerSourceInformation, parserContext, builder::addElement, returnSourceInfo));
    return builder.withElement(sectionIndex).build();
}
Also used : Section(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.Section) RootGraphFetchTree(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.graph.RootGraphFetchTree) LoggingEventType(org.finos.legend.engine.shared.core.operational.logs.LoggingEventType) PackageableElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda) ConnectionParser(org.finos.legend.engine.language.pure.grammar.from.connection.ConnectionParser) EngineErrorType(org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType) Lists(org.eclipse.collections.api.factory.Lists) CodeParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.CodeParserGrammar) MappingParser(org.finos.legend.engine.language.pure.grammar.from.mapping.MappingParser) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) CharStreams(org.antlr.v4.runtime.CharStreams) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) ImportAwareCodeSection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection) SectionIndex(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.SectionIndex) CodeLexerGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.CodeLexerGrammar) DefaultCodeSection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.DefaultCodeSection) RuntimeParser(org.finos.legend.engine.language.pure.grammar.from.runtime.RuntimeParser) Logger(org.slf4j.Logger) PureGrammarParserExtensions(org.finos.legend.engine.language.pure.grammar.from.extension.PureGrammarParserExtensions) DomainParser(org.finos.legend.engine.language.pure.grammar.from.domain.DomainParser) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) ListIterate(org.eclipse.collections.impl.utility.ListIterate) SourceInformation(org.finos.legend.engine.protocol.pure.v1.model.SourceInformation) LogInfo(org.finos.legend.engine.shared.core.operational.logs.LogInfo) Consumer(java.util.function.Consumer) EngineException(org.finos.legend.engine.shared.core.operational.errorManagement.EngineException) SectionParser(org.finos.legend.engine.language.pure.grammar.from.extension.SectionParser) CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) CodeParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.CodeParserGrammar) CodeLexerGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.CodeLexerGrammar) SectionIndex(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.SectionIndex) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)

Aggregations

Consumer (java.util.function.Consumer)1 CharStreams (org.antlr.v4.runtime.CharStreams)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 Lists (org.eclipse.collections.api.factory.Lists)1 ListIterate (org.eclipse.collections.impl.utility.ListIterate)1 CodeLexerGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.CodeLexerGrammar)1 CodeParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.CodeParserGrammar)1 ConnectionParser (org.finos.legend.engine.language.pure.grammar.from.connection.ConnectionParser)1 DomainParser (org.finos.legend.engine.language.pure.grammar.from.domain.DomainParser)1 PureGrammarParserExtensions (org.finos.legend.engine.language.pure.grammar.from.extension.PureGrammarParserExtensions)1 SectionParser (org.finos.legend.engine.language.pure.grammar.from.extension.SectionParser)1 MappingParser (org.finos.legend.engine.language.pure.grammar.from.mapping.MappingParser)1 RuntimeParser (org.finos.legend.engine.language.pure.grammar.from.runtime.RuntimeParser)1 SourceInformation (org.finos.legend.engine.protocol.pure.v1.model.SourceInformation)1 EngineErrorType (org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType)1 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)1 PackageableElement (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement)1 DefaultCodeSection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.DefaultCodeSection)1 ImportAwareCodeSection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection)1 Section (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.Section)1