Search in sources :

Example 1 with ImportAwareCodeSection

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection 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 2 with ImportAwareCodeSection

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection 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)

Example 3 with ImportAwareCodeSection

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection in project legend-engine by finos.

the class DomainParser method parseValueSpecification.

public ValueSpecification parseValueSpecification(String input, String s, boolean returnSourceInfo) {
    PureGrammarParserContext parserContext = new PureGrammarParserContext(PureGrammarParserExtensions.fromExtensions(Lists.immutable.empty()));
    ParseTreeWalkerSourceInformation lambdaWalkerSourceInformation = new ParseTreeWalkerSourceInformation.Builder(s, 0, 0).withReturnSourceInfo(returnSourceInfo).build();
    String prefix = "function go():Any[*]{let x = ";
    String fullCode = prefix + input + ";}";
    ParseTreeWalkerSourceInformation walkerSourceInformation = new ParseTreeWalkerSourceInformation.Builder(lambdaWalkerSourceInformation).withColumnOffset(lambdaWalkerSourceInformation.getColumnOffset() - prefix.length()).build();
    SourceCodeParserInfo sectionParserInfo = this.getParserInfo(fullCode, null, walkerSourceInformation, true);
    DomainParseTreeWalker walker = new DomainParseTreeWalker(walkerSourceInformation, parserContext, (ImportAwareCodeSection) null);
    return (ValueSpecification) walker.combinedExpression(((DomainParserGrammar.DefinitionContext) sectionParserInfo.rootContext).elementDefinition(0).functionDefinition().codeBlock().programLine(0).letExpression().combinedExpression(), "", Lists.mutable.empty(), null, "", false, returnSourceInfo);
}
Also used : SourceCodeParserInfo(org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo) DomainParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.domain.DomainParserGrammar) PureGrammarParserContext(org.finos.legend.engine.language.pure.grammar.from.PureGrammarParserContext) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) ParseTreeWalkerSourceInformation(org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation)

Example 4 with ImportAwareCodeSection

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection in project legend-engine by finos.

the class DomainParser method parseLambda.

public Lambda parseLambda(String code, String lambdaId, PureGrammarParserContext parserContext, boolean returnSourceInfo) {
    ParseTreeWalkerSourceInformation lambdaWalkerSourceInformation = new ParseTreeWalkerSourceInformation.Builder(lambdaId, 0, 0).withReturnSourceInfo(returnSourceInfo).build();
    String prefix = "function go():Any[*]{";
    String fullCode = prefix + code + "}";
    ParseTreeWalkerSourceInformation walkerSourceInformation = new ParseTreeWalkerSourceInformation.Builder(lambdaWalkerSourceInformation).withColumnOffset(lambdaWalkerSourceInformation.getColumnOffset() - prefix.length()).build();
    SourceCodeParserInfo sectionParserInfo = this.getParserInfo(fullCode, null, walkerSourceInformation, true);
    DomainParseTreeWalker walker = new DomainParseTreeWalker(walkerSourceInformation, parserContext, (ImportAwareCodeSection) null);
    return (Lambda) walker.concreteFunctionDefinition(((DomainParserGrammar.DefinitionContext) sectionParserInfo.rootContext).elementDefinition(0).functionDefinition());
}
Also used : SourceCodeParserInfo(org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo) DomainParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.domain.DomainParserGrammar) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda) ParseTreeWalkerSourceInformation(org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation)

Example 5 with ImportAwareCodeSection

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection in project legend-engine by finos.

the class RuntimeParser method parse.

@Override
public Section parse(SourceCodeParserInfo sectionParserInfo, Consumer<PackageableElement> pureModelContextData, PureGrammarParserContext parserContext) {
    ImportAwareCodeSection section = new ImportAwareCodeSection();
    section.parserName = this.getName();
    section.sourceInformation = sectionParserInfo.sourceInformation;
    RuntimeParseTreeWalker walker = new RuntimeParseTreeWalker(sectionParserInfo.walkerSourceInformation, pureModelContextData, section, this.connectionParser);
    walker.visit((RuntimeParserGrammar.DefinitionContext) sectionParserInfo.rootContext);
    return section;
}
Also used : ImportAwareCodeSection(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection) RuntimeParserGrammar(org.finos.legend.engine.language.pure.grammar.from.antlr4.runtime.RuntimeParserGrammar)

Aggregations

ImportAwareCodeSection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.ImportAwareCodeSection)10 SourceCodeParserInfo (org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo)6 DomainParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.domain.DomainParserGrammar)3 ParseTreeWalkerSourceInformation (org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation)2 PureGrammarParserContext (org.finos.legend.engine.language.pure.grammar.from.PureGrammarParserContext)1 CodeParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.CodeParserGrammar)1 DiagramParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.DiagramParserGrammar)1 ExternalFormatParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.ExternalFormatParserGrammar)1 FileGenerationParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.FileGenerationParserGrammar)1 GenerationSpecificationParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.GenerationSpecificationParserGrammar)1 PersistenceParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.PersistenceParserGrammar)1 ConnectionParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.connection.ConnectionParserGrammar)1 MappingParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.mapping.MappingParserGrammar)1 RuntimeParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.runtime.RuntimeParserGrammar)1 SectionParser (org.finos.legend.engine.language.pure.grammar.from.extension.SectionParser)1 SourceInformation (org.finos.legend.engine.protocol.pure.v1.model.SourceInformation)1 DefaultCodeSection (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.DefaultCodeSection)1 Section (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.section.Section)1 ValueSpecification (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification)1 Lambda (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda)1