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