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;
}
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);
}
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;
}
Aggregations