UNPKG

ifc-expressions

Version:

Parsing and evaluation of IFC expressions

26 lines (25 loc) 1.41 kB
import { FuncArgString } from "./FuncArgString.js"; import { ExprEvalTypeErrorObj, isExprEvalError, } from "../../ExprEvalResult.js"; import { ExprKind } from "../../ExprKind.js"; import { isNullish } from "../../../util/IfcExpressionUtils.js"; export class FuncArgRegexFlag extends FuncArgString { constructor(required, name, defaultValue) { super(required, name, defaultValue); } transformForTypeCheck(callingExpr, invocationValue) { const val = super.transformForTypeCheck(callingExpr, invocationValue); if (isExprEvalError(val)) { return val; } const stringValue = val.result.getValue(); if (isNullish(stringValue.match(/^[imguv]*$/)) || // allowed flags not found !isNullish(stringValue.match(/^.*([imguv]).*\1.*$/))) { /* duplicated flags found */ return new ExprEvalTypeErrorObj(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; } } //# sourceMappingURL=FuncArgRegexFlag.js.map