Search in sources :

Example 1 with DomainParser

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

the class MappingParseTreeWalker method visitMappingTestQuery.

private Lambda visitMappingTestQuery(MappingParserGrammar.CombinedExpressionContext ctx, Mapping mapping) {
    DomainParser parser = new DomainParser();
    // prepare island grammar walker source information
    int startLine = ctx.getStart().getLine();
    int lineOffset = walkerSourceInformation.getLineOffset() + startLine - 1;
    // only add current walker source information column offset if this is the first line
    int columnOffset = (startLine == 1 ? walkerSourceInformation.getColumnOffset() : 0) + ctx.getStart().getCharPositionInLine();
    ParseTreeWalkerSourceInformation combineExpressionWalkerSourceInformation = new ParseTreeWalkerSourceInformation.Builder(mapping.getPath(), lineOffset, columnOffset).withReturnSourceInfo(this.walkerSourceInformation.getReturnSourceInfo()).build();
    String lambdaString = this.input.getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
    ValueSpecification valueSpecification = parser.parseCombinedExpression(lambdaString, combineExpressionWalkerSourceInformation, null);
    if (valueSpecification instanceof Lambda) {
        return (Lambda) valueSpecification;
    }
    // NOTE: If the user just provides the body of the lambda, we will wrap a lambda around it
    // we might want to reconsider this behavior and throw error if this convenience causes any trouble
    Lambda lambda = new Lambda();
    lambda.body = new ArrayList<>();
    lambda.body.add(valueSpecification);
    lambda.parameters = new ArrayList<>();
    return lambda;
}
Also used : DomainParser(org.finos.legend.engine.language.pure.grammar.from.domain.DomainParser) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda) ParseTreeWalkerSourceInformation(org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation) Interval(org.antlr.v4.runtime.misc.Interval)

Example 2 with DomainParser

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

the class XStoreAssociationMappingParseTreeWalker method visitLambda.

private Lambda visitLambda(XStoreAssociationMappingParserGrammar.CombinedExpressionContext ctx) {
    // Build source info for Lambda
    int startLine = ctx.start.getLine();
    int lineOffset = walkerSourceInformation.getLineOffset() + startLine - 1;
    // only add current walker source information column offset if this is the first line
    int columnOffset = (startLine == 1 ? walkerSourceInformation.getColumnOffset() : 0) + ctx.getStart().getCharPositionInLine();
    ParseTreeWalkerSourceInformation combinedExpressionSourceInformation = new ParseTreeWalkerSourceInformation.Builder(walkerSourceInformation.getSourceId(), lineOffset, columnOffset).withReturnSourceInfo(this.walkerSourceInformation.getReturnSourceInfo()).build();
    String lambdaString = this.input.getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
    ValueSpecification valueSpecification = new DomainParser().parseCombinedExpression(lambdaString, combinedExpressionSourceInformation, this.parserContext);
    Lambda lambda = new Lambda();
    lambda.body = Collections.singletonList(valueSpecification);
    return lambda;
}
Also used : DomainParser(org.finos.legend.engine.language.pure.grammar.from.domain.DomainParser) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda) ParseTreeWalkerSourceInformation(org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation) Interval(org.antlr.v4.runtime.misc.Interval)

Example 3 with DomainParser

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

the class TestLambdaRoundtrip method testLambda.

private static void testLambda(String text, String formattedText) {
    Lambda postJSON_lambda;
    try {
        Lambda lambda = new DomainParser().parseLambda(text, "", true);
        String json = objectMapper.writeValueAsString(lambda);
        postJSON_lambda = objectMapper.readValue(json, Lambda.class);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    Assert.assertEquals(formattedText, postJSON_lambda.accept(DEPRECATED_PureGrammarComposerCore.Builder.newInstance().build()));
}
Also used : DomainParser(org.finos.legend.engine.language.pure.grammar.from.domain.DomainParser) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda)

Example 4 with DomainParser

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

the class AggregationAwareMappingParseTreeWalker method visitLambda.

