Search in sources :

Example 1 with ExpressionPartContext

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

the class AntlrContextToM3CoreInstance method combinedExpression.

public CoreInstance combinedExpression(CombinedExpressionContext ctx, String exprName, MutableList<String> typeParametersNames, LambdaContext lambdaContext, String space, boolean wrapFlag, ImportGroup importId, boolean addLines) {
    CoreInstance result = this.expressionOrExpressionGroup(ctx.expressionOrExpressionGroup(), exprName, typeParametersNames, lambdaContext, space, wrapFlag, importId, addLines);
    CoreInstance boolResult = result;
    CoreInstance arithResult = result;
    if (ctx.expressionPart() != null) {
        MutableList<ArithmeticPartContext> arth = Lists.mutable.empty();
        MutableList<BooleanPartContext> bool = Lists.mutable.empty();
        // Invariant: arth.isEmpty() || bool.isEmpty ie they can't both contains elements at the same time
        for (ExpressionPartContext epCtx : ctx.expressionPart()) {
            if (epCtx.arithmeticPart() != null) {
                if (!bool.isEmpty()) {
                    boolResult = this.booleanPart(bool, (ValueSpecification) arithResult, exprName, typeParametersNames, lambdaContext, space, wrapFlag, importId, addLines);
                    bool.clear();
                }
                arth.add(epCtx.arithmeticPart());
            } else if (epCtx.booleanPart() != null) {
                if (!arth.isEmpty()) {
                    arithResult = this.arithmeticPart(arth, boolResult, exprName, typeParametersNames, lambdaContext, space, wrapFlag, importId, addLines);
                    arth.clear();
                }
                bool.add(epCtx.booleanPart());
            }
        }
        // Invariant allows us to make the choice here - either we still have arth to process or bool to process but not both
        if (!arth.isEmpty()) {
            result = this.arithmeticPart(arth, boolResult, exprName, typeParametersNames, lambdaContext, space, wrapFlag, importId, addLines);
        } else if (!bool.isEmpty()) {
            result = this.booleanPart(bool, (ValueSpecification) arithResult, exprName, typeParametersNames, lambdaContext, space, wrapFlag, importId, addLines);
        }
    }
    return result;
}
Also used : ArithmeticPartContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ArithmeticPartContext) PrimitiveCoreInstance(org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance) CoreInstance(org.finos.legend.pure.m4.coreinstance.CoreInstance) ValueSpecification(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification) ExpressionPartContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ExpressionPartContext) BooleanPartContext(org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.BooleanPartContext)

Aggregations

ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)1 ArithmeticPartContext (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ArithmeticPartContext)1 BooleanPartContext (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.BooleanPartContext)1 ExpressionPartContext (org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.ExpressionPartContext)1 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)1 PrimitiveCoreInstance (org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance)1