ifc-expressions
Version:
Parsing and evaluation of IFC expressions
30 lines (29 loc) • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FuncArgRegexFlag = void 0;
const FuncArgString_js_1 = require("./FuncArgString.js");
const ExprEvalResult_js_1 = require("../../ExprEvalResult.js");
const ExprKind_js_1 = require("../../ExprKind.js");
const IfcExpressionUtils_js_1 = require("../../../util/IfcExpressionUtils.js");
class FuncArgRegexFlag extends FuncArgString_js_1.FuncArgString {
constructor(required, name, defaultValue) {
super(required, name, defaultValue);
}
transformForTypeCheck(callingExpr, invocationValue) {
const val = super.transformForTypeCheck(callingExpr, invocationValue);
if ((0, ExprEvalResult_js_1.isExprEvalError)(val)) {
return val;
}
const stringValue = val.result.getValue();
if ((0, IfcExpressionUtils_js_1.isNullish)(stringValue.match(/^[imguv]*$/)) || // allowed flags not found
!(0, IfcExpressionUtils_js_1.isNullish)(stringValue.match(/^.*([imguv]).*\1.*$/))) {
/* duplicated flags found */ return new ExprEvalResult_js_1.ExprEvalTypeErrorObj(ExprKind_js_1.ExprKind.FUNCTION_ARGUMENTS, `Argument ${this.name} is a possibly empty collection of 'flags' for a javascript ` +
`regular expression. Order does not matter, duplicate flags are not allowed. ` +
`The flags are: 'g','i','m','s','u' and 'v'. The provided value, '${stringValue}' is not allowed. ` +
`By the way the default value is '${this.defaultValue.getValue()}'`, callingExpr.getTextSpan());
}
return val;
}
}
exports.FuncArgRegexFlag = FuncArgRegexFlag;
//# sourceMappingURL=FuncArgRegexFlag.js.map