ifc-expressions
Version:
Parsing and evaluation of IFC expressions
54 lines (53 loc) • 2.05 kB
JavaScript
import { ExprEvalError1Obj, ExprEvalErrorUndefinedResult, ExprEvalStatus, isExprEvalError, } from "./ExprEvalResult.js";
import { ExprBase } from "./ExprBase.js";
import { isNullish } from "../util/IfcExpressionUtils.js";
export class Expr1 extends ExprBase {
constructor(exprKind, sub) {
super(exprKind);
this.sub = sub;
}
getChildren() {
return [this.sub];
}
/**
* Override to generate a more specific error result.
* @param ctx
* @param localCtx
* @param subExpressionResult
* @protected
*/
obtainResultForSubExpressionError(ctx, localCtx, subExpressionResult) {
return subExpressionResult;
}
// calculate the final result
makeErrorOrCalculate(ctx, localCtx, subExpressionResult) {
if (isExprEvalError(subExpressionResult)) {
return this.obtainResultForSubExpressionError(ctx, localCtx, subExpressionResult);
}
return this.wrapInResultIfNecessary(this.calculateResult(ctx, localCtx, subExpressionResult.result));
}
onBeforeRecusion(ctx, localCtx) {
// do something before we calculate the subresult
return undefined;
}
evaluate(ctx, localCtx) {
const beforeRecursionError = this.onBeforeRecusion(ctx, localCtx);
if (!isNullish(beforeRecursionError)) {
return beforeRecursionError;
}
const subResult = this.sub.evaluate(ctx, localCtx);
if (isNullish(subResult)) {
return new ExprEvalError1Obj(this.getKind(), new ExprEvalErrorUndefinedResult(this.sub.getKind()), ExprEvalStatus.MISSING_OPERAND, undefined, this.getTextSpan());
}
try {
return this.makeErrorOrCalculate(ctx, localCtx, subResult);
}
catch (error) {
return this.handleError(error, subResult);
}
}
handleError(error, subResult) {
return new ExprEvalError1Obj(this.getKind(), subResult, ExprEvalStatus.ERROR, error, this.getTextSpan());
}
}
//# sourceMappingURL=Expr1.js.map