24 lines
921 B
Java
24 lines
921 B
Java
package io.gitlab.jfronny.muscript.compiler.expr.common.conditional;
|
|
|
|
import io.gitlab.jfronny.muscript.compiler.expr.*;
|
|
import io.gitlab.jfronny.muscript.dynamic.*;
|
|
|
|
public class StringConditional extends StringExpr {
|
|
public final BoolExpr condition;
|
|
public final StringExpr trueExpr;
|
|
public final StringExpr falseExpr;
|
|
|
|
public StringConditional(BoolExpr condition, StringExpr trueExpr, StringExpr falseExpr) {
|
|
this.condition = condition;
|
|
this.trueExpr = trueExpr;
|
|
this.falseExpr = falseExpr;
|
|
if (trueExpr.getResultType() != falseExpr.getResultType())
|
|
throw new IllegalArgumentException("Values used in conditional operator must be of the same type");
|
|
}
|
|
|
|
@Override
|
|
public String get(Dynamic<?> branch, Dynamic<?> dataRoot) {
|
|
return condition.get(branch, dataRoot) ? trueExpr.get(branch, dataRoot) : falseExpr.get(branch, dataRoot);
|
|
}
|
|
}
|