Search in sources :

Example 1 with LambdaPipeContext

use of org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.LambdaPipeContext in project legend-pure by finos.

the class AntlrContextToM3CoreInstance method lambdaPipe.

private Any lambdaPipe(LambdaPipeContext ctx, Token firstToken, ListIterable<VariableExpression> params, MutableList<String> typeParametersNames, LambdaContext lambdaContext, String space, boolean wrapFlag, ImportGroup importId, boolean addLines) {
    Token lambdaStartToken = firstToken != null ? firstToken : ctx.PIPE().getSymbol();
    ListIterable<ValueSpecification> block = codeBlock(ctx.codeBlock(), typeParametersNames, importId, lambdaContext, addLines, spacePlusTabs(space, 6));
    FunctionTypeInstance signature = FunctionTypeInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(lambdaStartToken), null, null);
    if (Iterate.notEmpty(params)) {
        signature._parameters(params);
    }
    // Note: we cannot set the function of the signature FunctionType, as this can cause stack overflow if serializing to M4
    GenericTypeInstance genericTypeInstance = GenericTypeInstance.createPersistent(this.repository);
    Type type = (Type) this.processorSupport.package_getByUserPath(M3Paths.LambdaFunction);
    genericTypeInstance._rawTypeCoreInstance(type);
    GenericTypeInstance genericTypeInstanceTa = GenericTypeInstance.createPersistent(this.repository);
    genericTypeInstanceTa._rawTypeCoreInstance(signature);
    genericTypeInstance._typeArguments(Lists.mutable.<GenericType>of(genericTypeInstanceTa));
    LambdaFunctionInstance lambdaFunction = LambdaFunctionInstance.createPersistent(this.repository, lambdaContext.getLambdaFunctionUniqueName(), this.sourceInformation.getPureSourceInformation(lambdaStartToken));
    lambdaFunction._classifierGenericType(genericTypeInstance);
    lambdaFunction._expressionSequence(block);
    return wrapFlag ? this.doWrap(lambdaFunction, lambdaStartToken) : lambdaFunction;
}
Also used : GenericTypeInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance) FunctionType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType) Type(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type) GenericType(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType) FunctionTypeInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionTypeInstance) LambdaFunctionInstance(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunctionInstance) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) Token(org.antlr.v4.runtime.Token)

Aggregations

Token (org.antlr.v4.runtime.Token)1 LambdaFunctionInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.LambdaFunctionInstance)1 FunctionType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionType)1 FunctionTypeInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.FunctionTypeInstance)1 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)1 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)1 GenericTypeInstance (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericTypeInstance)1 ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)1