Search in sources :

Example 1 with PureGrammarParserContext

use of org.finos.legend.engine.language.pure.grammar.from.PureGrammarParserContext 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)

Aggregations

ParseTreeWalkerSourceInformation (org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation)1 PureGrammarParserContext (org.finos.legend.engine.language.pure.grammar.from.PureGrammarParserContext)1 SourceCodeParserInfo (org.finos.legend.engine.language.pure.grammar.from.SourceCodeParserInfo)1 DomainParserGrammar (org.finos.legend.engine.language.pure.grammar.from.antlr4.domain.DomainParserGrammar)1 ValueSpecification (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification)1