ifc-expressions
Version:
Parsing and evaluation of IFC expressions
48 lines (47 loc) • 2.08 kB
JavaScript
import { ExprBase } from "./ExprBase.js";
import { ExprEvalError2Obj, ExprEvalErrorUndefinedResult, ExprEvalStatus, isExprEvalError, isExprEvalSuccess, } from "./ExprEvalResult.js";
import { isNullish } from "../util/IfcExpressionUtils.js";
export class Expr2LeftBeforeRight extends ExprBase {
constructor(exprKind, left, right) {
super(exprKind);
this.left = left;
this.right = right;
}
getChildren() {
return [this.left, this.right];
}
evaluate(ctx, localCtx) {
const leftResult = this.left.evaluate(ctx, localCtx);
if (isNullish(leftResult)) {
return new ExprEvalErrorUndefinedResult(this.left.getKind(), this.getTextSpan());
}
this.handleLeftResult(leftResult);
const rightResult = this.right.evaluate(ctx, localCtx);
if (isNullish(leftResult) || isNullish(rightResult)) {
return new ExprEvalError2Obj(this.getKind(), isNullish(leftResult)
? new ExprEvalErrorUndefinedResult(this.left.getKind())
: leftResult, isNullish(rightResult)
? new ExprEvalErrorUndefinedResult(this.right.getKind())
: rightResult, ExprEvalStatus.MISSING_OPERAND, undefined, this.getTextSpan());
}
if (isExprEvalSuccess(leftResult) && isExprEvalSuccess(rightResult)) {
try {
const result = this.doEvaluate(ctx, leftResult.result, rightResult.result);
return this.wrapInResultIfNecessary(result);
}
catch (error) {
return this.handleError(error, leftResult, rightResult);
}
}
else if (isExprEvalError(leftResult)) {
return leftResult;
}
else if (isExprEvalError(rightResult)) {
return rightResult;
}
}
handleError(error, leftResult, rightResult) {
return new ExprEvalError2Obj(this.getKind(), leftResult, rightResult, ExprEvalStatus.ERROR, error, this.getTextSpan());
}
}
//# sourceMappingURL=Expr2LeftBeforeRight.js.map