ifc-expressions
Version:
Parsing and evaluation of IFC expressions
112 lines (111 loc) • 4.83 kB
JavaScript
import { isNullish } from "../../util/IfcExpressionUtils.js";
import { MAP } from "./impl/MAP.js";
import { ROUND } from "./impl/ROUND.js";
import { AttributeAccessorFunction } from "./impl/AttributeAccessorFunction.js";
import { PROPERTYSET } from "./impl/PROPERTYSET.js";
import { PROPERTY } from "./impl/PROPERTY.js";
import { TYPE } from "./impl/TYPE.js";
import { FuncBooleanBinary } from "./impl/FuncBooleanBinary.js";
import { NOT } from "./impl/NOT.js";
import { CHOOSE } from "./impl/CHOOSE.js";
import { MatchesPattern } from "./impl/MatchesPattern.js";
import { Type, Types } from "../../type/Types.js";
import { TOSTRING } from "./impl/TOSTRING.js";
import { EXISTS } from "./impl/EXISTS.js";
import { EQUALS } from "./impl/EQUALS.js";
import { CompareMagnitudes } from "./impl/CompareMagnitudes.js";
import { ReplacePattern } from "./impl/ReplacePattern.js";
import { IF } from "./impl/IF.js";
import { TONUMERIC } from "./impl/TONUMERIC.js";
import { IfcExpressionFunctionConfigException } from "../../error/IfcExpressionFunctionConfigException.js";
import { TOBOOLEAN } from "./impl/TOBOOLEAN.js";
import { TOLOGICAL } from "./impl/TOLOGICAL.js";
import { TOLOWERCASE } from "./impl/TOLOWERCASE.js";
import { TOUPPERCASE } from "./impl/TOUPPERCASE.js";
import { SUBSTRING } from "./impl/SUBSTRING.js";
import { SPLIT } from "./impl/SPLIT.js";
import { AT } from "./impl/AT.js";
import { TOIFCDATE } from "./impl/TOIFCDATE.js";
import { TOIFCDATETIME } from "./impl/TOIFCDATETIME.js";
import { TOIFCTIME } from "./impl/TOIFCTIME.js";
import { TOIFCDURATION } from "./impl/TOIFCDURATION.js";
import { TOIFCTIMESTAMP } from "./impl/TOIFCTIMESTAMP.js";
import { ADDDURATION } from "./impl/ADDDURATION.js";
const builtinFunctions = new Map();
function registerOrDie(fnKey, func) {
if (builtinFunctions.has(fnKey)) {
throw new IfcExpressionFunctionConfigException(`cannot register function with name '${fnKey}': name already in use`);
}
builtinFunctions.set(fnKey, func);
}
function registerFunc(func, ...aliases) {
const fnKey = func.getName();
const keys = [...aliases];
keys.unshift(fnKey);
keys.forEach((key) => registerOrDie(IfcExpressionFunctions.normalizeName(key), func));
}
export class IfcExpressionFunctions {
static normalizeName(name) {
if (isNullish(name)) {
return undefined;
}
return name.toUpperCase();
}
static isBuiltinFunction(name) {
if (isNullish(name)) {
return false;
}
return builtinFunctions.has(this.normalizeName(name));
}
static getFunction(name) {
if (isNullish(name)) {
return undefined;
}
return builtinFunctions.get(this.normalizeName(name));
}
}
registerFunc(new MAP());
registerFunc(new CHOOSE());
registerFunc(new AT());
registerFunc(new IF());
registerFunc(new ROUND());
registerFunc(new AttributeAccessorFunction("name", Type.STRING));
registerFunc(new AttributeAccessorFunction("guid", Type.STRING));
registerFunc(new AttributeAccessorFunction("ifcClass", Type.STRING));
registerFunc(new AttributeAccessorFunction("description", Type.STRING));
registerFunc(new AttributeAccessorFunction("value", Types.or(Type.STRING, Type.NUMERIC, Type.BOOLEAN, Type.ARRAY)));
registerFunc(new PROPERTYSET());
registerFunc(new PROPERTY());
registerFunc(new TYPE());
registerFunc(new NOT());
registerFunc(new TOSTRING());
registerFunc(new TONUMERIC(), "TONUMBER");
registerFunc(new TOBOOLEAN());
registerFunc(new TOLOGICAL(), "NOTFOUNDASUNKNOWN");
registerFunc(new TOIFCDATE());
registerFunc(new TOIFCTIME());
registerFunc(new TOIFCDATETIME());
registerFunc(new TOIFCDURATION());
registerFunc(new TOIFCTIMESTAMP());
registerFunc(new ADDDURATION());
registerFunc(new TOLOWERCASE());
registerFunc(new TOUPPERCASE());
registerFunc(new SUBSTRING());
registerFunc(new SPLIT());
registerFunc(new EXISTS());
registerFunc(new FuncBooleanBinary("AND", "and"));
registerFunc(new FuncBooleanBinary("OR", "or"));
registerFunc(new FuncBooleanBinary("XOR", "xor"));
registerFunc(new FuncBooleanBinary("IMPLIES", "implies"));
registerFunc(new EQUALS());
registerFunc(new CompareMagnitudes("GREATERTHAN", (cmp) => cmp > 0));
registerFunc(new CompareMagnitudes("GREATERTHANOREQUAL", (cmp) => cmp >= 0));
registerFunc(new CompareMagnitudes("LESSTHAN", (cmp) => cmp < 0));
registerFunc(new CompareMagnitudes("LESSTHANOREQUAL", (cmp) => cmp <= 0));
registerFunc(new MatchesPattern("CONTAINS", true, false));
registerFunc(new MatchesPattern("MATCHES", true, true));
registerFunc(new MatchesPattern("REGEXCONTAINS", false, false));
registerFunc(new MatchesPattern("REGEXMATCHES", false, true));
registerFunc(new ReplacePattern("REPLACE", true));
registerFunc(new ReplacePattern("REGEXREPLACE", false));
//# sourceMappingURL=IfcExpressionFunctions.js.map