@itwin/grouping-mapping-widget 0.3.2 → 0.3.5
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 +137 -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/BlockingOverlay.d.ts +7 -0
- package/lib/cjs/widget/components/BlockingOverlay.js +21 -0
- package/lib/cjs/widget/components/BlockingOverlay.js.map +1 -0
- package/lib/cjs/widget/components/BlockingOverlay.scss +26 -0
- package/lib/cjs/widget/components/CalculatedPropertyAction.d.ts +1 -1
- package/lib/cjs/widget/components/CalculatedPropertyAction.js +4 -5
- 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 +5 -29
- package/lib/cjs/widget/components/CalculatedPropertyTable.js.map +1 -1
- package/lib/cjs/widget/components/ConfirmMappingsImport.js +1 -2
- package/lib/cjs/widget/components/ConfirmMappingsImport.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 +10 -6
- 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 +5 -29
- package/lib/cjs/widget/components/CustomCalculationTable.js.map +1 -1
- package/lib/cjs/widget/components/GroupAction.js +3 -12
- 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 +5 -6
- 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 +5 -29
- package/lib/cjs/widget/components/GroupPropertyTable.js.map +1 -1
- package/lib/cjs/widget/components/Grouping.js +2 -3
- package/lib/cjs/widget/components/Grouping.js.map +1 -1
- package/lib/cjs/widget/components/Mapping.js +26 -5
- package/lib/cjs/widget/components/Mapping.js.map +1 -1
- package/lib/cjs/widget/components/MappingAction.js +10 -13
- 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 +77 -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/SelectMappings.js +1 -2
- package/lib/cjs/widget/components/SelectMappings.js.map +1 -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/components/utils.d.ts +2 -0
- package/lib/cjs/widget/components/utils.js +13 -1
- package/lib/cjs/widget/components/utils.js.map +1 -1
- 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 +133 -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/BlockingOverlay.d.ts +7 -0
- package/lib/esm/widget/components/BlockingOverlay.js +14 -0
- package/lib/esm/widget/components/BlockingOverlay.js.map +1 -0
- package/lib/esm/widget/components/BlockingOverlay.scss +26 -0
- package/lib/esm/widget/components/CalculatedPropertyAction.d.ts +1 -1
- package/lib/esm/widget/components/CalculatedPropertyAction.js +5 -6
- 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 +6 -30
- package/lib/esm/widget/components/CalculatedPropertyTable.js.map +1 -1
- package/lib/esm/widget/components/ConfirmMappingsImport.js +2 -3
- package/lib/esm/widget/components/ConfirmMappingsImport.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 +11 -7
- 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 +6 -30
- package/lib/esm/widget/components/CustomCalculationTable.js.map +1 -1
- package/lib/esm/widget/components/GroupAction.js +4 -13
- 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 +6 -7
- 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 +6 -30
- package/lib/esm/widget/components/GroupPropertyTable.js.map +1 -1
- package/lib/esm/widget/components/Grouping.js +3 -4
- package/lib/esm/widget/components/Grouping.js.map +1 -1
- package/lib/esm/widget/components/Mapping.js +28 -7
- package/lib/esm/widget/components/Mapping.js.map +1 -1
- package/lib/esm/widget/components/MappingAction.js +12 -15
- 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 +79 -23
- 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/SelectMappings.js +2 -3
- package/lib/esm/widget/components/SelectMappings.js.map +1 -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/components/utils.d.ts +2 -0
- package/lib/esm/widget/components/utils.js +11 -0
- package/lib/esm/widget/components/utils.js.map +1 -1
- 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 +3 -3
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { IResult } from "./IResult";
|
|
2
|
+
import type { DataType, PossibleDataType } from "./Types";
|
|
3
|
+
export interface FormulaFunctionArgument {
|
|
4
|
+
dataType?: DataType;
|
|
5
|
+
canBeAny?: boolean;
|
|
6
|
+
canBeUndefined?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface FormulaFunction {
|
|
9
|
+
argumentCountBounds: [number, number];
|
|
10
|
+
expectedArguments: FormulaFunctionArgument[];
|
|
11
|
+
returnType?: DataType;
|
|
12
|
+
typesMatchFromIndex?: number;
|
|
13
|
+
isreturnTypeFromTypeMatch?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function getFormulaFunctionReturnType(func: FormulaFunction, args: PossibleDataType[]): IResult<PossibleDataType>;
|
|
16
|
+
export declare function getFunction(name: string): FormulaFunction | undefined;
|
|
17
|
+
export declare function isFunction(name: string): boolean;
|
|
18
|
+
//# sourceMappingURL=FormulaFunctionProvider.d.ts.map
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFunction = exports.getFunction = exports.getFormulaFunctionReturnType = void 0;
|
|
4
|
+
const Utils_1 = require("./Utils");
|
|
5
|
+
function isValidArgument(arg, argPos, expectedArg) {
|
|
6
|
+
let isValid;
|
|
7
|
+
if (arg === "undefined") {
|
|
8
|
+
isValid = !!expectedArg.canBeUndefined;
|
|
9
|
+
return { isValid, invalidReason: isValid ? undefined : `Expected ${Utils_1.formatNumericalPositionString(argPos + 1)} argument to not be null.` };
|
|
10
|
+
}
|
|
11
|
+
isValid = expectedArg.canBeAny || arg === expectedArg.dataType;
|
|
12
|
+
return { isValid, invalidReason: isValid ? undefined : `Expected ${Utils_1.formatNumericalPositionString(argPos + 1)} argument to be of type ${expectedArg.dataType}.` };
|
|
13
|
+
}
|
|
14
|
+
function validateArgumentsWithTypeMatching() {
|
|
15
|
+
let matchType = "undefined";
|
|
16
|
+
return (arg, argPos, expectedArg, shouldMatchType) => {
|
|
17
|
+
if (shouldMatchType && matchType === "undefined")
|
|
18
|
+
matchType = arg;
|
|
19
|
+
const validation = isValidArgument(arg, argPos, expectedArg);
|
|
20
|
+
if (!validation.isValid)
|
|
21
|
+
return validation;
|
|
22
|
+
const isValid = (matchType === "undefined" || arg === matchType || (arg === "undefined" && !!expectedArg.canBeUndefined));
|
|
23
|
+
if (matchType !== "undefined" && !isValid)
|
|
24
|
+
return {
|
|
25
|
+
isValid,
|
|
26
|
+
matchingType: matchType,
|
|
27
|
+
invalidReason: `Expected ${Utils_1.formatNumericalPositionString(argPos + 1)} argument to be of type ${matchType}.`,
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
isValid,
|
|
31
|
+
matchingType: matchType,
|
|
32
|
+
invalidReason: isValid ? undefined : `${Utils_1.formatNumericalPositionString(argPos + 1)} argument is invalid.`,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function getFormulaFunctionReturnType(func, args) {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const hasUnlimitedArguments = func.argumentCountBounds[1] === -1;
|
|
39
|
+
if (args.length < func.argumentCountBounds[0])
|
|
40
|
+
return { errorMessage: `Too few arguments received. Expected a minimum of ${func.argumentCountBounds[0]} argument(s)` };
|
|
41
|
+
if (!hasUnlimitedArguments && args.length > func.argumentCountBounds[1])
|
|
42
|
+
return { errorMessage: `Too many arguments received. Expected a maximum of ${func.argumentCountBounds[1]} argument(s)` };
|
|
43
|
+
let returnType = (_a = func.returnType) !== null && _a !== void 0 ? _a : "undefined";
|
|
44
|
+
const validationFunc = func.typesMatchFromIndex === undefined ? isValidArgument : validateArgumentsWithTypeMatching();
|
|
45
|
+
for (let i = 0; i < args.length; i++) {
|
|
46
|
+
const shouldTypeMatch = func.typesMatchFromIndex !== undefined && i >= func.typesMatchFromIndex;
|
|
47
|
+
const expectedTypeIndex = hasUnlimitedArguments && i > func.argumentCountBounds[0] - 1 ? func.argumentCountBounds[0] - 1 : i;
|
|
48
|
+
const expectedArg = func.expectedArguments[expectedTypeIndex];
|
|
49
|
+
const validationResult = validationFunc(args[i], i, expectedArg, shouldTypeMatch);
|
|
50
|
+
if (!validationResult.isValid)
|
|
51
|
+
return { errorMessage: validationResult.invalidReason };
|
|
52
|
+
if (func.isreturnTypeFromTypeMatch && shouldTypeMatch)
|
|
53
|
+
returnType = (_b = validationResult.matchingType) !== null && _b !== void 0 ? _b : "undefined";
|
|
54
|
+
}
|
|
55
|
+
return { value: returnType };
|
|
56
|
+
}
|
|
57
|
+
exports.getFormulaFunctionReturnType = getFormulaFunctionReturnType;
|
|
58
|
+
function getNumericalFunction(name) {
|
|
59
|
+
switch (name) {
|
|
60
|
+
case "abs": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
61
|
+
case "acos": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
62
|
+
case "acosh": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
63
|
+
case "asin": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
64
|
+
case "asinh": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
65
|
+
case "atan": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
66
|
+
case "atanh": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
67
|
+
case "atan2": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "number" }, { dataType: "number" }], returnType: "number" };
|
|
68
|
+
case "cbrt": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
69
|
+
case "ceil": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
70
|
+
case "clz32": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
71
|
+
case "cos": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
72
|
+
case "cosh": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
73
|
+
case "exp": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
74
|
+
case "expm1": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
75
|
+
case "floor": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
76
|
+
case "fround": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
77
|
+
case "hypot": return { argumentCountBounds: [2, -1], expectedArguments: [{ dataType: "number" }, { dataType: "number" }], returnType: "number" };
|
|
78
|
+
case "imul": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "number" }, { dataType: "number" }], returnType: "number" };
|
|
79
|
+
case "log": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
80
|
+
case "log1p": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
81
|
+
case "log10": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
82
|
+
case "log2": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
83
|
+
case "max": return { argumentCountBounds: [2, -1], expectedArguments: [{ dataType: "number" }, { dataType: "number" }], returnType: "number" };
|
|
84
|
+
case "min": return { argumentCountBounds: [2, -1], expectedArguments: [{ dataType: "number" }, { dataType: "number" }], returnType: "number" };
|
|
85
|
+
case "pow": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "number" }, { dataType: "number" }], returnType: "number" };
|
|
86
|
+
case "random": return { argumentCountBounds: [0, 0], expectedArguments: [], returnType: "number" };
|
|
87
|
+
case "round": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
88
|
+
case "sign": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
89
|
+
case "sin": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
90
|
+
case "sinh": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
91
|
+
case "sqrt": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
92
|
+
case "tan": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
93
|
+
case "tanh": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
94
|
+
case "trunc": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "number" }], returnType: "number" };
|
|
95
|
+
default: return undefined;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function getStringFunction(name) {
|
|
99
|
+
switch (name) {
|
|
100
|
+
case "charat": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "string" }, { dataType: "number" }], returnType: "string" };
|
|
101
|
+
case "concat": return { argumentCountBounds: [2, -1], expectedArguments: [{ dataType: "string" }, { dataType: "string" }], returnType: "string" };
|
|
102
|
+
case "padend": return { argumentCountBounds: [2, 3], expectedArguments: [{ dataType: "string" }, { dataType: "number" }, { dataType: "string" }], returnType: "string" };
|
|
103
|
+
case "padstart": return { argumentCountBounds: [2, 3], expectedArguments: [{ dataType: "string" }, { dataType: "number" }, { dataType: "string" }], returnType: "string" };
|
|
104
|
+
case "substring": return { argumentCountBounds: [2, 3], expectedArguments: [{ dataType: "string" }, { dataType: "number" }, { dataType: "number" }], returnType: "string" };
|
|
105
|
+
case "tolowercase": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "string" }], returnType: "string" };
|
|
106
|
+
case "touppercase": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "string" }], returnType: "string" };
|
|
107
|
+
case "trim": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "string" }], returnType: "string" };
|
|
108
|
+
case "trimend": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "string" }], returnType: "string" };
|
|
109
|
+
case "trimstart": return { argumentCountBounds: [1, 1], expectedArguments: [{ dataType: "string" }], returnType: "string" };
|
|
110
|
+
default: return undefined;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function getConditionalFunction(name) {
|
|
114
|
+
switch (name) {
|
|
115
|
+
case "if": return { argumentCountBounds: [3, 3], expectedArguments: [{ dataType: "boolean" }, { canBeAny: true, canBeUndefined: true }, { canBeAny: true, canBeUndefined: true }], typesMatchFromIndex: 1, isreturnTypeFromTypeMatch: true };
|
|
116
|
+
case "ifnull": return { argumentCountBounds: [2, 2], expectedArguments: [{ canBeAny: true, canBeUndefined: true }, { canBeAny: true }], typesMatchFromIndex: 0, isreturnTypeFromTypeMatch: true };
|
|
117
|
+
case "ifnotnull": return { argumentCountBounds: [2, 2], expectedArguments: [{ canBeAny: true, canBeUndefined: true }, { canBeAny: true }], typesMatchFromIndex: 0, isreturnTypeFromTypeMatch: true };
|
|
118
|
+
case "ifempty": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "string" }, { dataType: "string" }], returnType: "string" };
|
|
119
|
+
case "ifnotempty": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "string" }, { dataType: "string" }], returnType: "string" };
|
|
120
|
+
case "ifnullorempty": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "string", canBeUndefined: true }, { dataType: "string" }], returnType: "string" };
|
|
121
|
+
case "ifnotnullorempty": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "string", canBeUndefined: true }, { dataType: "string" }], returnType: "string" };
|
|
122
|
+
case "ifnullorwhitespace": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "string", canBeUndefined: true }, { dataType: "string" }], returnType: "string" };
|
|
123
|
+
case "ifnotnullorwhitespace": return { argumentCountBounds: [2, 2], expectedArguments: [{ dataType: "string", canBeUndefined: true }, { dataType: "string" }], returnType: "string" };
|
|
124
|
+
default: return undefined;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function getFunction(name) {
|
|
128
|
+
const nameLowerCase = name.toLowerCase();
|
|
129
|
+
return getNumericalFunction(nameLowerCase) || getStringFunction(nameLowerCase) || getConditionalFunction(nameLowerCase);
|
|
130
|
+
}
|
|
131
|
+
exports.getFunction = getFunction;
|
|
132
|
+
function isFunction(name) {
|
|
133
|
+
return !!getFunction(name);
|
|
134
|
+
}
|
|
135
|
+
exports.isFunction = isFunction;
|
|
136
|
+
//# sourceMappingURL=FormulaFunctionProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormulaFunctionProvider.js","sourceRoot":"","sources":["../../../src/formula/FormulaFunctionProvider.ts"],"names":[],"mappings":";;;AAMA,mCAAwD;AAsBxD,SAAS,eAAe,CAAC,GAAqB,EAAE,MAAc,EAAE,WAAoC;IAClG,IAAI,OAAgB,CAAC;IACrB,IAAI,GAAG,KAAK,WAAW,EAAE;QACvB,OAAO,GAAG,CAAC,CAAC,WAAW,CAAC,cAAc,CAAC;QACvC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,qCAA6B,CAAC,MAAM,GAAG,CAAC,CAAC,2BAA2B,EAAE,CAAC;KAC3I;IAED,OAAO,GAAG,WAAW,CAAC,QAAQ,IAAI,GAAG,KAAK,WAAW,CAAC,QAAQ,CAAC;IAC/D,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,qCAA6B,CAAC,MAAM,GAAG,CAAC,CAAC,2BAA2B,WAAW,CAAC,QAAQ,GAAG,EAAE,CAAC;AACnK,CAAC;AAED,SAAS,iCAA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cAAc,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;QACjL,KAAK,oBAAoB,CAAC,CAAC,OAAO,EAAE,mBAAmB,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;QACnL,KAAK,uBAAuB,CAAC,CAAC,OAAO,EAAE,mBAAmB,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,iBAAiB,EAAE,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;QACtL,OAAO,CAAC,CAAC,OAAO,SAAS,CAAC;KAC3B;AACH,CAAC;AAED,SAAgB,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;AAHD,kCAGC;AAED,SAAgB,UAAU,CAAC,IAAY;IACrC,OAAO,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC;AAFD,gCAEC","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,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOperatorReturnType = exports.getOperatorArgumentCountBounds = exports.isSupportedOperator = exports.getOperatorAssociativity = exports.getOperatorPrecedence = exports.getUnaryOperator = exports.getBinaryOperator = exports.isOperator = exports.OperatorAssociativity = exports.OperatorType = void 0;
|
|
4
|
+
const allOperators = ["+", "-", "*", "%", "**", "/", "`", "~", "!", "@", "#", "$", "^", "&", "=", "[", "]", "{", "}", "\\", "|", ";", ":", "'", "\"", "<", ">", "?", "+=", "-=", "*=", "/=", "%=", "&=", "^=", "|=", "?=", "==", "!=", ">=", "<=", "++", "--", "<<", ">>", "&&", "||", "??", "?.", "**=", "<<=", ">>=", "&&=", "||=", "??=", "===", "!==", ">>>", ">>>="];
|
|
5
|
+
var OperatorType;
|
|
6
|
+
(function (OperatorType) {
|
|
7
|
+
OperatorType[OperatorType["UnaryPlus"] = 0] = "UnaryPlus";
|
|
8
|
+
OperatorType[OperatorType["UnaryNegation"] = 1] = "UnaryNegation";
|
|
9
|
+
OperatorType[OperatorType["Exponentiation"] = 2] = "Exponentiation";
|
|
10
|
+
OperatorType[OperatorType["Multiplication"] = 3] = "Multiplication";
|
|
11
|
+
OperatorType[OperatorType["Division"] = 4] = "Division";
|
|
12
|
+
OperatorType[OperatorType["Remainder"] = 5] = "Remainder";
|
|
13
|
+
OperatorType[OperatorType["Addition"] = 6] = "Addition";
|
|
14
|
+
OperatorType[OperatorType["Subtraction"] = 7] = "Subtraction";
|
|
15
|
+
OperatorType[OperatorType["LogicalNot"] = 8] = "LogicalNot";
|
|
16
|
+
OperatorType[OperatorType["LessThan"] = 9] = "LessThan";
|
|
17
|
+
OperatorType[OperatorType["LessThanOrEqual"] = 10] = "LessThanOrEqual";
|
|
18
|
+
OperatorType[OperatorType["GreaterThan"] = 11] = "GreaterThan";
|
|
19
|
+
OperatorType[OperatorType["GreaterThanOrEqual"] = 12] = "GreaterThanOrEqual";
|
|
20
|
+
OperatorType[OperatorType["Equality"] = 13] = "Equality";
|
|
21
|
+
OperatorType[OperatorType["Inequality"] = 14] = "Inequality";
|
|
22
|
+
OperatorType[OperatorType["LogicalAnd"] = 15] = "LogicalAnd";
|
|
23
|
+
OperatorType[OperatorType["LogicalOr"] = 16] = "LogicalOr";
|
|
24
|
+
})(OperatorType = exports.OperatorType || (exports.OperatorType = {}));
|
|
25
|
+
var OperatorAssociativity;
|
|
26
|
+
(function (OperatorAssociativity) {
|
|
27
|
+
OperatorAssociativity[OperatorAssociativity["Left"] = 0] = "Left";
|
|
28
|
+
OperatorAssociativity[OperatorAssociativity["Right"] = 1] = "Right";
|
|
29
|
+
})(OperatorAssociativity = exports.OperatorAssociativity || (exports.OperatorAssociativity = {}));
|
|
30
|
+
function isOperator(token) {
|
|
31
|
+
return allOperators.includes(token);
|
|
32
|
+
}
|
|
33
|
+
exports.isOperator = isOperator;
|
|
34
|
+
function getBinaryOperator(token) {
|
|
35
|
+
switch (token) {
|
|
36
|
+
case "**": return OperatorType.Exponentiation;
|
|
37
|
+
case "*": return OperatorType.Multiplication;
|
|
38
|
+
case "/": return OperatorType.Division;
|
|
39
|
+
case "%": return OperatorType.Remainder;
|
|
40
|
+
case "+": return OperatorType.Addition;
|
|
41
|
+
case "-": return OperatorType.Subtraction;
|
|
42
|
+
case "<": return OperatorType.LessThan;
|
|
43
|
+
case "<=": return OperatorType.LessThanOrEqual;
|
|
44
|
+
case ">": return OperatorType.GreaterThan;
|
|
45
|
+
case ">=": return OperatorType.GreaterThanOrEqual;
|
|
46
|
+
case "==": return OperatorType.Equality;
|
|
47
|
+
case "!=": return OperatorType.Inequality;
|
|
48
|
+
case "&&": return OperatorType.LogicalAnd;
|
|
49
|
+
case "||": return OperatorType.LogicalOr;
|
|
50
|
+
default: return undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.getBinaryOperator = getBinaryOperator;
|
|
54
|
+
function getUnaryOperator(token) {
|
|
55
|
+
switch (token) {
|
|
56
|
+
case "+": return OperatorType.UnaryPlus;
|
|
57
|
+
case "-": return OperatorType.UnaryNegation;
|
|
58
|
+
case "!": return OperatorType.LogicalNot;
|
|
59
|
+
default: return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.getUnaryOperator = getUnaryOperator;
|
|
63
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
|
|
64
|
+
function getOperatorPrecedence(op) {
|
|
65
|
+
switch (op) {
|
|
66
|
+
case OperatorType.UnaryPlus:
|
|
67
|
+
case OperatorType.UnaryNegation:
|
|
68
|
+
case OperatorType.LogicalNot:
|
|
69
|
+
return 15;
|
|
70
|
+
case OperatorType.Exponentiation:
|
|
71
|
+
return 14;
|
|
72
|
+
case OperatorType.Multiplication:
|
|
73
|
+
case OperatorType.Division:
|
|
74
|
+
case OperatorType.Remainder:
|
|
75
|
+
return 13;
|
|
76
|
+
case OperatorType.Subtraction:
|
|
77
|
+
case OperatorType.Addition:
|
|
78
|
+
return 12;
|
|
79
|
+
case OperatorType.LessThan:
|
|
80
|
+
case OperatorType.LessThanOrEqual:
|
|
81
|
+
case OperatorType.GreaterThan:
|
|
82
|
+
case OperatorType.GreaterThanOrEqual:
|
|
83
|
+
return 10;
|
|
84
|
+
case OperatorType.Equality:
|
|
85
|
+
case OperatorType.Inequality:
|
|
86
|
+
return 9;
|
|
87
|
+
case OperatorType.LogicalAnd:
|
|
88
|
+
return 5;
|
|
89
|
+
case OperatorType.LogicalOr:
|
|
90
|
+
return 4;
|
|
91
|
+
default: return 1;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.getOperatorPrecedence = getOperatorPrecedence;
|
|
95
|
+
function getOperatorAssociativity(op) {
|
|
96
|
+
switch (op) {
|
|
97
|
+
case OperatorType.UnaryPlus:
|
|
98
|
+
case OperatorType.UnaryNegation:
|
|
99
|
+
case OperatorType.Exponentiation:
|
|
100
|
+
case OperatorType.LogicalNot:
|
|
101
|
+
return OperatorAssociativity.Right;
|
|
102
|
+
case OperatorType.Multiplication:
|
|
103
|
+
case OperatorType.Division:
|
|
104
|
+
case OperatorType.Remainder:
|
|
105
|
+
case OperatorType.Addition:
|
|
106
|
+
case OperatorType.Subtraction:
|
|
107
|
+
case OperatorType.LessThan:
|
|
108
|
+
case OperatorType.LessThanOrEqual:
|
|
109
|
+
case OperatorType.GreaterThan:
|
|
110
|
+
case OperatorType.GreaterThanOrEqual:
|
|
111
|
+
case OperatorType.Equality:
|
|
112
|
+
case OperatorType.Inequality:
|
|
113
|
+
case OperatorType.LogicalAnd:
|
|
114
|
+
case OperatorType.LogicalOr:
|
|
115
|
+
return OperatorAssociativity.Left;
|
|
116
|
+
default:
|
|
117
|
+
return OperatorAssociativity.Left;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.getOperatorAssociativity = getOperatorAssociativity;
|
|
121
|
+
function isSupportedOperator(token) {
|
|
122
|
+
return undefined !== getUnaryOperator(token) || undefined !== getBinaryOperator(token);
|
|
123
|
+
}
|
|
124
|
+
exports.isSupportedOperator = isSupportedOperator;
|
|
125
|
+
function getOperatorArgumentCountBounds(token) {
|
|
126
|
+
switch (token) {
|
|
127
|
+
case "**": return [2, 2];
|
|
128
|
+
case "*": return [2, 2];
|
|
129
|
+
case "/": return [2, 2];
|
|
130
|
+
case "%": return [2, 2];
|
|
131
|
+
case "+": return [1, 2];
|
|
132
|
+
case "-": return [1, 2];
|
|
133
|
+
case "!": return [1, 1];
|
|
134
|
+
case "<": return [2, 2];
|
|
135
|
+
case "<=": return [2, 2];
|
|
136
|
+
case ">": return [2, 2];
|
|
137
|
+
case ">=": return [2, 2];
|
|
138
|
+
case "==": return [2, 2];
|
|
139
|
+
case "!=": return [2, 2];
|
|
140
|
+
case "&&": return [2, 2];
|
|
141
|
+
case "||": return [2, 2];
|
|
142
|
+
default: return undefined;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.getOperatorArgumentCountBounds = getOperatorArgumentCountBounds;
|
|
146
|
+
function getOperatorReturnType(token, arg1, arg2) {
|
|
147
|
+
if (!arg2 && !getUnaryOperator(token))
|
|
148
|
+
return { errorMessage: `Unary operator "${token}" is not supported.` };
|
|
149
|
+
if (arg2 && !getBinaryOperator(token))
|
|
150
|
+
return { errorMessage: `Binary operator "${token}" is not supported.` };
|
|
151
|
+
if ((arg1 === "undefined" || arg2 === "undefined") && (token !== "==" && token !== "!="))
|
|
152
|
+
return { errorMessage: `${!arg2 ? "Unary" : "Binary"} operator "${token}" does not support null operands.` };
|
|
153
|
+
switch (token) {
|
|
154
|
+
case "**":
|
|
155
|
+
case "*":
|
|
156
|
+
case "/":
|
|
157
|
+
case "%":
|
|
158
|
+
return arg1 === "string" || arg2 === "string" ?
|
|
159
|
+
{ errorMessage: `Binary operator "${token}" does not support string operands.` } :
|
|
160
|
+
{ value: "number" };
|
|
161
|
+
case "-":
|
|
162
|
+
return arg1 === "string" || arg2 === "string" ?
|
|
163
|
+
{ errorMessage: `${!arg2 ? "Unary" : "Binary"} operator "${token}" does not support string operands.` } :
|
|
164
|
+
{ value: "number" };
|
|
165
|
+
case "+":
|
|
166
|
+
if (!arg2)
|
|
167
|
+
return { value: arg1 };
|
|
168
|
+
else
|
|
169
|
+
return arg1 === "string" || arg2 === "string" ? { value: "string" } : { value: "number" };
|
|
170
|
+
case "!":
|
|
171
|
+
case "<":
|
|
172
|
+
case "<=":
|
|
173
|
+
case ">":
|
|
174
|
+
case ">=":
|
|
175
|
+
case "==":
|
|
176
|
+
case "!=":
|
|
177
|
+
case "&&":
|
|
178
|
+
case "||":
|
|
179
|
+
return { value: "boolean" };
|
|
180
|
+
default:
|
|
181
|
+
return { errorMessage: `Operator "${token}" is not supported.` };
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.getOperatorReturnType = getOperatorReturnType;
|
|
185
|
+
//# 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,IAAY,YAkBX;AAlBD,WAAY,YAAY;IACtB,yDAAS,CAAA;IACT,iEAAa,CAAA;IACb,mEAAc,CAAA;IACd,mEAAc,CAAA;I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AAE,KAAK,EAAE,IAAgB,EAAE,CAAC;;gBAEnC,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,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;AAxCD,sDAwCC","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,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.splitFormula = void 0;
|
|
4
|
+
/*---------------------------------------------------------------------------------------------
|
|
5
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
6
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
7
|
+
*--------------------------------------------------------------------------------------------*/
|
|
8
|
+
const InputStream_1 = require("./InputStream");
|
|
9
|
+
const StringBuilder_1 = require("./StringBuilder");
|
|
10
|
+
const Utils_1 = require("./Utils");
|
|
11
|
+
const fourSymbolCombinations = [">>>="];
|
|
12
|
+
const threeSymbolCombinations = ["**=", "<<=", ">>=", "&&=", "||=", "??=", "===", "!==", ">>>"];
|
|
13
|
+
const twoSymbolCombinations = ["+=", "-=", "*=", "/=", "%=", "&=", "^=", "|=", "?=", "==", "!=", ">=", "<=", "++", "--", "**", "<<", ">>", "&&", "||", "??", "?."];
|
|
14
|
+
const oneSymbolCombinations = ["~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "=", "+", "[", "]", "{", "}", "\\", "|", ";", ":", ",", ".", "<", ">", "/", "?"];
|
|
15
|
+
const symbolCombinations = [
|
|
16
|
+
fourSymbolCombinations,
|
|
17
|
+
threeSymbolCombinations,
|
|
18
|
+
twoSymbolCombinations,
|
|
19
|
+
oneSymbolCombinations,
|
|
20
|
+
];
|
|
21
|
+
function parseScientificNotation(stream) {
|
|
22
|
+
const notationBuilder = new StringBuilder_1.StringBuilder();
|
|
23
|
+
const nextChar = stream.next;
|
|
24
|
+
const afterEChar = stream.peek;
|
|
25
|
+
if (Utils_1.isDigit(afterEChar) || afterEChar === "+" || afterEChar === "-") {
|
|
26
|
+
notationBuilder.push(nextChar);
|
|
27
|
+
notationBuilder.push(stream.next);
|
|
28
|
+
while (Utils_1.isDigit(stream.peek)) {
|
|
29
|
+
notationBuilder.push(stream.next);
|
|
30
|
+
}
|
|
31
|
+
if (Utils_1.isDecimalSeparator(stream.peek)) {
|
|
32
|
+
throw new Error("The exponent in scientific notation must be an integer.");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
stream.undo;
|
|
37
|
+
}
|
|
38
|
+
return notationBuilder.value;
|
|
39
|
+
}
|
|
40
|
+
function parseNumber(stream) {
|
|
41
|
+
const numberBuilder = new StringBuilder_1.StringBuilder(stream.current);
|
|
42
|
+
let hasSeparator = Utils_1.isDecimalSeparator(stream.current);
|
|
43
|
+
while (true) {
|
|
44
|
+
const peekedChar = stream.peek;
|
|
45
|
+
if (peekedChar.toLowerCase() === "e") {
|
|
46
|
+
numberBuilder.push(parseScientificNotation(stream));
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
if (Utils_1.isDecimalSeparator(peekedChar)) {
|
|
50
|
+
if (hasSeparator) {
|
|
51
|
+
throw new Error("A number cannot have multiple decimal separators.");
|
|
52
|
+
}
|
|
53
|
+
hasSeparator = true;
|
|
54
|
+
numberBuilder.push(stream.next);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (Utils_1.isDigit(peekedChar)) {
|
|
58
|
+
numberBuilder.push(stream.next);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return numberBuilder.value;
|
|
65
|
+
}
|
|
66
|
+
function unescape(char) {
|
|
67
|
+
switch (char) {
|
|
68
|
+
case "n": return "\n";
|
|
69
|
+
case "t": return "\t";
|
|
70
|
+
default: return char;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function parseStringLiteral(stream) {
|
|
74
|
+
const stringBuilder = new StringBuilder_1.StringBuilder(stream.current);
|
|
75
|
+
const delimiter = stream.current;
|
|
76
|
+
while (stream.next !== delimiter) {
|
|
77
|
+
if (stream.isEOF) {
|
|
78
|
+
throw new Error(`Missing closing string delimiter (${delimiter}).`);
|
|
79
|
+
}
|
|
80
|
+
stringBuilder.push(stream.current === "\\" ? unescape(stream.next) : stream.current);
|
|
81
|
+
}
|
|
82
|
+
stringBuilder.push(stream.current);
|
|
83
|
+
return stringBuilder.value;
|
|
84
|
+
}
|
|
85
|
+
function parseVariable(stream) {
|
|
86
|
+
const variableBuilder = new StringBuilder_1.StringBuilder(stream.current);
|
|
87
|
+
while (Utils_1.isLetterOrUnderscore(stream.peek) || Utils_1.isDigit(stream.peek)) {
|
|
88
|
+
variableBuilder.push(stream.next);
|
|
89
|
+
}
|
|
90
|
+
if (Utils_1.isDecimalSeparator(stream.peek)) {
|
|
91
|
+
throw new Error("Decimal separator in variable.");
|
|
92
|
+
}
|
|
93
|
+
return variableBuilder.value;
|
|
94
|
+
}
|
|
95
|
+
function parseSymbolCombination(stream) {
|
|
96
|
+
const symbolComboBuilder = new StringBuilder_1.StringBuilder(stream.current);
|
|
97
|
+
while (symbolComboBuilder.length < symbolCombinations.length && oneSymbolCombinations.includes(stream.peek)) {
|
|
98
|
+
symbolComboBuilder.push(stream.next);
|
|
99
|
+
}
|
|
100
|
+
for (let i = symbolCombinations.length - symbolComboBuilder.length; i < symbolCombinations.length - 1; i++) {
|
|
101
|
+
const symbolCombo = symbolComboBuilder.value;
|
|
102
|
+
if (symbolCombinations[i].includes(symbolCombo)) {
|
|
103
|
+
return symbolCombo;
|
|
104
|
+
}
|
|
105
|
+
symbolComboBuilder.pop();
|
|
106
|
+
stream.undo;
|
|
107
|
+
}
|
|
108
|
+
return symbolComboBuilder.value;
|
|
109
|
+
}
|
|
110
|
+
function parseFormula(formula) {
|
|
111
|
+
const tokens = [];
|
|
112
|
+
const stream = new InputStream_1.InputStream(formula);
|
|
113
|
+
while (!stream.isEOF) {
|
|
114
|
+
const char = stream.next;
|
|
115
|
+
if (Utils_1.isWhitespace(char)) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (Utils_1.isDigit(char) || Utils_1.isDecimalSeparator(char)) {
|
|
119
|
+
tokens.push(parseNumber(stream));
|
|
120
|
+
}
|
|
121
|
+
else if (Utils_1.isLetterOrUnderscore(char)) {
|
|
122
|
+
tokens.push(parseVariable(stream));
|
|
123
|
+
}
|
|
124
|
+
else if (Utils_1.isStringDelimiter(char)) {
|
|
125
|
+
tokens.push(parseStringLiteral(stream));
|
|
126
|
+
}
|
|
127
|
+
else if (oneSymbolCombinations.includes(char)) {
|
|
128
|
+
tokens.push(parseSymbolCombination(stream));
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
throw new Error(`Unknown symbol received "${char}".`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return tokens;
|
|
135
|
+
}
|
|
136
|
+
function splitFormula(formula) {
|
|
137
|
+
return parseFormula(formula);
|
|
138
|
+
}
|
|
139
|
+
exports.splitFormula = splitFormula;
|
|
140
|
+
//# sourceMappingURL=FormulaSplitter.js.map
|