UNPKG

ifc-expressions

Version:

Parsing and evaluation of IFC expressions

58 lines (57 loc) 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Expr1 = void 0; const ExprEvalResult_js_1 = require("./ExprEvalResult.js"); const ExprBase_js_1 = require("./ExprBase.js"); const IfcExpressionUtils_js_1 = require("../util/IfcExpressionUtils.js"); class Expr1 extends ExprBase_js_1.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 ((0, ExprEvalResult_js_1.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 (!(0, IfcExpressionUtils_js_1.isNullish)(beforeRecursionError)) { return beforeRecursionError; } const subResult = this.sub.evaluate(ctx, localCtx); if ((0, IfcExpressionUtils_js_1.isNullish)(subResult)) { return new ExprEvalResult_js_1.ExprEvalError1Obj(this.getKind(), new ExprEvalResult_js_1.ExprEvalErrorUndefinedResult(this.sub.getKind()), ExprEvalResult_js_1.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 ExprEvalResult_js_1.ExprEvalError1Obj(this.getKind(), subResult, ExprEvalResult_js_1.ExprEvalStatus.ERROR, error, this.getTextSpan()); } } exports.Expr1 = Expr1; //# sourceMappingURL=Expr1.js.map