private Lambda visitLambda(AggregationAwareParserGrammar.CombinedExpressionContext ctx) {
    // Build source info for Lambda
    int startLine = ctx.start.getLine();
    int lineOffset = walkerSourceInformation.getLineOffset() + startLine - 1;
    // only add current walker source information column offset if this is the first line
    int columnOffset = (startLine == 1 ? walkerSourceInformation.getColumnOffset() : 0) + ctx.getStart().getCharPositionInLine();
    ParseTreeWalkerSourceInformation combinedExpressionSourceInformation = new ParseTreeWalkerSourceInformation.Builder(walkerSourceInformation.getSourceId(), lineOffset, columnOffset).withReturnSourceInfo(this.walkerSourceInformation.getReturnSourceInfo()).build();
    String lambdaString = this.input.getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
    ValueSpecification valueSpecification = new DomainParser().parseCombinedExpression(lambdaString, combinedExpressionSourceInformation, this.parserContext);
    Lambda lambda = new Lambda();
    lambda.body = Collections.singletonList(valueSpecification);
    return lambda;
}
Also used : DomainParser(org.finos.legend.engine.language.pure.grammar.from.domain.DomainParser) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda) ParseTreeWalkerSourceInformation(org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation) Interval(org.antlr.v4.runtime.misc.Interval)

Example 5 with DomainParser

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

the class OperationClassMappingParseTreeWalker method visitMergeOperationClassMapping.

public void visitMergeOperationClassMapping(OperationClassMappingParserGrammar.OperationClassMappingContext mappingContext, MergeOperationClassMapping mergeOperationClassMapping) {
    // TODO mappingClass extendsClassMappingId
    if (mappingContext.functionPath() != null) {
        mergeOperationClassMapping.operation = funcToOps.get(mappingContext.functionPath().getText());
    }
    if (mappingContext.mergeParameters() != null) {
        if (mappingContext.mergeParameters().setParameter() != null && mappingContext.mergeParameters().setParameter().identifier() != null) {
            mergeOperationClassMapping.parameters = ListIterate.collect(mappingContext.mergeParameters().setParameter().identifier(), PureGrammarParserUtility::fromIdentifier);
        }
        if (mappingContext.mergeParameters().validationLambda() != null) {
            int startLine = mappingContext.start.getLine();
            int lineOffset = walkerSourceInformation.getLineOffset() + startLine - 1;
            // only add current walker source information column offset if this is the first line
            int columnOffset = (startLine == 1 ? walkerSourceInformation.getColumnOffset() : 0) + mappingContext.getStart().getCharPositionInLine();
            ParseTreeWalkerSourceInformation combinedExpressionSourceInformation = new ParseTreeWalkerSourceInformation.Builder(walkerSourceInformation.getSourceId(), lineOffset, columnOffset).withReturnSourceInfo(this.walkerSourceInformation.getReturnSourceInfo()).build();
            String lambdaString = mappingContext.mergeParameters().validationLambda().getText();
            ValueSpecification valueSpecification = new DomainParser().parseCombinedExpression(lambdaString, combinedExpressionSourceInformation, this.parserContext);
            Lambda lambda = new Lambda();
            lambda.body = Collections.singletonList(valueSpecification);
            mergeOperationClassMapping.validationFunction = lambda;
        }
    }
}
Also used : DomainParser(org.finos.legend.engine.language.pure.grammar.from.domain.DomainParser) ValueSpecification(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification) Lambda(org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda) ParseTreeWalkerSourceInformation(org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation)

Aggregations

DomainParser (org.finos.legend.engine.language.pure.grammar.from.domain.DomainParser)9 ValueSpecification (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.ValueSpecification)8 Lambda (org.finos.legend.engine.protocol.pure.v1.model.valueSpecification.raw.Lambda)8 ParseTreeWalkerSourceInformation (org.finos.legend.engine.language.pure.grammar.from.ParseTreeWalkerSourceInformation)7 Interval (org.antlr.v4.runtime.misc.Interval)6