UNPKG

ifc-expressions

Version:

Parsing and evaluation of IFC expressions

137 lines (136 loc) 4.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Types = exports.Type = void 0; const SimpleType_js_1 = require("./SimpleType.js"); const TypeDisjunction_js_1 = require("./TypeDisjunction.js"); const ArrayType_js_1 = require("./ArrayType.js"); const TupleType_js_1 = require("./TupleType.js"); class Type { } exports.Type = Type; Type.ANY = new SimpleType_js_1.SimpleType("any"); Type.NUMERIC = new SimpleType_js_1.SimpleType("numeric"); Type.STRING = new SimpleType_js_1.SimpleType("string"); Type.LOGICAL = new SimpleType_js_1.SimpleType("logical"); Type.BOOLEAN = new SimpleType_js_1.SimpleType("boolean", Type.LOGICAL); Type.IFC_DATE = new SimpleType_js_1.SimpleType("ifcDate", Type.STRING); Type.IFC_DATE_TIME = new SimpleType_js_1.SimpleType("ifcDateTime", Type.STRING); Type.IFC_TIME = new SimpleType_js_1.SimpleType("ifcTime", Type.STRING); Type.IFC_DURATION = new SimpleType_js_1.SimpleType("ifcDuration", Type.STRING); Type.IFC_TIME_STAMP = new SimpleType_js_1.SimpleType("ifcTimeStamp", Type.NUMERIC); Type.IFC_OBJECT_REF = new SimpleType_js_1.SimpleType("ifcObjectRef"); Type.IFC_ELEMENT_REF = new SimpleType_js_1.SimpleType("ifcElementRef", Type.IFC_OBJECT_REF); Type.IFC_PROPERTY_REF = new SimpleType_js_1.SimpleType("ifcPropertyRef", Type.IFC_OBJECT_REF); Type.IFC_PROPERTY_SET_REF = new SimpleType_js_1.SimpleType("ifcPropertySetRef", Type.IFC_OBJECT_REF); Type.IFC_TYPE_OBJECT_REF = new SimpleType_js_1.SimpleType("ifcTypeObjectRef", Type.IFC_OBJECT_REF); Type.ARRAY = new SimpleType_js_1.SimpleType("array"); class Types { static or(...types) { const disjunction = new TypeDisjunction_js_1.TypeDisjunction(...types); if (disjunction.getTypes().length == 1) { return disjunction.getTypes()[0]; } return disjunction; } static array(elementType) { return new ArrayType_js_1.ArrayType(elementType); } static tuple(...types) { return new TupleType_js_1.TupleType(...types); } static isNumeric(actualType) { return this.isType(actualType, Type.NUMERIC); } static isBoolean(actualType) { return this.isType(actualType, Type.BOOLEAN); } static isLogical(actualType) { return this.isType(actualType, Type.LOGICAL); } static isString(actualType) { return this.isType(actualType, Type.STRING); } static isIfcDate(actualType) { return this.isType(actualType, Type.IFC_DATE); } static isIfcDateTime(actualType) { return this.isType(actualType, Type.IFC_DATE_TIME); } static isIfcTime(actualType) { return this.isType(actualType, Type.IFC_TIME); } static isIfcDuration(actualType) { return this.isType(actualType, Type.IFC_DURATION); } static isIfcTimeStamp(actualType) { return this.isType(actualType, Type.IFC_TIME_STAMP); } static isType(actualType, type) { return actualType === type; } static boolean() { return Type.BOOLEAN; } static logical() { return Type.LOGICAL; } static string() { return Type.STRING; } static ifcDate() { return Type.IFC_DATE; } static ifcDateTime() { return Type.IFC_DATE_TIME; } static ifcTime() { return Type.IFC_TIME; } static ifcDuration() { return Type.IFC_DURATION; } static ifcTimeStamp() { return Type.IFC_TIME_STAMP; } static numeric() { return Type.NUMERIC; } static ifcObjectRef() { return Type.IFC_OBJECT_REF; } static requireIsAssignableFrom(expectedType, actualType, exceptionProducer) { if (!expectedType.isAssignableFrom(actualType)) { throw exceptionProducer(); } } /** * Requires overlap if actual is a disjunction, assignable from if it is a type * @param expectedType * @param actualType * @param exceptionProducer */ static requireWeakIsAssignableFrom(expectedType, actualType, exceptionProducer) { if (expectedType.isAssignableFrom(actualType)) { return; } if (actualType instanceof TypeDisjunction_js_1.TypeDisjunction) { if (expectedType.overlapsWith(actualType)) { return; } } if (actualType instanceof TupleType_js_1.TupleType) { const weakerType = Types.array(Types.or(...actualType.getTypes())); if (expectedType.isAssignableFrom(weakerType)) { return; } } throw exceptionProducer(); } static requireTypesOverlap(actualType, actualType2, exceptionProducer) { if (!actualType.overlapsWith(actualType2)) { throw exceptionProducer(); } } } exports.Types = Types; //# sourceMappingURL=Types.js.map