@itwin/grouping-mapping-widget 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/formula/FormulaFunctionProvider.d.ts +18 -0
- package/lib/cjs/formula/FormulaFunctionProvider.js +136 -0
- package/lib/cjs/formula/FormulaFunctionProvider.js.map +1 -0
- package/lib/cjs/formula/FormulaOperatorsProvider.d.ts +34 -0
- package/lib/cjs/formula/FormulaOperatorsProvider.js +185 -0
- package/lib/cjs/formula/FormulaOperatorsProvider.js.map +1 -0
- package/lib/cjs/formula/FormulaSplitter.d.ts +2 -0
- package/lib/cjs/formula/FormulaSplitter.js +140 -0
- package/lib/cjs/formula/FormulaSplitter.js.map +1 -0
- package/lib/cjs/formula/FormulaTokensValidator.d.ts +5 -0
- package/lib/cjs/formula/FormulaTokensValidator.js +135 -0
- package/lib/cjs/formula/FormulaTokensValidator.js.map +1 -0
- package/lib/cjs/formula/FormulaValidator.d.ts +3 -0
- package/lib/cjs/formula/FormulaValidator.js +35 -0
- package/lib/cjs/formula/FormulaValidator.js.map +1 -0
- package/lib/cjs/formula/IResult.d.ts +5 -0
- package/lib/cjs/formula/IResult.js +3 -0
- package/lib/cjs/formula/IResult.js.map +1 -0
- package/lib/cjs/formula/InfixToPostfixConverter.d.ts +18 -0
- package/lib/cjs/formula/InfixToPostfixConverter.js +299 -0
- package/lib/cjs/formula/InfixToPostfixConverter.js.map +1 -0
- package/lib/cjs/formula/InputStream.d.ts +12 -0
- package/lib/cjs/formula/InputStream.js +36 -0
- package/lib/cjs/formula/InputStream.js.map +1 -0
- package/lib/cjs/formula/ParenthesisValidator.d.ts +7 -0
- package/lib/cjs/formula/ParenthesisValidator.js +34 -0
- package/lib/cjs/formula/ParenthesisValidator.js.map +1 -0
- package/lib/cjs/formula/Queue.d.ts +11 -0
- package/lib/cjs/formula/Queue.js +42 -0
- package/lib/cjs/formula/Queue.js.map +1 -0
- package/lib/cjs/formula/Stack.d.ts +14 -0
- package/lib/cjs/formula/Stack.js +71 -0
- package/lib/cjs/formula/Stack.js.map +1 -0
- package/lib/cjs/formula/StringBuilder.d.ts +9 -0
- package/lib/cjs/formula/StringBuilder.js +26 -0
- package/lib/cjs/formula/StringBuilder.js.map +1 -0
- package/lib/cjs/formula/Types.d.ts +8 -0
- package/lib/cjs/formula/Types.js +3 -0
- package/lib/cjs/formula/Types.js.map +1 -0
- package/lib/cjs/formula/Utils.d.ts +7 -0
- package/lib/cjs/formula/Utils.js +39 -0
- package/lib/cjs/formula/Utils.js.map +1 -0
- package/lib/cjs/widget/components/CalculatedPropertyAction.d.ts +1 -1
- package/lib/cjs/widget/components/CalculatedPropertyAction.js +3 -3
- package/lib/cjs/widget/components/CalculatedPropertyAction.js.map +1 -1
- package/lib/cjs/widget/components/CalculatedPropertyTable.d.ts +5 -2
- package/lib/cjs/widget/components/CalculatedPropertyTable.js +3 -27
- package/lib/cjs/widget/components/CalculatedPropertyTable.js.map +1 -1
- package/lib/cjs/widget/components/ConfirmMappingsImport.scss +4 -2
- package/lib/cjs/widget/components/CustomCalculationAction.d.ts +4 -2
- package/lib/cjs/widget/components/CustomCalculationAction.js +9 -4
- package/lib/cjs/widget/components/CustomCalculationAction.js.map +1 -1
- package/lib/cjs/widget/components/CustomCalculationTable.d.ts +5 -2
- package/lib/cjs/widget/components/CustomCalculationTable.js +3 -27
- package/lib/cjs/widget/components/CustomCalculationTable.js.map +1 -1
- package/lib/cjs/widget/components/GroupAction.js +2 -10
- package/lib/cjs/widget/components/GroupAction.js.map +1 -1
- package/lib/cjs/widget/components/GroupPropertyAction.d.ts +1 -1
- package/lib/cjs/widget/components/GroupPropertyAction.js +3 -3
- package/lib/cjs/widget/components/GroupPropertyAction.js.map +1 -1
- package/lib/cjs/widget/components/GroupPropertyTable.d.ts +5 -2
- package/lib/cjs/widget/components/GroupPropertyTable.js +3 -27
- package/lib/cjs/widget/components/GroupPropertyTable.js.map +1 -1
- package/lib/cjs/widget/components/MappingAction.js +2 -10
- package/lib/cjs/widget/components/MappingAction.js.map +1 -1
- package/lib/cjs/widget/components/MappingImportWizardModal.js +2 -2
- package/lib/cjs/widget/components/MappingImportWizardModal.js.map +1 -1
- package/lib/cjs/widget/components/MappingImportWizardModal.scss +6 -2
- package/lib/cjs/widget/components/PropertyMenu.js +68 -21
- package/lib/cjs/widget/components/PropertyMenu.js.map +1 -1
- package/lib/cjs/widget/components/SelectIModel.scss +2 -1
- package/lib/cjs/widget/components/SelectMapping.scss +2 -1
- package/lib/cjs/widget/components/SelectProject.js +9 -9
- package/lib/cjs/widget/components/SelectProject.js.map +1 -1
- package/lib/cjs/widget/components/SelectProject.scss +3 -8
- package/lib/cjs/widget/hooks/useFetchData.d.ts +9 -0
- package/lib/cjs/widget/hooks/useFetchData.js +41 -0
- package/lib/cjs/widget/hooks/useFetchData.js.map +1 -0
- package/lib/cjs/widget/hooks/useFormulaValidation.d.ts +6 -0
- package/lib/cjs/widget/hooks/useFormulaValidation.js +29 -0
- package/lib/cjs/widget/hooks/useFormulaValidation.js.map +1 -0
- package/lib/cjs/widget/utils.d.ts +1 -0
- package/lib/cjs/widget/utils.js +9 -0
- package/lib/cjs/widget/utils.js.map +1 -1
- package/lib/esm/formula/FormulaFunctionProvider.d.ts +18 -0
- package/lib/esm/formula/FormulaFunctionProvider.js +130 -0
- package/lib/esm/formula/FormulaFunctionProvider.js.map +1 -0
- package/lib/esm/formula/FormulaOperatorsProvider.d.ts +34 -0
- package/lib/esm/formula/FormulaOperatorsProvider.js +174 -0
- package/lib/esm/formula/FormulaOperatorsProvider.js.map +1 -0
- package/lib/esm/formula/FormulaSplitter.d.ts +2 -0
- package/lib/esm/formula/FormulaSplitter.js +136 -0
- package/lib/esm/formula/FormulaSplitter.js.map +1 -0
- package/lib/esm/formula/FormulaTokensValidator.d.ts +5 -0
- package/lib/esm/formula/FormulaTokensValidator.js +131 -0
- package/lib/esm/formula/FormulaTokensValidator.js.map +1 -0
- package/lib/esm/formula/FormulaValidator.d.ts +3 -0
- package/lib/esm/formula/FormulaValidator.js +31 -0
- package/lib/esm/formula/FormulaValidator.js.map +1 -0
- package/lib/esm/formula/IResult.d.ts +5 -0
- package/lib/esm/formula/IResult.js +2 -0
- package/lib/esm/formula/IResult.js.map +1 -0
- package/lib/esm/formula/InfixToPostfixConverter.d.ts +18 -0
- package/lib/esm/formula/InfixToPostfixConverter.js +295 -0
- package/lib/esm/formula/InfixToPostfixConverter.js.map +1 -0
- package/lib/esm/formula/InputStream.d.ts +12 -0
- package/lib/esm/formula/InputStream.js +32 -0
- package/lib/esm/formula/InputStream.js.map +1 -0
- package/lib/esm/formula/ParenthesisValidator.d.ts +7 -0
- package/lib/esm/formula/ParenthesisValidator.js +30 -0
- package/lib/esm/formula/ParenthesisValidator.js.map +1 -0
- package/lib/esm/formula/Queue.d.ts +11 -0
- package/lib/esm/formula/Queue.js +38 -0
- package/lib/esm/formula/Queue.js.map +1 -0
- package/lib/esm/formula/Stack.d.ts +14 -0
- package/lib/esm/formula/Stack.js +67 -0
- package/lib/esm/formula/Stack.js.map +1 -0
- package/lib/esm/formula/StringBuilder.d.ts +9 -0
- package/lib/esm/formula/StringBuilder.js +22 -0
- package/lib/esm/formula/StringBuilder.js.map +1 -0
- package/lib/esm/formula/Types.d.ts +8 -0
- package/lib/esm/formula/Types.js +2 -0
- package/lib/esm/formula/Types.js.map +1 -0
- package/lib/esm/formula/Utils.d.ts +7 -0
- package/lib/esm/formula/Utils.js +30 -0
- package/lib/esm/formula/Utils.js.map +1 -0
- package/lib/esm/widget/components/CalculatedPropertyAction.d.ts +1 -1
- package/lib/esm/widget/components/CalculatedPropertyAction.js +3 -3
- package/lib/esm/widget/components/CalculatedPropertyAction.js.map +1 -1
- package/lib/esm/widget/components/CalculatedPropertyTable.d.ts +5 -2
- package/lib/esm/widget/components/CalculatedPropertyTable.js +4 -28
- package/lib/esm/widget/components/CalculatedPropertyTable.js.map +1 -1
- package/lib/esm/widget/components/ConfirmMappingsImport.scss +4 -2
- package/lib/esm/widget/components/CustomCalculationAction.d.ts +4 -2
- package/lib/esm/widget/components/CustomCalculationAction.js +9 -4
- package/lib/esm/widget/components/CustomCalculationAction.js.map +1 -1
- package/lib/esm/widget/components/CustomCalculationTable.d.ts +5 -2
- package/lib/esm/widget/components/CustomCalculationTable.js +4 -28
- package/lib/esm/widget/components/CustomCalculationTable.js.map +1 -1
- package/lib/esm/widget/components/GroupAction.js +2 -10
- package/lib/esm/widget/components/GroupAction.js.map +1 -1
- package/lib/esm/widget/components/GroupPropertyAction.d.ts +1 -1
- package/lib/esm/widget/components/GroupPropertyAction.js +3 -3
- package/lib/esm/widget/components/GroupPropertyAction.js.map +1 -1
- package/lib/esm/widget/components/GroupPropertyTable.d.ts +5 -2
- package/lib/esm/widget/components/GroupPropertyTable.js +4 -28
- package/lib/esm/widget/components/GroupPropertyTable.js.map +1 -1
- package/lib/esm/widget/components/MappingAction.js +2 -10
- package/lib/esm/widget/components/MappingAction.js.map +1 -1
- package/lib/esm/widget/components/MappingImportWizardModal.js +2 -2
- package/lib/esm/widget/components/MappingImportWizardModal.js.map +1 -1
- package/lib/esm/widget/components/MappingImportWizardModal.scss +6 -2
- package/lib/esm/widget/components/PropertyMenu.js +69 -22
- package/lib/esm/widget/components/PropertyMenu.js.map +1 -1
- package/lib/esm/widget/components/SelectIModel.scss +2 -1
- package/lib/esm/widget/components/SelectMapping.scss +2 -1
- package/lib/esm/widget/components/SelectProject.js +9 -9
- package/lib/esm/widget/components/SelectProject.js.map +1 -1
- package/lib/esm/widget/components/SelectProject.scss +3 -8
- package/lib/esm/widget/hooks/useFetchData.d.ts +9 -0
- package/lib/esm/widget/hooks/useFetchData.js +35 -0
- package/lib/esm/widget/hooks/useFetchData.js.map +1 -0
- package/lib/esm/widget/hooks/useFormulaValidation.d.ts +6 -0
- package/lib/esm/widget/hooks/useFormulaValidation.js +25 -0
- package/lib/esm/widget/hooks/useFormulaValidation.js.map +1 -0
- package/lib/esm/widget/utils.d.ts +1 -0
- package/lib/esm/widget/utils.js +7 -1
- package/lib/esm/widget/utils.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { formatNumericalPositionString } from "./Utils";
|
|
2
|
+
function isValidArgument(arg, argPos, expectedArg) {
|
|
3
|
+
let isValid;
|
|
4
|
+
if (arg === "undefined") {
|
|
5
|
+
isValid = !!expectedArg.canBeUndefined;
|
|
6
|
+
return { isValid, invalidReason: isValid ? undefined : `Expected ${formatNumericalPositionString(argPos + 1)} argument to not be null.` };
|
|
7
|
+
}
|
|
8
|
+
isValid = expectedArg.canBeAny || arg === expectedArg.dataType;
|
|
9
|
+
return { isValid, invalidReason: isValid ? undefined : `Expected ${formatNumericalPositionString(argPos + 1)} argument to be of type ${expectedArg.dataType}.` };
|
|
10
|
+
}
|
|
11
|
+
function validateArgumentsWithTypeMatching() {
|
|
12
|
+
let matchType = "undefined";
|
|
13
|
+
return (arg, argPos, expectedArg, shouldMatchType) => {
|
|
14
|
+
if (shouldMatchType && matchType === "undefined")
|
|
15
|
+
matchType = arg;
|
|
16
|
+
const validation = isValidArgument(arg, argPos, expectedArg);
|
|
17
|
+
if (!validation.isValid)
|
|
18
|
+
return validation;
|
|
19
|
+
const isValid = (matchType === "undefined" || arg === matchType || (arg === "undefined" && !!expectedArg.canBeUndefined));
|
|
20
|
+
if (matchType !== "undefined" && !isValid)
|
|
21
|
+
return {
|
|
22
|
+
isValid,
|
|
23
|
+
matchingType: matchType,
|
|
24
|
+
invalidReason: `Expected ${formatNumericalPositionString(argPos + 1)} argument to be of type ${matchType}.`,
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
isValid,
|
|
28
|
+
matchingType: matchType,
|
|
29
|
+
invalidReason: isValid ? undefined : `${formatNumericalPositionString(argPos + 1)} argument is invalid.`,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function getFormulaFunctionReturnType(func, args) {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
const hasUnlimitedArguments = func.argumentCountBounds[1] === -1;
|
|
36
|
+
if (args.length < func.argumentCountBounds[0])
|
|
37
|
+
return { errorMessage: `Too few arguments received. Expected a minimum of ${func.argumentCountBounds[0]} argument(s)` };
|
|
38
|
+
if (!hasUnlimitedArguments && args.length > func.argumentCountBounds[1])
|
|
39
|
+
return { errorMessage: `Too many arguments received. Expected a maximum of ${func.argumentCountBounds[1]} argument(s)` };
|
|
40
|
+
let returnType = (_a = func.returnType) !== null && _a !== void 0 ? _a : "undefined";
|
|
41
|
+
const validationFunc = func.typesMatchFromIndex === undefined ? isValidArgument : validateArgumentsWithTypeMatching();
|
|
42
|
+
for (let i = 0; i < args.length; i++) {
|
|
43
|
+
const shouldTypeMatch = func.typesMatchFromIndex !== undefined && i >= func.typesMatchFromIndex;
|
|
44
|
+
const expectedTypeIndex = hasUnlimitedArguments && i > func.argumentCountBounds[0] - 1 ? func.argumentCountBounds[0] - 1 : i;
|
|
45
|
+
const expectedArg = func.expectedArguments[expectedTypeIndex];
|
|
46
|
+
const validationResult = validationFunc(args[i], i, expectedArg, shouldTypeMatch);
|
|
47
|
+
if (!validationResult.isValid)
|
|
48
|
+
return { errorMessage: validationResult.invalidReason };
|
|
49
|
+
if (func.isreturnTypeFromTypeMatch && shouldTypeMatch)
|
|
50
|
+
returnType = (_b = validationResult.matchingType) !== null && _b !== void 0 ? _b : "undefined";
|
|
51
|
+
}
|
|
52
|
+
return { value: returnType };
|
|
53
|
+
}
|
|
54
|
+
function getNumericalFunction(name) {
|
|
55
|
+
switch (name) {
|
|
56
|
+
case "abs": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
57
|
+
case "acos": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
58
|
+
case "acosh": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
59
|
+
case "asin": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
60
|
+
case "asinh": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
61
|
+
case "atan": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
62
|
+
case "atanh": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
63
|
+
case "atan2": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "number" }, { dataType: "number" }], returnType: "number" };
|
|
64
|
+
case "cbrt": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
65
|
+
case "ceil": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
66
|
+
case "clz32": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
67
|
+
case "cos": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
68
|
+
case "cosh": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
69
|
+
case "exp": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
70
|
+
case "expm1": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
71
|
+
case "floor": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
72
|
+
case "fround": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
73
|
+
case "hypot": return { argumentCountBounds: [2, -1], expectedArguments: [{ dataType: "number" }, { dataType: "number" }], returnType: "number" };
|
|
74
|
+
case "imul": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "number" }, { dataType: "number" }], returnType: "number" };
|
|
75
|
+
case "log": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
76
|
+
case "log1p": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
77
|
+
case "log10": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
78
|
+
case "log2": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
79
|
+
case "max": return { argumentCountBounds: [2, -1], expectedArguments: [{ dataType: "number" }, { dataType: "number" }], returnType: "number" };
|
|
80
|
+
case "min": return { argumentCountBounds: [2, -1], expectedArguments: [{ dataType: "number" }, { dataType: "number" }], returnType: "number" };
|
|
81
|
+
case "pow": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "number" }, { dataType: "number" }], returnType: "number" };
|
|
82
|
+
case "random": return { argumentCountBounds: [0, 0], expectedArguments: [], returnType: "number" };
|
|
83
|
+
case "round": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
84
|
+
case "sign": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
85
|
+
case "sin": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
86
|
+
case "sinh": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
87
|
+
case "sqrt": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
88
|
+
case "tan": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
89
|
+
case "tanh": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
90
|
+
case "trunc": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
91
|
+
default: return undefined;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function getStringFunction(name) {
|
|
95
|
+
switch (name) {
|
|
96
|
+
case "charat": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "string" }, { dataType: "number" }], returnType: "string" };
|
|
97
|
+
case "concat": return { argumentCountBounds: [2, -1], expectedArguments: [{ dataType: "string" }, { dataType: "string" }], returnType: "string" };
|
|
98
|
+
case "padend": return { argumentCountBounds: [2, 3], expectedArguments: [{ dataType: "string" }, { dataType: "number" }, { dataType: "string" }], returnType: "string" };
|
|
99
|
+
case "padstart": return { argumentCountBounds: [2, 3], expectedArguments: [{ dataType: "string" }, { dataType: "number" }, { dataType: "string" }], returnType: "string" };
|
|
100
|
+
case "substring": return { argumentCountBounds: [2, 3], expectedArguments: [{ dataType: "string" }, { dataType: "number" }, { dataType: "number" }], returnType: "string" };
|
|
101
|
+
case "tolowercase": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "string" }], returnType: "string" };
|
|
102
|
+
case "touppercase": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "string" }], returnType: "string" };
|
|
103
|
+
case "trim": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "string" }], returnType: "string" };
|
|
104
|
+
case "trimend": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "string" }], returnType: "string" };
|
|
105
|
+
case "trimstart": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "string" }], returnType: "string" };
|
|
106
|
+
default: return undefined;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function getConditionalFunction(name) {
|
|
110
|
+
switch (name) {
|
|
111
|
+
case "if": return { argumentCountBounds: [3, 3], expectedArguments: [{ dataType: "boolean" }, { canBeAny: true, canBeUndefined: true }, { canBeAny: true, canBeUndefined: true }], typesMatchFromIndex: 1, isreturnTypeFromTypeMatch: true };
|
|
112
|
+
case "ifnull": return { argumentCountBounds: [2, 2], expectedArguments: [{ canBeAny: true, canBeUndefined: true }, { canBeAny: true }], typesMatchFromIndex: 0, isreturnTypeFromTypeMatch: true };
|
|
113
|
+
case "ifnotnull": return { argumentCountBounds: [2, 2], expectedArguments: [{ canBeAny: true, canBeUndefined: true }, { canBeAny: true }], typesMatchFromIndex: 0, isreturnTypeFromTypeMatch: true };
|
|
114
|
+
case "ifempty": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "string" }, { dataType: "string" }], returnType: "string" };
|
|
115
|
+
case "ifnotempty": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "string" }, { dataType: "string" }], returnType: "string" };
|
|
116
|
+
case "ifnullorempty": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "string", canBeUndefined: true }, { dataType: "string" }], returnType: "string" };
|
|
117
|
+
case "ifnotnullorempty": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "string", canBeUndefined: true }, { dataType: "string" }], returnType: "string" };
|
|
118
|
+
case "ifnullorwhitespace": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "string", canBeUndefined: true }, { dataType: "string" }], returnType: "string" };
|
|
119
|
+
case "ifnotnullorwhitespace": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "string", canBeUndefined: true }, { dataType: "string" }], returnType: "string" };
|
|
120
|
+
default: return undefined;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export function getFunction(name) {
|
|
124
|
+
const nameLowerCase = name.toLowerCase();
|
|
125
|
+
return getNumericalFunction(nameLowerCase) || getStringFunction(nameLowerCase) || getConditionalFunction(nameLowerCase);
|
|
126
|
+
}
|
|
127
|
+
export function isFunction(name) {
|
|
128
|
+
return !!getFunction(name);
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=FormulaFunctionProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormulaFunctionProvider.js","sourceRoot":"","sources":["../../../src/formula/FormulaFunctionProvider.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,6BAA6B,EAAE,MAAM,SAAS,CAAC;AAsBxD,SAAS,eAAe,CAAC,GAAqB,EAAE,MAAc,EAAE,WAAoC;IAClG,I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,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,aAAa,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACzC,OAAO,oBAAoB,CAAC,aAAa,CAAC,IAAI,iBAAiB,CAAC,aAAa,CAAC,IAAI,sBAAsB,CAAC,aAAa,CAAC,CAAC;AAC1H,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport type { IResult } from \"./IResult\";\nimport type { DataType, PossibleDataType } from \"./Types\";\nimport { formatNumericalPositionString } from \"./Utils\";\n\nexport interface FormulaFunctionArgument {\n dataType?: DataType;\n canBeAny?: boolean;\n canBeUndefined?: boolean;\n}\n\nexport interface FormulaFunction {\n argumentCountBounds: [number, number];\n expectedArguments: FormulaFunctionArgument[];\n returnType?: DataType;\n typesMatchFromIndex?: number;\n isreturnTypeFromTypeMatch?: boolean;\n}\n\ninterface ArgumentValidationResult {\n isValid: boolean;\n matchingType?: PossibleDataType;\n invalidReason?: string;\n}\n\nfunction isValidArgument(arg: PossibleDataType, argPos: number, expectedArg: FormulaFunctionArgument): ArgumentValidationResult {\n let isValid: boolean;\n if (arg === \"undefined\") {\n isValid = !!expectedArg.canBeUndefined;\n return { isValid, invalidReason: isValid ? undefined : `Expected ${formatNumericalPositionString(argPos + 1)} argument to not be null.` };\n }\n\n isValid = expectedArg.canBeAny || arg === expectedArg.dataType;\n return { isValid, invalidReason: isValid ? undefined : `Expected ${formatNumericalPositionString(argPos + 1)} argument to be of type ${expectedArg.dataType}.` };\n}\n\nfunction validateArgumentsWithTypeMatching(): (arg: PossibleDataType, argPos: number, expectedArg: FormulaFunctionArgument, shouldTypeMatch: boolean) => ArgumentValidationResult {\n let matchType: PossibleDataType = \"undefined\";\n return (arg: PossibleDataType, argPos: number, expectedArg: FormulaFunctionArgument, shouldMatchType: boolean) => {\n if (shouldMatchType && matchType === \"undefined\")\n matchType = arg;\n\n const validation = isValidArgument(arg, argPos, expectedArg);\n if (!validation.isValid)\n return validation;\n\n const isValid = (matchType === \"undefined\" || arg === matchType || (arg === \"undefined\" && !!expectedArg.canBeUndefined));\n if (matchType !== \"undefined\" && !isValid)\n return {\n isValid,\n matchingType: matchType,\n invalidReason: `Expected ${formatNumericalPositionString(argPos + 1)} argument to be of type ${matchType}.`,\n };\n\n return {\n isValid,\n matchingType: matchType,\n invalidReason: isValid ? undefined : `${formatNumericalPositionString(argPos + 1)} argument is invalid.`,\n };\n };\n}\n\nexport function getFormulaFunctionReturnType(func: FormulaFunction, args: PossibleDataType[]): IResult<PossibleDataType> {\n const hasUnlimitedArguments = func.argumentCountBounds[1] === -1;\n if (args.length < func.argumentCountBounds[0])\n return { errorMessage: `Too few arguments received. Expected a minimum of ${func.argumentCountBounds[0]} argument(s)` };\n if (!hasUnlimitedArguments && args.length > func.argumentCountBounds[1])\n return { errorMessage: `Too many arguments received. Expected a maximum of ${func.argumentCountBounds[1]} argument(s)` };\n\n let returnType: PossibleDataType = func.returnType ?? \"undefined\";\n const validationFunc = func.typesMatchFromIndex === undefined ? isValidArgument : validateArgumentsWithTypeMatching();\n\n for (let i = 0; i < args.length; i++) {\n const shouldTypeMatch = func.typesMatchFromIndex !== undefined && i >= func.typesMatchFromIndex;\n const expectedTypeIndex = hasUnlimitedArguments && i > func.argumentCountBounds[0] - 1 ? func.argumentCountBounds[0] - 1 : i;\n const expectedArg = func.expectedArguments[expectedTypeIndex];\n const validationResult = validationFunc(args[i], i, expectedArg, shouldTypeMatch);\n if (!validationResult.isValid)\n return { errorMessage: validationResult.invalidReason };\n\n if (func.isreturnTypeFromTypeMatch && shouldTypeMatch)\n returnType = validationResult.matchingType ?? \"undefined\";\n }\n\n return { value: returnType };\n}\n\nfunction getNumericalFunction(name: string): FormulaFunction | undefined {\n switch (name) {\n case \"abs\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"acos\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"acosh\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"asin\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"asinh\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"atan\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"atanh\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"atan2\": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: \"number\" }, { dataType: \"number\" }], returnType: \"number\" };\n case \"cbrt\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"ceil\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"clz32\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"cos\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"cosh\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"exp\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"expm1\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"floor\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"fround\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"hypot\": return { argumentCountBounds: [2, -1], expectedArguments: [{ dataType: \"number\" }, { dataType: \"number\" }], returnType: \"number\" };\n case \"imul\": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: \"number\" }, { dataType: \"number\" }], returnType: \"number\" };\n case \"log\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"log1p\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"log10\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"log2\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"max\": return { argumentCountBounds: [2, -1], expectedArguments: [{ dataType: \"number\" }, { dataType: \"number\" }], returnType: \"number\" };\n case \"min\": return { argumentCountBounds: [2, -1], expectedArguments: [{ dataType: \"number\" }, { dataType: \"number\" }], returnType: \"number\" };\n case \"pow\": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: \"number\" }, { dataType: \"number\" }], returnType: \"number\" };\n case \"random\": return { argumentCountBounds: [0, 0], expectedArguments: [], returnType: \"number\" };\n case \"round\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"sign\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"sin\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"sinh\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"sqrt\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"tan\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"tanh\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n case \"trunc\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"number\" }], returnType: \"number\" };\n default: return undefined;\n }\n}\n\nfunction getStringFunction(name: string): FormulaFunction | undefined {\n switch (name) {\n case \"charat\": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: \"string\" }, { dataType: \"number\" }], returnType: \"string\" };\n case \"concat\": return { argumentCountBounds: [2, -1], expectedArguments: [{ dataType: \"string\" }, { dataType: \"string\" }], returnType: \"string\" };\n case \"padend\": return { argumentCountBounds: [2, 3], expectedArguments: [{ dataType: \"string\" }, { dataType: \"number\" }, { dataType: \"string\" }], returnType: \"string\" };\n case \"padstart\": return { argumentCountBounds: [2, 3], expectedArguments: [{ dataType: \"string\" }, { dataType: \"number\" }, { dataType: \"string\" }], returnType: \"string\" };\n case \"substring\": return { argumentCountBounds: [2, 3], expectedArguments: [{ dataType: \"string\" }, { dataType: \"number\" }, { dataType: \"number\" }], returnType: \"string\" };\n case \"tolowercase\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"string\" }], returnType: \"string\" };\n case \"touppercase\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"string\" }], returnType: \"string\" };\n case \"trim\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"string\" }], returnType: \"string\" };\n case \"trimend\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"string\" }], returnType: \"string\" };\n case \"trimstart\": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: \"string\" }], returnType: \"string\" };\n default: return undefined;\n }\n}\n\nfunction getConditionalFunction(name: string): FormulaFunction | undefined {\n switch (name) {\n case \"if\": return { argumentCountBounds: [3, 3], expectedArguments: [{ dataType: \"boolean\" }, { canBeAny: true, canBeUndefined: true }, { canBeAny: true, canBeUndefined: true }], typesMatchFromIndex: 1, isreturnTypeFromTypeMatch: true };\n case \"ifnull\": return { argumentCountBounds: [2, 2], expectedArguments: [{ canBeAny: true, canBeUndefined: true }, { canBeAny: true }], typesMatchFromIndex: 0, isreturnTypeFromTypeMatch: true };\n case \"ifnotnull\": return { argumentCountBounds: [2, 2], expectedArguments: [{ canBeAny: true, canBeUndefined: true }, { canBeAny: true }], typesMatchFromIndex: 0, isreturnTypeFromTypeMatch: true };\n case \"ifempty\": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: \"string\" }, { dataType: \"string\" }], returnType: \"string\" };\n case \"ifnotempty\": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: \"string\" }, { dataType: \"string\" }], returnType: \"string\" };\n case \"ifnullorempty\": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: \"string\", canBeUndefined: true }, { dataType: \"string\" }], returnType: \"string\" };\n case \"ifnotnullorempty\": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: \"string\", canBeUndefined: true }, { dataType: \"string\" }], returnType: \"string\" };\n case \"ifnullorwhitespace\": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: \"string\", canBeUndefined: true }, { dataType: \"string\" }], returnType: \"string\" };\n case \"ifnotnullorwhitespace\": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: \"string\", canBeUndefined: true }, { dataType: \"string\" }], returnType: \"string\" };\n default: return undefined;\n }\n}\n\nexport function getFunction(name: string): FormulaFunction | undefined {\n const nameLowerCase = name.toLowerCase();\n return getNumericalFunction(nameLowerCase) || getStringFunction(nameLowerCase) || getConditionalFunction(nameLowerCase);\n}\n\nexport function isFunction(name: string): boolean {\n return !!getFunction(name);\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { IResult } from "./IResult";
|
|
2
|
+
import type { DataType, PossibleDataType } from "./Types";
|
|
3
|
+
export declare enum OperatorType {
|
|
4
|
+
UnaryPlus = 0,
|
|
5
|
+
UnaryNegation = 1,
|
|
6
|
+
Exponentiation = 2,
|
|
7
|
+
Multiplication = 3,
|
|
8
|
+
Division = 4,
|
|
9
|
+
Remainder = 5,
|
|
10
|
+
Addition = 6,
|
|
11
|
+
Subtraction = 7,
|
|
12
|
+
LogicalNot = 8,
|
|
13
|
+
LessThan = 9,
|
|
14
|
+
LessThanOrEqual = 10,
|
|
15
|
+
GreaterThan = 11,
|
|
16
|
+
GreaterThanOrEqual = 12,
|
|
17
|
+
Equality = 13,
|
|
18
|
+
Inequality = 14,
|
|
19
|
+
LogicalAnd = 15,
|
|
20
|
+
LogicalOr = 16
|
|
21
|
+
}
|
|
22
|
+
export declare enum OperatorAssociativity {
|
|
23
|
+
Left = 0,
|
|
24
|
+
Right = 1
|
|
25
|
+
}
|
|
26
|
+
export declare function isOperator(token: string): boolean;
|
|
27
|
+
export declare function getBinaryOperator(token: string): OperatorType | undefined;
|
|
28
|
+
export declare function getUnaryOperator(token: string): OperatorType | undefined;
|
|
29
|
+
export declare function getOperatorPrecedence(op: OperatorType | undefined): number;
|
|
30
|
+
export declare function getOperatorAssociativity(op: OperatorType | undefined): number;
|
|
31
|
+
export declare function isSupportedOperator(token: string): boolean;
|
|
32
|
+
export declare function getOperatorArgumentCountBounds(token: string): [number, number] | undefined;
|
|
33
|
+
export declare function getOperatorReturnType(token: string, arg1: PossibleDataType, arg2?: PossibleDataType): IResult<DataType>;
|
|
34
|
+
//# sourceMappingURL=FormulaOperatorsProvider.d.ts.map
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
const allOperators = ["+", "-", "*", "%", "**", "/", "`", "~", "!", "@", "#", "$", "^", "&", "=", "[", "]", "{", "}", "\\", "|", ";", ":", "'", "\"", "<", ">", "?", "+=", "-=", "*=", "/=", "%=", "&=", "^=", "|=", "?=", "==", "!=", ">=", "<=", "++", "--", "<<", ">>", "&&", "||", "??", "?.", "**=", "<<=", ">>=", "&&=", "||=", "??=", "===", "!==", ">>>", ">>>="];
|
|
2
|
+
export var OperatorType;
|
|
3
|
+
(function (OperatorType) {
|
|
4
|
+
OperatorType[OperatorType["UnaryPlus"] = 0] = "UnaryPlus";
|
|
5
|
+
OperatorType[OperatorType["UnaryNegation"] = 1] = "UnaryNegation";
|
|
6
|
+
OperatorType[OperatorType["Exponentiation"] = 2] = "Exponentiation";
|
|
7
|
+
OperatorType[OperatorType["Multiplication"] = 3] = "Multiplication";
|
|
8
|
+
OperatorType[OperatorType["Division"] = 4] = "Division";
|
|
9
|
+
OperatorType[OperatorType["Remainder"] = 5] = "Remainder";
|
|
10
|
+
OperatorType[OperatorType["Addition"] = 6] = "Addition";
|
|
11
|
+
OperatorType[OperatorType["Subtraction"] = 7] = "Subtraction";
|
|
12
|
+
OperatorType[OperatorType["LogicalNot"] = 8] = "LogicalNot";
|
|
13
|
+
OperatorType[OperatorType["LessThan"] = 9] = "LessThan";
|
|
14
|
+
OperatorType[OperatorType["LessThanOrEqual"] = 10] = "LessThanOrEqual";
|
|
15
|
+
OperatorType[OperatorType["GreaterThan"] = 11] = "GreaterThan";
|
|
16
|
+
OperatorType[OperatorType["GreaterThanOrEqual"] = 12] = "GreaterThanOrEqual";
|
|
17
|
+
OperatorType[OperatorType["Equality"] = 13] = "Equality";
|
|
18
|
+
OperatorType[OperatorType["Inequality"] = 14] = "Inequality";
|
|
19
|
+
OperatorType[OperatorType["LogicalAnd"] = 15] = "LogicalAnd";
|
|
20
|
+
OperatorType[OperatorType["LogicalOr"] = 16] = "LogicalOr";
|
|
21
|
+
})(OperatorType || (OperatorType = {}));
|
|
22
|
+
export var OperatorAssociativity;
|
|
23
|
+
(function (OperatorAssociativity) {
|
|
24
|
+
OperatorAssociativity[OperatorAssociativity["Left"] = 0] = "Left";
|
|
25
|
+
OperatorAssociativity[OperatorAssociativity["Right"] = 1] = "Right";
|
|
26
|
+
})(OperatorAssociativity || (OperatorAssociativity = {}));
|
|
27
|
+
export function isOperator(token) {
|
|
28
|
+
return allOperators.includes(token);
|
|
29
|
+
}
|
|
30
|
+
export function getBinaryOperator(token) {
|
|
31
|
+
switch (token) {
|
|
32
|
+
case "**": return OperatorType.Exponentiation;
|
|
33
|
+
case "*": return OperatorType.Multiplication;
|
|
34
|
+
case "/": return OperatorType.Division;
|
|
35
|
+
case "%": return OperatorType.Remainder;
|
|
36
|
+
case "+": return OperatorType.Addition;
|
|
37
|
+
case "-": return OperatorType.Subtraction;
|
|
38
|
+
case "<": return OperatorType.LessThan;
|
|
39
|
+
case "<=": return OperatorType.LessThanOrEqual;
|
|
40
|
+
case ">": return OperatorType.GreaterThan;
|
|
41
|
+
case ">=": return OperatorType.GreaterThanOrEqual;
|
|
42
|
+
case "==": return OperatorType.Equality;
|
|
43
|
+
case "!=": return OperatorType.Inequality;
|
|
44
|
+
case "&&": return OperatorType.LogicalAnd;
|
|
45
|
+
case "||": return OperatorType.LogicalOr;
|
|
46
|
+
default: return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export function getUnaryOperator(token) {
|
|
50
|
+
switch (token) {
|
|
51
|
+
case "+": return OperatorType.UnaryPlus;
|
|
52
|
+
case "-": return OperatorType.UnaryNegation;
|
|
53
|
+
case "!": return OperatorType.LogicalNot;
|
|
54
|
+
default: return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
|
|
58
|
+
export function getOperatorPrecedence(op) {
|
|
59
|
+
switch (op) {
|
|
60
|
+
case OperatorType.UnaryPlus:
|
|
61
|
+
case OperatorType.UnaryNegation:
|
|
62
|
+
case OperatorType.LogicalNot:
|
|
63
|
+
return 15;
|
|
64
|
+
case OperatorType.Exponentiation:
|
|
65
|
+
return 14;
|
|
66
|
+
case OperatorType.Multiplication:
|
|
67
|
+
case OperatorType.Division:
|
|
68
|
+
case OperatorType.Remainder:
|
|
69
|
+
return 13;
|
|
70
|
+
case OperatorType.Subtraction:
|
|
71
|
+
case OperatorType.Addition:
|
|
72
|
+
return 12;
|
|
73
|
+
case OperatorType.LessThan:
|
|
74
|
+
case OperatorType.LessThanOrEqual:
|
|
75
|
+
case OperatorType.GreaterThan:
|
|
76
|
+
case OperatorType.GreaterThanOrEqual:
|
|
77
|
+
return 10;
|
|
78
|
+
case OperatorType.Equality:
|
|
79
|
+
case OperatorType.Inequality:
|
|
80
|
+
return 9;
|
|
81
|
+
case OperatorType.LogicalAnd:
|
|
82
|
+
return 5;
|
|
83
|
+
case OperatorType.LogicalOr:
|
|
84
|
+
return 4;
|
|
85
|
+
default: return 1;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export function getOperatorAssociativity(op) {
|
|
89
|
+
switch (op) {
|
|
90
|
+
case OperatorType.UnaryPlus:
|
|
91
|
+
case OperatorType.UnaryNegation:
|
|
92
|
+
case OperatorType.Exponentiation:
|
|
93
|
+
case OperatorType.LogicalNot:
|
|
94
|
+
return OperatorAssociativity.Right;
|
|
95
|
+
case OperatorType.Multiplication:
|
|
96
|
+
case OperatorType.Division:
|
|
97
|
+
case OperatorType.Remainder:
|
|
98
|
+
case OperatorType.Addition:
|
|
99
|
+
case OperatorType.Subtraction:
|
|
100
|
+
case OperatorType.LessThan:
|
|
101
|
+
case OperatorType.LessThanOrEqual:
|
|
102
|
+
case OperatorType.GreaterThan:
|
|
103
|
+
case OperatorType.GreaterThanOrEqual:
|
|
104
|
+
case OperatorType.Equality:
|
|
105
|
+
case OperatorType.Inequality:
|
|
106
|
+
case OperatorType.LogicalAnd:
|
|
107
|
+
case OperatorType.LogicalOr:
|
|
108
|
+
return OperatorAssociativity.Left;
|
|
109
|
+
default:
|
|
110
|
+
return OperatorAssociativity.Left;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export function isSupportedOperator(token) {
|
|
114
|
+
return undefined !== getUnaryOperator(token) || undefined !== getBinaryOperator(token);
|
|
115
|
+
}
|
|
116
|
+
export function getOperatorArgumentCountBounds(token) {
|
|
117
|
+
switch (token) {
|
|
118
|
+
case "**": return [2, 2];
|
|
119
|
+
case "*": return [2, 2];
|
|
120
|
+
case "/": return [2, 2];
|
|
121
|
+
case "%": return [2, 2];
|
|
122
|
+
case "+": return [1, 2];
|
|
123
|
+
case "-": return [1, 2];
|
|
124
|
+
case "!": return [1, 1];
|
|
125
|
+
case "<": return [2, 2];
|
|
126
|
+
case "<=": return [2, 2];
|
|
127
|
+
case ">": return [2, 2];
|
|
128
|
+
case ">=": return [2, 2];
|
|
129
|
+
case "==": return [2, 2];
|
|
130
|
+
case "!=": return [2, 2];
|
|
131
|
+
case "&&": return [2, 2];
|
|
132
|
+
case "||": return [2, 2];
|
|
133
|
+
default: return undefined;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export function getOperatorReturnType(token, arg1, arg2) {
|
|
137
|
+
if (!arg2 && !getUnaryOperator(token))
|
|
138
|
+
return { errorMessage: `Unary operator "${token}" is not supported.` };
|
|
139
|
+
if (arg2 && !getBinaryOperator(token))
|
|
140
|
+
return { errorMessage: `Binary operator "${token}" is not supported.` };
|
|
141
|
+
if ((arg1 === "undefined" || arg2 === "undefined") && (token !== "==" && token !== "!="))
|
|
142
|
+
return { errorMessage: `${!arg2 ? "Unary" : "Binary"} operator "${token}" does not support null operands.` };
|
|
143
|
+
switch (token) {
|
|
144
|
+
case "**":
|
|
145
|
+
case "*":
|
|
146
|
+
case "/":
|
|
147
|
+
case "%":
|
|
148
|
+
return arg1 === "string" || arg2 === "string" ?
|
|
149
|
+
{ errorMessage: `Binary operator "${token}" does not support string operands.` } :
|
|
150
|
+
{ value: "number" };
|
|
151
|
+
case "-":
|
|
152
|
+
return arg1 === "string" || arg2 === "string" ?
|
|
153
|
+
{ errorMessage: `${!arg2 ? "Unary" : "Binary"} operator "${token}" does not support string operands.` } :
|
|
154
|
+
{ value: "number" };
|
|
155
|
+
case "+":
|
|
156
|
+
if (!arg2)
|
|
157
|
+
return { value: arg1 };
|
|
158
|
+
else
|
|
159
|
+
return arg1 === "string" || arg2 === "string" ? { value: "string" } : { value: "number" };
|
|
160
|
+
case "!":
|
|
161
|
+
case "<":
|
|
162
|
+
case "<=":
|
|
163
|
+
case ">":
|
|
164
|
+
case ">=":
|
|
165
|
+
case "==":
|
|
166
|
+
case "!=":
|
|
167
|
+
case "&&":
|
|
168
|
+
case "||":
|
|
169
|
+
return { value: "boolean" };
|
|
170
|
+
default:
|
|
171
|
+
return { errorMessage: `Operator "${token}" is not supported.` };
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=FormulaOperatorsProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormulaOperatorsProvider.js","sourceRoot":"","sources":["../../../src/formula/FormulaOperatorsProvider.ts"],"names":[],"mappings":"AAOA,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAE1W,MAAM,CAAN,IAAY,YAkBX;AAlBD,WAAY,YAAY;IACtB,yDAAS,CAAA;IACT,iEAAa,CAAA;IACb,mEAAc,CAAA;IACd,mEAAc,CAAA;IACd,uDAAQ,CAAA;IACR,yDAAS,CAA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AAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;QAC9F,KAAK,GAAG,CAAC;QACT,KAAK,GAAG,CAAC;QACT,KAAK,IAAI,CAAC;QACV,KAAK,GAAG,CAAC;QACT,KAAK,IAAI,CAAC;QACV,KAAK,IAAI,CAAC;QACV,KAAK,IAAI,CAAC;QACV,KAAK,IAAI,CAAC;QACV,KAAK,IAAI;YACP,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;QAC9B;YACE,OAAO,EAAE,YAAY,EAAE,aAAa,KAAK,qBAAqB,EAAE,CAAC;KACpE;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport type { IResult } from \"./IResult\";\nimport type { DataType, PossibleDataType } from \"./Types\";\n\nconst allOperators = [\"+\", \"-\", \"*\", \"%\", \"**\", \"/\", \"`\", \"~\", \"!\", \"@\", \"#\", \"$\", \"^\", \"&\", \"=\", \"[\", \"]\", \"{\", \"}\", \"\\\\\", \"|\", \";\", \":\", \"'\", \"\\\"\", \"<\", \">\", \"?\", \"+=\", \"-=\", \"*=\", \"/=\", \"%=\", \"&=\", \"^=\", \"|=\", \"?=\", \"==\", \"!=\", \">=\", \"<=\", \"++\", \"--\", \"<<\", \">>\", \"&&\", \"||\", \"??\", \"?.\", \"**=\", \"<<=\", \">>=\", \"&&=\", \"||=\", \"??=\", \"===\", \"!==\", \">>>\", \">>>=\"];\n\nexport enum OperatorType {\n UnaryPlus,\n UnaryNegation,\n Exponentiation,\n Multiplication,\n Division,\n Remainder,\n Addition,\n Subtraction,\n LogicalNot,\n LessThan,\n LessThanOrEqual,\n GreaterThan,\n GreaterThanOrEqual,\n Equality,\n Inequality,\n LogicalAnd,\n LogicalOr,\n}\n\nexport enum OperatorAssociativity {\n Left,\n Right,\n}\n\nexport function isOperator(token: string): boolean {\n return allOperators.includes(token);\n}\n\nexport function getBinaryOperator(token: string): OperatorType | undefined {\n switch (token) {\n case \"**\": return OperatorType.Exponentiation;\n case \"*\": return OperatorType.Multiplication;\n case \"/\": return OperatorType.Division;\n case \"%\": return OperatorType.Remainder;\n case \"+\": return OperatorType.Addition;\n case \"-\": return OperatorType.Subtraction;\n case \"<\": return OperatorType.LessThan;\n case \"<=\": return OperatorType.LessThanOrEqual;\n case \">\": return OperatorType.GreaterThan;\n case \">=\": return OperatorType.GreaterThanOrEqual;\n case \"==\": return OperatorType.Equality;\n case \"!=\": return OperatorType.Inequality;\n case \"&&\": return OperatorType.LogicalAnd;\n case \"||\": return OperatorType.LogicalOr;\n default: return undefined;\n }\n}\n\nexport function getUnaryOperator(token: string): OperatorType | undefined {\n switch (token) {\n case \"+\": return OperatorType.UnaryPlus;\n case \"-\": return OperatorType.UnaryNegation;\n case \"!\": return OperatorType.LogicalNot;\n default: return undefined;\n }\n}\n\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence\nexport function getOperatorPrecedence(op: OperatorType | undefined): number {\n switch (op) {\n case OperatorType.UnaryPlus:\n case OperatorType.UnaryNegation:\n case OperatorType.LogicalNot:\n return 15;\n case OperatorType.Exponentiation:\n return 14;\n case OperatorType.Multiplication:\n case OperatorType.Division:\n case OperatorType.Remainder:\n return 13;\n case OperatorType.Subtraction:\n case OperatorType.Addition:\n return 12;\n case OperatorType.LessThan:\n case OperatorType.LessThanOrEqual:\n case OperatorType.GreaterThan:\n case OperatorType.GreaterThanOrEqual:\n return 10;\n case OperatorType.Equality:\n case OperatorType.Inequality:\n return 9;\n case OperatorType.LogicalAnd:\n return 5;\n case OperatorType.LogicalOr:\n return 4;\n default: return 1;\n }\n}\n\nexport function getOperatorAssociativity(op: OperatorType | undefined): number {\n switch (op) {\n case OperatorType.UnaryPlus:\n case OperatorType.UnaryNegation:\n case OperatorType.Exponentiation:\n case OperatorType.LogicalNot:\n return OperatorAssociativity.Right;\n case OperatorType.Multiplication:\n case OperatorType.Division:\n case OperatorType.Remainder:\n case OperatorType.Addition:\n case OperatorType.Subtraction:\n case OperatorType.LessThan:\n case OperatorType.LessThanOrEqual:\n case OperatorType.GreaterThan:\n case OperatorType.GreaterThanOrEqual:\n case OperatorType.Equality:\n case OperatorType.Inequality:\n case OperatorType.LogicalAnd:\n case OperatorType.LogicalOr:\n return OperatorAssociativity.Left;\n default:\n return OperatorAssociativity.Left;\n }\n}\n\nexport function isSupportedOperator(token: string): boolean {\n return undefined !== getUnaryOperator(token) || undefined !== getBinaryOperator(token);\n}\n\nexport function getOperatorArgumentCountBounds(token: string): [number, number] | undefined {\n switch (token) {\n case \"**\": return [2, 2];\n case \"*\": return [2, 2];\n case \"/\": return [2, 2];\n case \"%\": return [2, 2];\n case \"+\": return [1, 2];\n case \"-\": return [1, 2];\n case \"!\": return [1, 1];\n case \"<\": return [2, 2];\n case \"<=\": return [2, 2];\n case \">\": return [2, 2];\n case \">=\": return [2, 2];\n case \"==\": return [2, 2];\n case \"!=\": return [2, 2];\n case \"&&\": return [2, 2];\n case \"||\": return [2, 2];\n default: return undefined;\n }\n}\n\nexport function getOperatorReturnType(token: string, arg1: PossibleDataType, arg2?: PossibleDataType): IResult<DataType> {\n if (!arg2 && !getUnaryOperator(token))\n return { errorMessage: `Unary operator \"${token}\" is not supported.` };\n\n if (arg2 && !getBinaryOperator(token))\n return { errorMessage: `Binary operator \"${token}\" is not supported.` };\n\n if ((arg1 === \"undefined\" || arg2 === \"undefined\") && (token !== \"==\" && token !== \"!=\"))\n return { errorMessage: `${!arg2 ? \"Unary\" : \"Binary\"} operator \"${token}\" does not support null operands.` };\n\n switch (token) {\n case \"**\":\n case \"*\":\n case \"/\":\n case \"%\":\n return arg1 === \"string\" || arg2 === \"string\" ?\n { errorMessage: `Binary operator \"${token}\" does not support string operands.` } :\n { value: \"number\" };\n case \"-\":\n return arg1 === \"string\" || arg2 === \"string\" ?\n { errorMessage: `${!arg2 ? \"Unary\" : \"Binary\"} operator \"${token}\" does not support string operands.` } :\n { value: \"number\" };\n case \"+\":\n if (!arg2)\n return { value: arg1 as DataType };\n else\n return arg1 === \"string\" || arg2 === \"string\" ? { value: \"string\" } : { value: \"number\" };\n case \"!\":\n case \"<\":\n case \"<=\":\n case \">\":\n case \">=\":\n case \"==\":\n case \"!=\":\n case \"&&\":\n case \"||\":\n return { value: \"boolean\" };\n default:\n return { errorMessage: `Operator \"${token}\" is not supported.` };\n }\n}\n"]}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { InputStream } from "./InputStream";
|
|
6
|
+
import { StringBuilder } from "./StringBuilder";
|
|
7
|
+
import { isDecimalSeparator, isDigit, isLetterOrUnderscore, isStringDelimiter, isWhitespace } from "./Utils";
|
|
8
|
+
const fourSymbolCombinations = [">>>="];
|
|
9
|
+
const threeSymbolCombinations = ["**=", "<<=", ">>=", "&&=", "||=", "??=", "===", "!==", ">>>"];
|
|
10
|
+
const twoSymbolCombinations = ["+=", "-=", "*=", "/=", "%=", "&=", "^=", "|=", "?=", "==", "!=", ">=", "<=", "++", "--", "**", "<<", ">>", "&&", "||", "??", "?."];
|
|
11
|
+
const oneSymbolCombinations = ["~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "=", "+", "[", "]", "{", "}", "\\", "|", ";", ":", ",", ".", "<", ">", "/", "?"];
|
|
12
|
+
const symbolCombinations = [
|
|
13
|
+
fourSymbolCombinations,
|
|
14
|
+
threeSymbolCombinations,
|
|
15
|
+
twoSymbolCombinations,
|
|
16
|
+
oneSymbolCombinations,
|
|
17
|
+
];
|
|
18
|
+
function parseScientificNotation(stream) {
|
|
19
|
+
const notationBuilder = new StringBuilder();
|
|
20
|
+
const nextChar = stream.next;
|
|
21
|
+
const afterEChar = stream.peek;
|
|
22
|
+
if (isDigit(afterEChar) || afterEChar === "+" || afterEChar === "-") {
|
|
23
|
+
notationBuilder.push(nextChar);
|
|
24
|
+
notationBuilder.push(stream.next);
|
|
25
|
+
while (isDigit(stream.peek)) {
|
|
26
|
+
notationBuilder.push(stream.next);
|
|
27
|
+
}
|
|
28
|
+
if (isDecimalSeparator(stream.peek)) {
|
|
29
|
+
throw new Error("The exponent in scientific notation must be an integer.");
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
stream.undo;
|
|
34
|
+
}
|
|
35
|
+
return notationBuilder.value;
|
|
36
|
+
}
|
|
37
|
+
function parseNumber(stream) {
|
|
38
|
+
const numberBuilder = new StringBuilder(stream.current);
|
|
39
|
+
let hasSeparator = isDecimalSeparator(stream.current);
|
|
40
|
+
while (true) {
|
|
41
|
+
const peekedChar = stream.peek;
|
|
42
|
+
if (peekedChar.toLowerCase() === "e") {
|
|
43
|
+
numberBuilder.push(parseScientificNotation(stream));
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
if (isDecimalSeparator(peekedChar)) {
|
|
47
|
+
if (hasSeparator) {
|
|
48
|
+
throw new Error("A number cannot have multiple decimal separators.");
|
|
49
|
+
}
|
|
50
|
+
hasSeparator = true;
|
|
51
|
+
numberBuilder.push(stream.next);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (isDigit(peekedChar)) {
|
|
55
|
+
numberBuilder.push(stream.next);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return numberBuilder.value;
|
|
62
|
+
}
|
|
63
|
+
function unescape(char) {
|
|
64
|
+
switch (char) {
|
|
65
|
+
case "n": return "\n";
|
|
66
|
+
case "t": return "\t";
|
|
67
|
+
default: return char;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function parseStringLiteral(stream) {
|
|
71
|
+
const stringBuilder = new StringBuilder(stream.current);
|
|
72
|
+
const delimiter = stream.current;
|
|
73
|
+
while (stream.next !== delimiter) {
|
|
74
|
+
if (stream.isEOF) {
|
|
75
|
+
throw new Error(`Missing closing string delimiter (${delimiter}).`);
|
|
76
|
+
}
|
|
77
|
+
stringBuilder.push(stream.current === "\\" ? unescape(stream.next) : stream.current);
|
|
78
|
+
}
|
|
79
|
+
stringBuilder.push(stream.current);
|
|
80
|
+
return stringBuilder.value;
|
|
81
|
+
}
|
|
82
|
+
function parseVariable(stream) {
|
|
83
|
+
const variableBuilder = new StringBuilder(stream.current);
|
|
84
|
+
while (isLetterOrUnderscore(stream.peek) || isDigit(stream.peek)) {
|
|
85
|
+
variableBuilder.push(stream.next);
|
|
86
|
+
}
|
|
87
|
+
if (isDecimalSeparator(stream.peek)) {
|
|
88
|
+
throw new Error("Decimal separator in variable.");
|
|
89
|
+
}
|
|
90
|
+
return variableBuilder.value;
|
|
91
|
+
}
|
|
92
|
+
function parseSymbolCombination(stream) {
|
|
93
|
+
const symbolComboBuilder = new StringBuilder(stream.current);
|
|
94
|
+
while (symbolComboBuilder.length < symbolCombinations.length && oneSymbolCombinations.includes(stream.peek)) {
|
|
95
|
+
symbolComboBuilder.push(stream.next);
|
|
96
|
+
}
|
|
97
|
+
for (let i = symbolCombinations.length - symbolComboBuilder.length; i < symbolCombinations.length - 1; i++) {
|
|
98
|
+
const symbolCombo = symbolComboBuilder.value;
|
|
99
|
+
if (symbolCombinations[i].includes(symbolCombo)) {
|
|
100
|
+
return symbolCombo;
|
|
101
|
+
}
|
|
102
|
+
symbolComboBuilder.pop();
|
|
103
|
+
stream.undo;
|
|
104
|
+
}
|
|
105
|
+
return symbolComboBuilder.value;
|
|
106
|
+
}
|
|
107
|
+
function parseFormula(formula) {
|
|
108
|
+
const tokens = [];
|
|
109
|
+
const stream = new InputStream(formula);
|
|
110
|
+
while (!stream.isEOF) {
|
|
111
|
+
const char = stream.next;
|
|
112
|
+
if (isWhitespace(char)) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (isDigit(char) || isDecimalSeparator(char)) {
|
|
116
|
+
tokens.push(parseNumber(stream));
|
|
117
|
+
}
|
|
118
|
+
else if (isLetterOrUnderscore(char)) {
|
|
119
|
+
tokens.push(parseVariable(stream));
|
|
120
|
+
}
|
|
121
|
+
else if (isStringDelimiter(char)) {
|
|
122
|
+
tokens.push(parseStringLiteral(stream));
|
|
123
|
+
}
|
|
124
|
+
else if (oneSymbolCombinations.includes(char)) {
|
|
125
|
+
tokens.push(parseSymbolCombination(stream));
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
throw new Error(`Unknown symbol received "${char}".`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return tokens;
|
|
132
|
+
}
|
|
133
|
+
export function splitFormula(formula) {
|
|
134
|
+
return parseFormula(formula);
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=FormulaSplitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormulaSplitter.js","sourceRoot":"","sources":["../../../src/formula/FormulaSplitter.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE7G,MAAM,sBAAsB,GAAG,CAAC,MAAM,CAAC,CAAC;AACxC,MAAM,uBAAuB,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAChG,MAAM,qBAAqB,GAAG,CAAC,IAAI,EAAE,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AC,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC;SAC7C;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAI,IAAI,CAAC,CAAC;SACvD;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,OAAO,YAAY,CAAC,OAAO,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { InputStream } from \"./InputStream\";\nimport { StringBuilder } from \"./StringBuilder\";\nimport { isDecimalSeparator, isDigit, isLetterOrUnderscore, isStringDelimiter, isWhitespace } from \"./Utils\";\n\nconst fourSymbolCombinations = [\">>>=\"];\nconst threeSymbolCombinations = [\"**=\", \"<<=\", \">>=\", \"&&=\", \"||=\", \"??=\", \"===\", \"!==\", \">>>\"];\nconst twoSymbolCombinations = [\"+=\", \"-=\", \"*=\", \"/=\", \"%=\", \"&=\", \"^=\", \"|=\", \"?=\", \"==\", \"!=\", \">=\", \"<=\", \"++\", \"--\", \"**\", \"<<\", \">>\", \"&&\", \"||\", \"??\", \"?.\"];\nconst oneSymbolCombinations = [\"~\", \"!\", \"@\", \"#\", \"$\", \"%\", \"^\", \"&\", \"*\", \"(\", \")\", \"-\", \"=\", \"+\", \"[\", \"]\", \"{\", \"}\", \"\\\\\", \"|\", \";\", \":\", \",\", \".\", \"<\", \">\", \"/\", \"?\"];\n\nconst symbolCombinations: string[][] = [\n fourSymbolCombinations,\n threeSymbolCombinations,\n twoSymbolCombinations,\n oneSymbolCombinations,\n];\n\nfunction parseScientificNotation(stream: InputStream) {\n const notationBuilder = new StringBuilder();\n\n const nextChar = stream.next;\n const afterEChar = stream.peek;\n if (isDigit(afterEChar) || afterEChar === \"+\" || afterEChar === \"-\") {\n notationBuilder.push(nextChar);\n notationBuilder.push(stream.next);\n while (isDigit(stream.peek)) {\n notationBuilder.push(stream.next);\n }\n if (isDecimalSeparator(stream.peek)) {\n throw new Error(\"The exponent in scientific notation must be an integer.\");\n }\n } else {\n stream.undo;\n }\n\n return notationBuilder.value;\n}\n\nfunction parseNumber(stream: InputStream): string {\n const numberBuilder = new StringBuilder(stream.current);\n let hasSeparator = isDecimalSeparator(stream.current);\n\n while (true) {\n const peekedChar = stream.peek;\n if (peekedChar.toLowerCase() === \"e\") {\n numberBuilder.push(parseScientificNotation(stream));\n break;\n }\n\n if (isDecimalSeparator(peekedChar)) {\n if (hasSeparator) {\n throw new Error(\"A number cannot have multiple decimal separators.\");\n }\n hasSeparator = true;\n numberBuilder.push(stream.next);\n continue;\n }\n\n if (isDigit(peekedChar)) {\n numberBuilder.push(stream.next);\n } else {\n break;\n }\n }\n\n return numberBuilder.value;\n}\n\nfunction unescape(char: string): string {\n switch (char) {\n case \"n\": return \"\\n\";\n case \"t\": return \"\\t\";\n default: return char;\n }\n}\n\nfunction parseStringLiteral(stream: InputStream): string {\n const stringBuilder = new StringBuilder(stream.current);\n const delimiter = stream.current;\n\n while (stream.next !== delimiter) {\n if (stream.isEOF) {\n throw new Error(`Missing closing string delimiter (${delimiter}).`);\n }\n\n stringBuilder.push(stream.current === \"\\\\\" ? unescape(stream.next) : stream.current);\n }\n\n stringBuilder.push(stream.current);\n return stringBuilder.value;\n}\n\nfunction parseVariable(stream: InputStream): string {\n const variableBuilder = new StringBuilder(stream.current);\n\n while (isLetterOrUnderscore(stream.peek) || isDigit(stream.peek)) {\n variableBuilder.push(stream.next);\n }\n\n if (isDecimalSeparator(stream.peek)) {\n throw new Error(\"Decimal separator in variable.\");\n }\n\n return variableBuilder.value;\n}\n\nfunction parseSymbolCombination(stream: InputStream): string {\n const symbolComboBuilder = new StringBuilder(stream.current);\n while (symbolComboBuilder.length < symbolCombinations.length && oneSymbolCombinations.includes(stream.peek)) {\n symbolComboBuilder.push(stream.next);\n }\n\n for (let i = symbolCombinations.length - symbolComboBuilder.length; i < symbolCombinations.length - 1; i++) {\n const symbolCombo = symbolComboBuilder.value;\n if (symbolCombinations[i].includes(symbolCombo)) {\n return symbolCombo;\n }\n symbolComboBuilder.pop();\n stream.undo;\n }\n\n return symbolComboBuilder.value;\n}\n\nfunction parseFormula(formula: string): string[] {\n const tokens: string[] = [];\n const stream = new InputStream(formula);\n while (!stream.isEOF) {\n const char = stream.next;\n if (isWhitespace(char)) {\n continue;\n }\n\n if (isDigit(char) || isDecimalSeparator(char)) {\n tokens.push(parseNumber(stream));\n } else if (isLetterOrUnderscore(char)) {\n tokens.push(parseVariable(stream));\n } else if (isStringDelimiter(char)) {\n tokens.push(parseStringLiteral(stream));\n } else if (oneSymbolCombinations.includes(char)) {\n tokens.push(parseSymbolCombination(stream));\n } else {\n throw new Error(`Unknown symbol received \"${char}\".`);\n }\n }\n\n return tokens;\n}\n\nexport function splitFormula(formula: string): string[] {\n return parseFormula(formula);\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Token } from "./InfixToPostfixConverter";
|
|
2
|
+
import type { Queue } from "./Queue";
|
|
3
|
+
import type { PropertyMap } from "./Types";
|
|
4
|
+
export declare function validateTokens(tokens: Queue<Token>, properties: PropertyMap): string;
|
|
5
|
+
//# sourceMappingURL=FormulaTokensValidator.d.ts.map
|