UNPKG

ifc-expressions

Version:

Parsing and evaluation of IFC expressions

46 lines (45 loc) 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FuncArgMappings = void 0; const FuncArg_js_1 = require("../FuncArg.js"); const ExprEvalResult_js_1 = require("../../ExprEvalResult.js"); const ArrayValue_js_1 = require("../../../value/ArrayValue.js"); const ExprKind_js_1 = require("../../ExprKind.js"); const Types_js_1 = require("../../../type/Types.js"); class FuncArgMappings extends FuncArg_js_1.FuncArg { constructor(required, name) { super(required, name); } getType() { return Types_js_1.Types.array(Types_js_1.Types.tuple(Types_js_1.Type.ANY, Types_js_1.Type.ANY)); } transformValue(callingExpr, invocationValue) { if ((0, ExprEvalResult_js_1.isExprEvalSuccess)(invocationValue)) { const mappings = invocationValue.result; if (!Array.isArray(mappings.getValue())) { return FuncArgMappings.makeError(callingExpr, mappings, "The value is not an array"); } const arr = mappings.getValue(); if (arr.length === 0) { return FuncArgMappings.makeError(callingExpr, mappings, "The mappings array is empty"); } } return invocationValue; } static checkSingleMapping(callingExpr, mappings, index) { const element = mappings[index]; if (!ArrayValue_js_1.ArrayValue.isArrayValueType(element)) { return FuncArgMappings.makeError(callingExpr, element, `The element at 0-based position${index} is not an array: ${JSON.stringify(element)}`); } const pair = element.getValue(); if (pair.length !== 2) { return FuncArgMappings.makeError(callingExpr, element, `The array at 0-based position ${index} must be of length 2 but is of length ${pair.length}`); } return undefined; } static makeError(callingExpr, mappings, problem) { return new ExprEvalResult_js_1.ExprEvalTypeErrorObj(ExprKind_js_1.ExprKind.FUNCTION_ARGUMENTS, `Argument ${this.name} must be an array containing two arrays of the same length (i.e., a 2xn matrix: 2 rows, N columns). Problem: ${problem}.`, mappings, callingExpr.getTextSpan()); } } exports.FuncArgMappings = FuncArgMappings; //# sourceMappingURL=FuncArgMappings.js.map