UNPKG

ifc-expressions

Version:

Parsing and evaluation of IFC expressions

42 lines (41 loc) 2.02 kB
import { FuncArg } from "../FuncArg.js"; import { ExprEvalTypeErrorObj, isExprEvalSuccess, } from "../../ExprEvalResult.js"; import { ArrayValue } from "../../../value/ArrayValue.js"; import { ExprKind } from "../../ExprKind.js"; import { Type, Types } from "../../../type/Types.js"; export class FuncArgMappings extends FuncArg { constructor(required, name) { super(required, name); } getType() { return Types.array(Types.tuple(Type.ANY, Type.ANY)); } transformValue(callingExpr, invocationValue) { if (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.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 ExprEvalTypeErrorObj(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()); } } //# sourceMappingURL=FuncArgMappings.js.map