UNPKG

ifc-expressions

Version:

Parsing and evaluation of IFC expressions

38 lines (37 loc) 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PlusOrConcatExpr = void 0; const Expr2_js_1 = require("../Expr2.js"); const NumericValue_js_1 = require("../../value/NumericValue.js"); const ExprKind_js_1 = require("../ExprKind.js"); const StringValue_js_1 = require("../../value/StringValue.js"); const ExprEvalResult_js_1 = require("../ExprEvalResult.js"); const Types_js_1 = require("../../type/Types.js"); class PlusOrConcatExpr extends Expr2_js_1.Expr2 { constructor(left, right) { super(ExprKind_js_1.ExprKind.NUM_PLUS, left, right); } calculateResult(ctx, localCtx, leftResult, rightResult) { if (leftResult instanceof NumericValue_js_1.NumericValue && rightResult instanceof NumericValue_js_1.NumericValue) { return NumericValue_js_1.NumericValue.of(leftResult.getValue().plus(rightResult.getValue())); } else if (leftResult instanceof StringValue_js_1.StringValue && rightResult instanceof StringValue_js_1.StringValue) { return StringValue_js_1.StringValue.of(leftResult.getValue() + rightResult.getValue()); } return new ExprEvalResult_js_1.ExprEvalTypeErrorObj(ExprKind_js_1.ExprKind.FUNCTION, `Operator '+' requires the operands to be either both of type numeric or both of type string, but they are '${leftResult .getType() .getName()}' (left operand) and '${rightResult .getType() .getName()}' (right operand)`, [leftResult, rightResult], this.getTextSpan()); } buildExprString(builder) { builder.appendExpr(this.left).appendString(" + ").appendExpr(this.right); } getType() { return Types_js_1.Types.or(Types_js_1.Type.NUMERIC, Types_js_1.Type.STRING); } } exports.PlusOrConcatExpr = PlusOrConcatExpr; //# sourceMappingURL=PlusOrConcatExpr.js.map