Search in sources :

Example 1 with BooleanPartContext

use of org.finos.legend.pure.m3.serialization.grammar.m3parser.antlr.M3Parser.BooleanPartContext 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)

Example 2 with BooleanPartContext

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

the class AntlrContextToM3CoreInstance method processBooleanOp.

private SimpleFunctionExpression processBooleanOp(SimpleFunctionExpression sfe, BooleanPartContext ctx, BoolOp op, CoreInstance initialValue, String exprName, MutableList<String> typeParamtersNames, LambdaContext lambdaContext, String space, boolean wrapFlag, ImportGroup importId, boolean addLines) {
    if (sfe == null) {
        return buildBoolean(ctx, op, initialValue, exprName, typeParamtersNames, lambdaContext, space, wrapFlag, importId, addLines);
    }
    if (isLowerPrecedenceBoolean(sfe.getValueForMetaPropertyToOne("functionName").getName(), op.name().toLowerCase())) {
        ListIterable<? extends CoreInstance> params = sfe.getValueForMetaPropertyToMany("parametersValues");
        SimpleFunctionExpression newSfe = buildBoolean(ctx, op, params.getLast(), exprName, typeParamtersNames, lambdaContext, space, wrapFlag, importId, addLines);
        MutableList<CoreInstance> l = Lists.mutable.withAll(params.subList(0, params.size() - 1));
        sfe._parametersValues(Lists.mutable.of((ValueSpecification) l.get(0), newSfe));
        return sfe;
    }
    return buildBoolean(ctx, op, sfe, exprName, typeParamtersNames, lambdaContext, space, wrapFlag, importId, addLines);
}
Also used : SimpleFunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression) 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)

Example 3 with BooleanPartContext

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

the class AntlrContextToM3CoreInstance method buildBoolean.

private SimpleFunctionExpression buildBoolean(BooleanPartContext ctx, BoolOp op, CoreInstance initialValue, String exprName, MutableList<String> typeParamtersNames, LambdaContext lambdaContext, String space, boolean wrapFlag, ImportGroup importId, boolean addLines) {
    TerminalNode terminalNode;
    switch(op) {
        case AND:
            {
                terminalNode = ctx.AND();
                break;
            }
        case OR:
            {
                terminalNode = ctx.OR();
                break;
            }
        default:
            {
                throw new IllegalArgumentException("Unexpected boolean operation in buildBoolean" + op);
            }
    }
    CoreInstance other = this.expression(ctx.expression(), exprName, typeParamtersNames, lambdaContext, space, wrapFlag, importId, addLines);
    SimpleFunctionExpression sfe = SimpleFunctionExpressionInstance.createPersistent(this.repository, this.sourceInformation.getPureSourceInformation(terminalNode.getSymbol()), null, null, importId, null);
    sfe._functionName(op.name().toLowerCase());
    sfe._parametersValues(Lists.mutable.of((ValueSpecification) initialValue, (ValueSpecification) other));
    return sfe;
}
Also used : SimpleFunctionExpression(org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression) 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) TerminalNode(org.antlr.v4.runtime.tree.TerminalNode)

Aggregations

ValueSpecification (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.ValueSpecification)3 CoreInstance (org.finos.legend.pure.m4.coreinstance.CoreInstance)3 PrimitiveCoreInstance (org.finos.legend.pure.m4.coreinstance.primitive.PrimitiveCoreInstance)3 SimpleFunctionExpression (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.valuespecification.SimpleFunctionExpression)2 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)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