math-expression-compiler 4.3.1 → 4.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/dist/index.d.ts +1 -409
- package/dist/index.js +187 -374
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { exhaustiveGuard } from "@esposter/shared";
|
|
2
2
|
import { err, ok } from "neverthrow";
|
|
3
|
-
|
|
3
|
+
// src/models/function/MathExpressionFunctionName.ts
|
|
4
4
|
let MathExpressionFunctionName = /* @__PURE__ */ function(MathExpressionFunctionName) {
|
|
5
5
|
MathExpressionFunctionName["CTranspose"] = "ctranspose";
|
|
6
6
|
MathExpressionFunctionName["Factorial"] = "factorial";
|
|
@@ -8,16 +8,14 @@ let MathExpressionFunctionName = /* @__PURE__ */ function(MathExpressionFunction
|
|
|
8
8
|
MathExpressionFunctionName["UnaryPlus"] = "unaryPlus";
|
|
9
9
|
return MathExpressionFunctionName;
|
|
10
10
|
}({});
|
|
11
|
-
|
|
12
|
-
//#region src/models/function/MathExpressionParameterType.ts
|
|
11
|
+
// src/models/function/MathExpressionParameterType.ts
|
|
13
12
|
let MathExpressionParameterType = /* @__PURE__ */ function(MathExpressionParameterType) {
|
|
14
13
|
MathExpressionParameterType["Any"] = "any";
|
|
15
14
|
MathExpressionParameterType["List"] = "list";
|
|
16
15
|
MathExpressionParameterType["Number"] = "number";
|
|
17
16
|
return MathExpressionParameterType;
|
|
18
17
|
}({});
|
|
19
|
-
|
|
20
|
-
//#region src/models/parser/MathExpressionGrammarRule.ts
|
|
18
|
+
// src/models/parser/MathExpressionGrammarRule.ts
|
|
21
19
|
let MathExpressionGrammarRule = /* @__PURE__ */ function(MathExpressionGrammarRule) {
|
|
22
20
|
MathExpressionGrammarRule["Assignment"] = "Assignment";
|
|
23
21
|
MathExpressionGrammarRule["Binary"] = "Binary";
|
|
@@ -32,8 +30,7 @@ let MathExpressionGrammarRule = /* @__PURE__ */ function(MathExpressionGrammarRu
|
|
|
32
30
|
MathExpressionGrammarRule["Unary"] = "Unary";
|
|
33
31
|
return MathExpressionGrammarRule;
|
|
34
32
|
}({});
|
|
35
|
-
|
|
36
|
-
//#region src/models/parser/MathExpressionTokenType.ts
|
|
33
|
+
// src/models/parser/MathExpressionTokenType.ts
|
|
37
34
|
let MathExpressionTokenType = /* @__PURE__ */ function(MathExpressionTokenType) {
|
|
38
35
|
MathExpressionTokenType["Delimiter"] = "delimiter";
|
|
39
36
|
MathExpressionTokenType["Null"] = "null";
|
|
@@ -42,24 +39,21 @@ let MathExpressionTokenType = /* @__PURE__ */ function(MathExpressionTokenType)
|
|
|
42
39
|
MathExpressionTokenType["Unknown"] = "unknown";
|
|
43
40
|
return MathExpressionTokenType;
|
|
44
41
|
}({});
|
|
45
|
-
|
|
46
|
-
//#region src/models/shared/MathExpressionError.ts
|
|
42
|
+
// src/models/shared/MathExpressionError.ts
|
|
47
43
|
var MathExpressionError = class extends Error {
|
|
48
44
|
constructor(message) {
|
|
49
45
|
super(message);
|
|
50
46
|
this.name = "MathExpressionError";
|
|
51
47
|
}
|
|
52
48
|
};
|
|
53
|
-
|
|
54
|
-
//#region src/models/shared/MathExpressionLogicalOperator.ts
|
|
49
|
+
// src/models/shared/MathExpressionLogicalOperator.ts
|
|
55
50
|
let MathExpressionLogicalOperator = /* @__PURE__ */ function(MathExpressionLogicalOperator) {
|
|
56
51
|
MathExpressionLogicalOperator["And"] = "and";
|
|
57
52
|
MathExpressionLogicalOperator["Nullish"] = "nullish";
|
|
58
53
|
MathExpressionLogicalOperator["Or"] = "or";
|
|
59
54
|
return MathExpressionLogicalOperator;
|
|
60
55
|
}({});
|
|
61
|
-
|
|
62
|
-
//#region src/models/shared/MathExpressionNodeType.ts
|
|
56
|
+
// src/models/shared/MathExpressionNodeType.ts
|
|
63
57
|
let MathExpressionNodeType = /* @__PURE__ */ function(MathExpressionNodeType) {
|
|
64
58
|
MathExpressionNodeType["Assignment"] = "assignment";
|
|
65
59
|
MathExpressionNodeType["Binary"] = "binary";
|
|
@@ -75,8 +69,7 @@ let MathExpressionNodeType = /* @__PURE__ */ function(MathExpressionNodeType) {
|
|
|
75
69
|
MathExpressionNodeType["Unary"] = "unary";
|
|
76
70
|
return MathExpressionNodeType;
|
|
77
71
|
}({});
|
|
78
|
-
|
|
79
|
-
//#region src/services/compiler/MathExpressionBitwiseAbsorptionMap.ts
|
|
72
|
+
// src/services/compiler/MathExpressionBitwiseAbsorptionMap.ts
|
|
80
73
|
const MathExpressionBitwiseAbsorptionMap = {
|
|
81
74
|
bitAnd: {
|
|
82
75
|
absorbs: 0,
|
|
@@ -87,8 +80,7 @@ const MathExpressionBitwiseAbsorptionMap = {
|
|
|
87
80
|
result: -1
|
|
88
81
|
}
|
|
89
82
|
};
|
|
90
|
-
|
|
91
|
-
//#region src/services/compiler/node/compileAssignment.ts
|
|
83
|
+
// src/services/compiler/node/compileAssignment.ts
|
|
92
84
|
const compileAssignment = (node, context) => {
|
|
93
85
|
const slot = context.assignedSlots.get(node.name) ?? 0;
|
|
94
86
|
const compiledValue = context.compile(node.value);
|
|
@@ -101,21 +93,18 @@ const compileAssignment = (node, context) => {
|
|
|
101
93
|
isConstant: false
|
|
102
94
|
};
|
|
103
95
|
};
|
|
104
|
-
|
|
105
|
-
//#region src/services/compiler/constants.ts
|
|
96
|
+
// src/services/compiler/constants.ts
|
|
106
97
|
const NO_VALUES = [];
|
|
107
98
|
const NO_LOCALS = [];
|
|
108
99
|
const ADDITIVE_NAMES = ["add", "subtract"];
|
|
109
|
-
|
|
110
|
-
//#region src/services/compiler/checkIsPercentageExpression.ts
|
|
100
|
+
// src/services/compiler/checkIsPercentageExpression.ts
|
|
111
101
|
const checkIsPercentageExpression = (node) => {
|
|
112
102
|
if (node.type === "percentage") return true;
|
|
113
103
|
if (node.type !== "binary") return false;
|
|
114
104
|
if (!ADDITIVE_NAMES.includes(node.name)) return false;
|
|
115
105
|
return checkIsPercentageExpression(node.left) && checkIsPercentageExpression(node.right);
|
|
116
106
|
};
|
|
117
|
-
|
|
118
|
-
//#region src/services/function/constants.ts
|
|
107
|
+
// src/services/function/constants.ts
|
|
119
108
|
const MATH_EXPRESSION_RELATIVE_TOLERANCE = 1e-12;
|
|
120
109
|
const MATH_EXPRESSION_ABSOLUTE_TOLERANCE = 1e-15;
|
|
121
110
|
const SQRT_PI = Math.sqrt(Math.PI);
|
|
@@ -180,8 +169,7 @@ const EULER_MACLAURIN_COEFFICIENTS = [
|
|
|
180
169
|
-3617 / 0x25e8dffc150000
|
|
181
170
|
];
|
|
182
171
|
const SUMMATION_LIMIT = 10;
|
|
183
|
-
|
|
184
|
-
//#region src/services/function/checkIsNearlyEqual.ts
|
|
172
|
+
// src/services/function/checkIsNearlyEqual.ts
|
|
185
173
|
const checkIsNearlyEqual = (left, right) => {
|
|
186
174
|
if (Number.isNaN(left) || Number.isNaN(right)) return false;
|
|
187
175
|
if (!Number.isFinite(left) || !Number.isFinite(right)) return left === right;
|
|
@@ -189,11 +177,9 @@ const checkIsNearlyEqual = (left, right) => {
|
|
|
189
177
|
const tolerance = Math.max(MATH_EXPRESSION_RELATIVE_TOLERANCE * Math.max(Math.abs(left), Math.abs(right)), MATH_EXPRESSION_ABSOLUTE_TOLERANCE);
|
|
190
178
|
return Math.abs(left - right) <= tolerance;
|
|
191
179
|
};
|
|
192
|
-
|
|
193
|
-
//#region src/services/function/checkIsLarger.ts
|
|
180
|
+
// src/services/function/checkIsLarger.ts
|
|
194
181
|
const checkIsLarger = (left, right) => left > right && !checkIsNearlyEqual(left, right);
|
|
195
|
-
|
|
196
|
-
//#region src/services/function/computeModularPower.ts
|
|
182
|
+
// src/services/function/computeModularPower.ts
|
|
197
183
|
const computeModularPower = (base, exponent, modulus) => {
|
|
198
184
|
let result = 1n;
|
|
199
185
|
let square = base % modulus;
|
|
@@ -205,8 +191,7 @@ const computeModularPower = (base, exponent, modulus) => {
|
|
|
205
191
|
}
|
|
206
192
|
return result;
|
|
207
193
|
};
|
|
208
|
-
|
|
209
|
-
//#region src/services/function/checkIsMillerRabinPassing.ts
|
|
194
|
+
// src/services/function/checkIsMillerRabinPassing.ts
|
|
210
195
|
const checkIsMillerRabinPassing = (candidate, base, oddPart, twos) => {
|
|
211
196
|
const minusOne = candidate - 1n;
|
|
212
197
|
let power = computeModularPower(base, oddPart, candidate);
|
|
@@ -217,8 +202,7 @@ const checkIsMillerRabinPassing = (candidate, base, oddPart, twos) => {
|
|
|
217
202
|
}
|
|
218
203
|
return false;
|
|
219
204
|
};
|
|
220
|
-
|
|
221
|
-
//#region src/services/function/checkIsPrime.ts
|
|
205
|
+
// src/services/function/checkIsPrime.ts
|
|
222
206
|
const checkIsPrime = (value) => {
|
|
223
207
|
if (!Number.isInteger(value) || value < 2 || value > Number.MAX_SAFE_INTEGER) return false;
|
|
224
208
|
const candidate = BigInt(value);
|
|
@@ -234,11 +218,9 @@ const checkIsPrime = (value) => {
|
|
|
234
218
|
}
|
|
235
219
|
return MILLER_RABIN_BASES.every((base) => checkIsMillerRabinPassing(candidate, base, oddPart, twos));
|
|
236
220
|
};
|
|
237
|
-
|
|
238
|
-
//#region src/services/function/checkIsSmaller.ts
|
|
221
|
+
// src/services/function/checkIsSmaller.ts
|
|
239
222
|
const checkIsSmaller = (left, right) => left < right && !checkIsNearlyEqual(left, right);
|
|
240
|
-
|
|
241
|
-
//#region src/services/function/computeBellNumber.ts
|
|
223
|
+
// src/services/function/computeBellNumber.ts
|
|
242
224
|
const computeBellNumber = (index) => {
|
|
243
225
|
if (!Number.isInteger(index) || index < 0) return null;
|
|
244
226
|
let row = [1];
|
|
@@ -250,8 +232,7 @@ const computeBellNumber = (index) => {
|
|
|
250
232
|
}
|
|
251
233
|
return row[0] ?? NaN;
|
|
252
234
|
};
|
|
253
|
-
|
|
254
|
-
//#region src/services/function/computeBernoulliNumber.ts
|
|
235
|
+
// src/services/function/computeBernoulliNumber.ts
|
|
255
236
|
const computeBernoulliNumber = (index) => {
|
|
256
237
|
if (index === 1) return -.5;
|
|
257
238
|
if (index > 1 && index % 2 === 1) return 0;
|
|
@@ -272,14 +253,11 @@ const computeBernoulliNumber = (index) => {
|
|
|
272
253
|
}
|
|
273
254
|
return numbers[index] ?? NaN;
|
|
274
255
|
};
|
|
275
|
-
|
|
276
|
-
//#region src/services/function/computeBitwiseAnd.ts
|
|
256
|
+
// src/services/function/computeBitwiseAnd.ts
|
|
277
257
|
const computeBitwiseAnd = (left, right) => left & right;
|
|
278
|
-
|
|
279
|
-
//#region src/services/function/computeBitwiseOr.ts
|
|
258
|
+
// src/services/function/computeBitwiseOr.ts
|
|
280
259
|
const computeBitwiseOr = (left, right) => left | right;
|
|
281
|
-
|
|
282
|
-
//#region src/services/function/computeCombinations.ts
|
|
260
|
+
// src/services/function/computeCombinations.ts
|
|
283
261
|
const computeCombinations = (available, chosen) => {
|
|
284
262
|
const smaller = Math.min(chosen, available - chosen);
|
|
285
263
|
let result = 1;
|
|
@@ -289,35 +267,29 @@ const computeCombinations = (available, chosen) => {
|
|
|
289
267
|
}
|
|
290
268
|
return Math.round(result);
|
|
291
269
|
};
|
|
292
|
-
|
|
293
|
-
//#region src/services/function/computeCatalan.ts
|
|
270
|
+
// src/services/function/computeCatalan.ts
|
|
294
271
|
const computeCatalan = (index) => {
|
|
295
272
|
if (!Number.isInteger(index) || index < 0) return null;
|
|
296
273
|
return Math.round(computeCombinations(2 * index, index) / (index + 1));
|
|
297
274
|
};
|
|
298
|
-
|
|
299
|
-
//#region src/services/function/computeComparison.ts
|
|
275
|
+
// src/services/function/computeComparison.ts
|
|
300
276
|
const computeComparison = (left, right) => {
|
|
301
277
|
if (checkIsNearlyEqual(left, right)) return 0;
|
|
302
278
|
return left > right ? 1 : -1;
|
|
303
279
|
};
|
|
304
|
-
|
|
305
|
-
//#region src/services/function/computeCompositions.ts
|
|
280
|
+
// src/services/function/computeCompositions.ts
|
|
306
281
|
const computeCompositions = (total, parts) => {
|
|
307
282
|
if (!Number.isInteger(total) || !Number.isInteger(parts) || parts < 1 || parts > total) return null;
|
|
308
283
|
return computeCombinations(total - 1, parts - 1);
|
|
309
284
|
};
|
|
310
|
-
|
|
311
|
-
//#region src/services/function/computeDotProduct.ts
|
|
285
|
+
// src/services/function/computeDotProduct.ts
|
|
312
286
|
const computeDotProduct = (left, right) => {
|
|
313
287
|
if (left.length !== right.length) return null;
|
|
314
288
|
return left.reduce((total, value, index) => total + value * (right[index] ?? NaN), 0);
|
|
315
289
|
};
|
|
316
|
-
|
|
317
|
-
//#region src/services/function/computeSum.ts
|
|
290
|
+
// src/services/function/computeSum.ts
|
|
318
291
|
const computeSum = (values) => values.length === 0 ? 0 : values.reduce((total, value) => total + value);
|
|
319
|
-
|
|
320
|
-
//#region src/services/function/computeCorrelation.ts
|
|
292
|
+
// src/services/function/computeCorrelation.ts
|
|
321
293
|
const computeCorrelation = (left, right) => {
|
|
322
294
|
if (left.length !== right.length) return null;
|
|
323
295
|
const count = left.length;
|
|
@@ -328,21 +300,18 @@ const computeCorrelation = (left, right) => {
|
|
|
328
300
|
const sumRightSquares = computeSum(right.map((value) => value ** 2));
|
|
329
301
|
return (count * sumProducts - sumLeft * sumRight) / Math.sqrt((count * sumLeftSquares - sumLeft ** 2) * (count * sumRightSquares - sumRight ** 2));
|
|
330
302
|
};
|
|
331
|
-
|
|
332
|
-
//#region src/services/function/computeDeterminant.ts
|
|
303
|
+
// src/services/function/computeDeterminant.ts
|
|
333
304
|
const computeDeterminant = (values) => {
|
|
334
305
|
if (values.length === 0) return 1;
|
|
335
306
|
return values.length === 1 ? values[0] ?? null : null;
|
|
336
307
|
};
|
|
337
|
-
|
|
338
|
-
//#region src/services/function/computePointToLine2D.ts
|
|
308
|
+
// src/services/function/computePointToLine2D.ts
|
|
339
309
|
const computePointToLine2D = (point, line) => {
|
|
340
310
|
const [x = NaN, y = NaN] = point;
|
|
341
311
|
const [a = NaN, b = NaN, c = NaN] = line;
|
|
342
312
|
return Math.abs(a * x + b * y + c) / Math.hypot(a, b);
|
|
343
313
|
};
|
|
344
|
-
|
|
345
|
-
//#region src/services/function/computePointToLine3D.ts
|
|
314
|
+
// src/services/function/computePointToLine3D.ts
|
|
346
315
|
const computePointToLine3D = (point, line) => {
|
|
347
316
|
const [x = NaN, y = NaN, z = NaN] = point;
|
|
348
317
|
const [x0 = NaN, y0 = NaN, z0 = NaN, a = NaN, b = NaN, c = NaN] = line;
|
|
@@ -351,8 +320,7 @@ const computePointToLine3D = (point, line) => {
|
|
|
351
320
|
const third = (x0 - x) * b - (y0 - y) * a;
|
|
352
321
|
return Math.hypot(first, second, third) / Math.hypot(a, b, c);
|
|
353
322
|
};
|
|
354
|
-
|
|
355
|
-
//#region src/services/function/computeDistance.ts
|
|
323
|
+
// src/services/function/computeDistance.ts
|
|
356
324
|
const computeDistance = (point, other) => {
|
|
357
325
|
if (point.length === 2 && other.length === 3) return computePointToLine2D(point, other);
|
|
358
326
|
if (point.length === 3 && other.length === 6) return computePointToLine3D(point, other);
|
|
@@ -364,8 +332,7 @@ const computeDistance = (point, other) => {
|
|
|
364
332
|
}
|
|
365
333
|
return Math.sqrt(total);
|
|
366
334
|
};
|
|
367
|
-
|
|
368
|
-
//#region src/services/function/computeErf.ts
|
|
335
|
+
// src/services/function/computeErf.ts
|
|
369
336
|
const SERIES_LIMIT = 3;
|
|
370
337
|
const CONTINUED_FRACTION_DEPTH = 80;
|
|
371
338
|
const computeErf = (value) => {
|
|
@@ -387,22 +354,19 @@ const computeErf = (value) => {
|
|
|
387
354
|
for (let index = CONTINUED_FRACTION_DEPTH; index >= 1; index--) fraction = magnitude + index / 2 / fraction;
|
|
388
355
|
return sign * (1 - Math.exp(-magnitude * magnitude) / SQRT_PI / fraction);
|
|
389
356
|
};
|
|
390
|
-
|
|
391
|
-
//#region src/services/function/computePolynomial.ts
|
|
357
|
+
// src/services/function/computePolynomial.ts
|
|
392
358
|
const computePolynomial = (leading, coefficients, variable) => {
|
|
393
359
|
let polynomial = leading;
|
|
394
360
|
for (const coefficient of coefficients) polynomial = coefficient + polynomial * variable;
|
|
395
361
|
return polynomial;
|
|
396
362
|
};
|
|
397
|
-
|
|
398
|
-
//#region src/services/function/computeInitialGuess.ts
|
|
363
|
+
// src/services/function/computeInitialGuess.ts
|
|
399
364
|
const computeInitialGuess = (value) => {
|
|
400
365
|
const weight = -Math.log((1 - value) * (1 + value));
|
|
401
366
|
if (weight < 5) return computePolynomial(2.81022636e-8, LOW_TAIL_COEFFICIENTS, weight - 2.5) * value;
|
|
402
367
|
return computePolynomial(-.000200214257, HIGH_TAIL_COEFFICIENTS, Math.sqrt(weight) - 3) * value;
|
|
403
368
|
};
|
|
404
|
-
|
|
405
|
-
//#region src/services/function/computeErfInverse.ts
|
|
369
|
+
// src/services/function/computeErfInverse.ts
|
|
406
370
|
const computeErfInverse = (value) => {
|
|
407
371
|
if (Number.isNaN(value) || value < -1 || value > 1) return NaN;
|
|
408
372
|
if (value === 1) return Number.POSITIVE_INFINITY;
|
|
@@ -414,8 +378,7 @@ const computeErfInverse = (value) => {
|
|
|
414
378
|
}
|
|
415
379
|
return estimate;
|
|
416
380
|
};
|
|
417
|
-
|
|
418
|
-
//#region src/services/function/computeStirlingLogGamma.ts
|
|
381
|
+
// src/services/function/computeStirlingLogGamma.ts
|
|
419
382
|
const computeStirlingLogGamma = (value) => {
|
|
420
383
|
const inverse = 1 / value;
|
|
421
384
|
const squared = inverse * inverse;
|
|
@@ -427,8 +390,7 @@ const computeStirlingLogGamma = (value) => {
|
|
|
427
390
|
}
|
|
428
391
|
return (value - .5) * Math.log(value) - value + .5 * Math.log(2 * Math.PI) + series;
|
|
429
392
|
};
|
|
430
|
-
|
|
431
|
-
//#region src/services/function/computeLogGammaOfPositive.ts
|
|
393
|
+
// src/services/function/computeLogGammaOfPositive.ts
|
|
432
394
|
const computeLogGammaOfPositive = (value) => {
|
|
433
395
|
let shifted = value;
|
|
434
396
|
let product = 1;
|
|
@@ -441,16 +403,14 @@ const computeLogGammaOfPositive = (value) => {
|
|
|
441
403
|
product
|
|
442
404
|
};
|
|
443
405
|
};
|
|
444
|
-
|
|
445
|
-
//#region src/services/function/computeProductOfRange.ts
|
|
406
|
+
// src/services/function/computeProductOfRange.ts
|
|
446
407
|
const computeProductOfRange = (first, last) => {
|
|
447
408
|
if (last < first) return 1;
|
|
448
409
|
if (last === first) return last;
|
|
449
410
|
const middle = Math.floor((first + last) / 2);
|
|
450
411
|
return computeProductOfRange(first, middle) * computeProductOfRange(middle + 1, last);
|
|
451
412
|
};
|
|
452
|
-
|
|
453
|
-
//#region src/services/function/computeGamma.ts
|
|
413
|
+
// src/services/function/computeGamma.ts
|
|
454
414
|
const computeGamma = (value) => {
|
|
455
415
|
if (Number.isNaN(value)) return NaN;
|
|
456
416
|
if (Number.isInteger(value)) {
|
|
@@ -462,14 +422,12 @@ const computeGamma = (value) => {
|
|
|
462
422
|
const { logGamma, product } = computeLogGammaOfPositive(value);
|
|
463
423
|
return Math.exp(logGamma) / product;
|
|
464
424
|
};
|
|
465
|
-
|
|
466
|
-
//#region src/services/function/computeFactorial.ts
|
|
425
|
+
// src/services/function/computeFactorial.ts
|
|
467
426
|
const computeFactorial = (value) => {
|
|
468
427
|
if (value < 0) return null;
|
|
469
428
|
return computeGamma(value + 1);
|
|
470
429
|
};
|
|
471
|
-
|
|
472
|
-
//#region src/services/function/computeHypotenuse.ts
|
|
430
|
+
// src/services/function/computeHypotenuse.ts
|
|
473
431
|
const computeHypotenuse = (values) => {
|
|
474
432
|
let largest = 0;
|
|
475
433
|
let total = 0;
|
|
@@ -486,25 +444,21 @@ const computeHypotenuse = (values) => {
|
|
|
486
444
|
}
|
|
487
445
|
return largest * Math.sqrt(total);
|
|
488
446
|
};
|
|
489
|
-
|
|
490
|
-
//#region src/services/function/computeGreatestCommonDivisor.ts
|
|
447
|
+
// src/services/function/computeGreatestCommonDivisor.ts
|
|
491
448
|
const computeGreatestCommonDivisor = (left, right) => right === 0 ? Math.abs(left) : computeGreatestCommonDivisor(right, left % right);
|
|
492
|
-
|
|
493
|
-
//#region src/services/function/computeIntegerGreatestCommonDivisor.ts
|
|
449
|
+
// src/services/function/computeIntegerGreatestCommonDivisor.ts
|
|
494
450
|
const computeIntegerGreatestCommonDivisor = (values) => {
|
|
495
451
|
if (!values.every((value) => Number.isInteger(value))) return null;
|
|
496
452
|
return values.reduce((total, value) => computeGreatestCommonDivisor(total, value), 0);
|
|
497
453
|
};
|
|
498
|
-
|
|
499
|
-
//#region src/services/function/computeInverseCoth.ts
|
|
454
|
+
// src/services/function/computeInverseCoth.ts
|
|
500
455
|
const computeInverseCoth = (value) => {
|
|
501
456
|
const magnitude = Math.abs(value);
|
|
502
457
|
if (magnitude < 1) return NaN;
|
|
503
458
|
if (magnitude === 1) return value * Number.POSITIVE_INFINITY;
|
|
504
459
|
return Math.sign(value) * .5 * Math.log1p(2 / (magnitude - 1));
|
|
505
460
|
};
|
|
506
|
-
|
|
507
|
-
//#region src/services/function/computeKullbackLeibler.ts
|
|
461
|
+
// src/services/function/computeKullbackLeibler.ts
|
|
508
462
|
const computeKullbackLeibler = (distribution, reference) => {
|
|
509
463
|
if (distribution.length !== reference.length) return null;
|
|
510
464
|
const distributionSum = computeSum(distribution);
|
|
@@ -514,15 +468,13 @@ const computeKullbackLeibler = (distribution, reference) => {
|
|
|
514
468
|
const normalizedReference = reference.map((value) => value / referenceSum);
|
|
515
469
|
return computeSum(normalizedDistribution.map((value, index) => value * Math.log(value / (normalizedReference[index] ?? NaN))));
|
|
516
470
|
};
|
|
517
|
-
|
|
518
|
-
//#region src/services/function/computeLeastCommonMultiple.ts
|
|
471
|
+
// src/services/function/computeLeastCommonMultiple.ts
|
|
519
472
|
const computeLeastCommonMultiple = (left, right) => {
|
|
520
473
|
if (!Number.isInteger(left) || !Number.isInteger(right)) return null;
|
|
521
474
|
const divisor = computeGreatestCommonDivisor(left, right);
|
|
522
475
|
return divisor === 0 ? 0 : Math.abs(left * right / divisor);
|
|
523
476
|
};
|
|
524
|
-
|
|
525
|
-
//#region src/services/function/computeListComparison.ts
|
|
477
|
+
// src/services/function/computeListComparison.ts
|
|
526
478
|
const computeListComparison = (left, right) => {
|
|
527
479
|
for (const [index, value] of left.entries()) {
|
|
528
480
|
const other = right[index];
|
|
@@ -532,11 +484,9 @@ const computeListComparison = (left, right) => {
|
|
|
532
484
|
}
|
|
533
485
|
return left.length < right.length ? -1 : 0;
|
|
534
486
|
};
|
|
535
|
-
|
|
536
|
-
//#region src/services/function/computeLogarithm.ts
|
|
487
|
+
// src/services/function/computeLogarithm.ts
|
|
537
488
|
const computeLogarithm = (value, base) => base === void 0 ? Math.log(value) : Math.log(value) / Math.log(base);
|
|
538
|
-
|
|
539
|
-
//#region src/services/function/computeLogGamma.ts
|
|
489
|
+
// src/services/function/computeLogGamma.ts
|
|
540
490
|
const computeLogGamma = (value) => {
|
|
541
491
|
if (Number.isNaN(value) || value < 0) return NaN;
|
|
542
492
|
if ([0, Number.POSITIVE_INFINITY].includes(value)) return Number.POSITIVE_INFINITY;
|
|
@@ -544,28 +494,23 @@ const computeLogGamma = (value) => {
|
|
|
544
494
|
const { logGamma, product } = computeLogGammaOfPositive(value);
|
|
545
495
|
return logGamma - Math.log(product);
|
|
546
496
|
};
|
|
547
|
-
|
|
548
|
-
//#region src/services/function/computeMean.ts
|
|
497
|
+
// src/services/function/computeMean.ts
|
|
549
498
|
const computeMean = (values) => computeSum(values) / values.length;
|
|
550
|
-
|
|
551
|
-
//#region src/services/function/compareNumbers.ts
|
|
499
|
+
// src/services/function/compareNumbers.ts
|
|
552
500
|
const compareNumbers = (left, right) => left - right;
|
|
553
|
-
|
|
554
|
-
//#region src/services/function/computeMedian.ts
|
|
501
|
+
// src/services/function/computeMedian.ts
|
|
555
502
|
const computeMedian = (values) => {
|
|
556
503
|
const sorted = values.toSorted(compareNumbers);
|
|
557
504
|
const middle = Math.floor(sorted.length / 2);
|
|
558
505
|
if (sorted.length % 2 === 1) return sorted[middle] ?? NaN;
|
|
559
506
|
return ((sorted[middle - 1] ?? NaN) + (sorted[middle] ?? NaN)) / 2;
|
|
560
507
|
};
|
|
561
|
-
|
|
562
|
-
//#region src/services/function/computeMedianAbsoluteDeviation.ts
|
|
508
|
+
// src/services/function/computeMedianAbsoluteDeviation.ts
|
|
563
509
|
const computeMedianAbsoluteDeviation = (values) => {
|
|
564
510
|
const center = computeMedian(values);
|
|
565
511
|
return computeMedian(values.map((value) => Math.abs(value - center)));
|
|
566
512
|
};
|
|
567
|
-
|
|
568
|
-
//#region src/services/function/computeModulo.ts
|
|
513
|
+
// src/services/function/computeModulo.ts
|
|
569
514
|
const computeModulo = (dividend, divisor) => {
|
|
570
515
|
if (divisor === 0) return dividend;
|
|
571
516
|
if (!Number.isFinite(dividend) || !Number.isFinite(divisor)) return NaN;
|
|
@@ -578,8 +523,7 @@ const computeModulo = (dividend, divisor) => {
|
|
|
578
523
|
if (checkIsNearlyEqual(quotient, Math.round(quotient))) return 0;
|
|
579
524
|
return dividend - divisor * Math.floor(quotient);
|
|
580
525
|
};
|
|
581
|
-
|
|
582
|
-
//#region src/services/function/computeModularInverse.ts
|
|
526
|
+
// src/services/function/computeModularInverse.ts
|
|
583
527
|
const computeModularInverse = (value, modulus) => {
|
|
584
528
|
if (!Number.isInteger(value) || !Number.isInteger(modulus) || modulus === 0) return null;
|
|
585
529
|
let remainder = value;
|
|
@@ -595,8 +539,7 @@ const computeModularInverse = (value, modulus) => {
|
|
|
595
539
|
const inverse = computeModulo(remainder < 0 ? -previousCoefficient : previousCoefficient, modulus);
|
|
596
540
|
return inverse < 0 ? inverse + modulus : inverse;
|
|
597
541
|
};
|
|
598
|
-
|
|
599
|
-
//#region src/services/function/computeMultinomial.ts
|
|
542
|
+
// src/services/function/computeMultinomial.ts
|
|
600
543
|
const computeMultinomial = (parts) => {
|
|
601
544
|
if (!parts.every((part) => Number.isInteger(part) && part > 0)) return null;
|
|
602
545
|
let result = 1;
|
|
@@ -607,15 +550,13 @@ const computeMultinomial = (parts) => {
|
|
|
607
550
|
}
|
|
608
551
|
return result;
|
|
609
552
|
};
|
|
610
|
-
|
|
611
|
-
//#region src/services/function/computeNorm.ts
|
|
553
|
+
// src/services/function/computeNorm.ts
|
|
612
554
|
const computeNorm = (values) => {
|
|
613
555
|
if (values.length === 0) return 0;
|
|
614
556
|
if (values.length === 1) return Math.abs(values[0] ?? NaN);
|
|
615
557
|
return Math.sqrt(computeSum(values.map((value) => value * value)));
|
|
616
558
|
};
|
|
617
|
-
|
|
618
|
-
//#region src/services/function/computeNthRoot.ts
|
|
559
|
+
// src/services/function/computeNthRoot.ts
|
|
619
560
|
const computeNthRoot = (value, root) => {
|
|
620
561
|
const isInverse = root < 0;
|
|
621
562
|
const degree = Math.abs(root);
|
|
@@ -629,14 +570,12 @@ const computeNthRoot = (value, root) => {
|
|
|
629
570
|
if (value < 0) result = -result;
|
|
630
571
|
return isInverse ? 1 / result : result;
|
|
631
572
|
};
|
|
632
|
-
|
|
633
|
-
//#region src/services/function/computePartitionSelect.ts
|
|
573
|
+
// src/services/function/computePartitionSelect.ts
|
|
634
574
|
const computePartitionSelect = (values, index) => {
|
|
635
575
|
if (!Number.isInteger(index) || index < 0 || index >= values.length) return null;
|
|
636
576
|
return values.toSorted(compareNumbers)[index] ?? null;
|
|
637
577
|
};
|
|
638
|
-
|
|
639
|
-
//#region src/services/function/computePermutations.ts
|
|
578
|
+
// src/services/function/computePermutations.ts
|
|
640
579
|
const computePermutations = (available, chosen) => {
|
|
641
580
|
if (!Number.isInteger(available) || !Number.isInteger(chosen) || chosen < 0 || chosen > available) return null;
|
|
642
581
|
let result = 1;
|
|
@@ -646,11 +585,9 @@ const computePermutations = (available, chosen) => {
|
|
|
646
585
|
}
|
|
647
586
|
return result;
|
|
648
587
|
};
|
|
649
|
-
|
|
650
|
-
//#region src/services/function/scaleList.ts
|
|
588
|
+
// src/services/function/scaleList.ts
|
|
651
589
|
const scaleList = (list, scalar) => list.map((element) => element * scalar);
|
|
652
|
-
|
|
653
|
-
//#region src/services/function/multiplyPair.ts
|
|
590
|
+
// src/services/function/multiplyPair.ts
|
|
654
591
|
const multiplyPair = (left, right) => {
|
|
655
592
|
if (typeof left === "number" && typeof right === "number") return left * right;
|
|
656
593
|
if (typeof left === "number" && Array.isArray(right)) return scaleList(right, left);
|
|
@@ -658,8 +595,7 @@ const multiplyPair = (left, right) => {
|
|
|
658
595
|
if (Array.isArray(left) && Array.isArray(right)) return computeDotProduct(left, right);
|
|
659
596
|
return null;
|
|
660
597
|
};
|
|
661
|
-
|
|
662
|
-
//#region src/services/function/computeProduct.ts
|
|
598
|
+
// src/services/function/computeProduct.ts
|
|
663
599
|
const computeProduct = (values) => {
|
|
664
600
|
let total = 1;
|
|
665
601
|
for (const value of values) {
|
|
@@ -668,8 +604,7 @@ const computeProduct = (values) => {
|
|
|
668
604
|
}
|
|
669
605
|
return typeof total === "number" ? total : null;
|
|
670
606
|
};
|
|
671
|
-
|
|
672
|
-
//#region src/services/function/computeQuantile.ts
|
|
607
|
+
// src/services/function/computeQuantile.ts
|
|
673
608
|
const computeQuantile = (values, probability, isSorted) => {
|
|
674
609
|
if (values.length === 0 || probability < 0 || probability > 1) return null;
|
|
675
610
|
const ordered = isSorted ? values : values.toSorted(compareNumbers);
|
|
@@ -679,8 +614,7 @@ const computeQuantile = (values, probability, isSorted) => {
|
|
|
679
614
|
const fraction = index % 1;
|
|
680
615
|
return (ordered[integerPart] ?? NaN) * (1 - fraction) + (ordered[integerPart + 1] ?? NaN) * fraction;
|
|
681
616
|
};
|
|
682
|
-
|
|
683
|
-
//#region src/services/function/computeStirlingColumn.ts
|
|
617
|
+
// src/services/function/computeStirlingColumn.ts
|
|
684
618
|
const computeStirlingColumn = (count, parts) => {
|
|
685
619
|
const column = Array.from({ length: parts + 1 }, (_element, index) => index === 0 ? 1 : 0);
|
|
686
620
|
for (let step = 1; step <= count; step++) {
|
|
@@ -689,15 +623,13 @@ const computeStirlingColumn = (count, parts) => {
|
|
|
689
623
|
}
|
|
690
624
|
return column[parts] ?? 0;
|
|
691
625
|
};
|
|
692
|
-
|
|
693
|
-
//#region src/services/function/computeStirlingDiagonal.ts
|
|
626
|
+
// src/services/function/computeStirlingDiagonal.ts
|
|
694
627
|
const computeStirlingDiagonal = (count, index) => {
|
|
695
628
|
const diagonal = Array.from({ length: index + 1 }, (_element, position) => position === 0 ? 1 : 0);
|
|
696
629
|
for (let step = 1; step <= count; step++) for (let position = Math.min(step, index); position >= 1; position--) diagonal[position] = (step - position) * (diagonal[position - 1] ?? 0) + (diagonal[position] ?? 0);
|
|
697
630
|
return diagonal[index] ?? 0;
|
|
698
631
|
};
|
|
699
|
-
|
|
700
|
-
//#region src/services/function/computeStirlingSecondKind.ts
|
|
632
|
+
// src/services/function/computeStirlingSecondKind.ts
|
|
701
633
|
const computeStirlingSecondKind = (count, parts) => {
|
|
702
634
|
if (!Number.isInteger(count) || !Number.isInteger(parts) || count < 0 || parts < 0 || parts > count) return null;
|
|
703
635
|
if (parts === 0) return count === 0 ? 1 : 0;
|
|
@@ -706,21 +638,17 @@ const computeStirlingSecondKind = (count, parts) => {
|
|
|
706
638
|
if (count * band > 4e6) return null;
|
|
707
639
|
return band === parts ? computeStirlingColumn(count, parts) : computeStirlingDiagonal(count, count - parts);
|
|
708
640
|
};
|
|
709
|
-
|
|
710
|
-
//#region src/services/shared/checkIsTruthy.ts
|
|
641
|
+
// src/services/shared/checkIsTruthy.ts
|
|
711
642
|
const checkIsTruthy = (value) => value !== 0 && !Number.isNaN(value);
|
|
712
|
-
|
|
713
|
-
//#region src/services/function/computeTruthyCount.ts
|
|
643
|
+
// src/services/function/computeTruthyCount.ts
|
|
714
644
|
const computeTruthyCount = (values) => values.filter((value) => checkIsTruthy(value)).length;
|
|
715
|
-
|
|
716
|
-
//#region src/services/function/computeVariance.ts
|
|
645
|
+
// src/services/function/computeVariance.ts
|
|
717
646
|
const computeVariance = (values) => {
|
|
718
647
|
if (values.length === 1) return Number.isFinite(values[0] ?? NaN) ? 0 : NaN;
|
|
719
648
|
const average = computeMean(values);
|
|
720
649
|
return computeSum(values.map((value) => (value - average) ** 2)) / (values.length - 1);
|
|
721
650
|
};
|
|
722
|
-
|
|
723
|
-
//#region src/services/function/computeExtreme.ts
|
|
651
|
+
// src/services/function/computeExtreme.ts
|
|
724
652
|
const computeExtreme = (values, initial, checkIsPreferred) => {
|
|
725
653
|
let extreme = initial;
|
|
726
654
|
for (const value of values) {
|
|
@@ -729,8 +657,7 @@ const computeExtreme = (values, initial, checkIsPreferred) => {
|
|
|
729
657
|
}
|
|
730
658
|
return extreme;
|
|
731
659
|
};
|
|
732
|
-
|
|
733
|
-
//#region src/services/function/computeVectorNorm.ts
|
|
660
|
+
// src/services/function/computeVectorNorm.ts
|
|
734
661
|
const computeVectorNorm = (values, power) => {
|
|
735
662
|
if (Number.isNaN(power)) return null;
|
|
736
663
|
const magnitudes = values.map((value) => Math.abs(value));
|
|
@@ -742,8 +669,7 @@ const computeVectorNorm = (values, power) => {
|
|
|
742
669
|
if (checkIsNearlyEqual(power, 0)) return Number.POSITIVE_INFINITY;
|
|
743
670
|
return computeSum(magnitudes.map((magnitude) => magnitude ** power)) ** (1 / power);
|
|
744
671
|
};
|
|
745
|
-
|
|
746
|
-
//#region src/services/function/computeSummedZeta.ts
|
|
672
|
+
// src/services/function/computeSummedZeta.ts
|
|
747
673
|
const computeSummedZeta = (value) => {
|
|
748
674
|
let total = 0;
|
|
749
675
|
for (let integer = 1; integer < 10; integer++) total += integer ** -value;
|
|
@@ -756,8 +682,7 @@ const computeSummedZeta = (value) => {
|
|
|
756
682
|
}
|
|
757
683
|
return total;
|
|
758
684
|
};
|
|
759
|
-
|
|
760
|
-
//#region src/services/function/computeZeta.ts
|
|
685
|
+
// src/services/function/computeZeta.ts
|
|
761
686
|
const computeZeta = (value) => {
|
|
762
687
|
if (value === Number.POSITIVE_INFINITY) return 1;
|
|
763
688
|
if (!Number.isFinite(value)) return NaN;
|
|
@@ -772,11 +697,9 @@ const computeZeta = (value) => {
|
|
|
772
697
|
}
|
|
773
698
|
return 2 ** value * Math.PI ** (value - 1) * Math.sin(Math.PI * value / 2) * computeGamma(1 - value) * computeSummedZeta(1 - value);
|
|
774
699
|
};
|
|
775
|
-
|
|
776
|
-
//#region src/services/function/signature/createNumericCompute.ts
|
|
700
|
+
// src/services/function/signature/createNumericCompute.ts
|
|
777
701
|
const createNumericCompute = (compute) => (values) => compute(values.flat());
|
|
778
|
-
|
|
779
|
-
//#region src/services/function/signature/createSignature.ts
|
|
702
|
+
// src/services/function/signature/createSignature.ts
|
|
780
703
|
const createSignature = (parameters, minArity, maxArity, compute, scalarCompute = {}) => ({
|
|
781
704
|
compute,
|
|
782
705
|
maxArity,
|
|
@@ -784,37 +707,30 @@ const createSignature = (parameters, minArity, maxArity, compute, scalarCompute
|
|
|
784
707
|
parameters,
|
|
785
708
|
...scalarCompute
|
|
786
709
|
});
|
|
787
|
-
|
|
788
|
-
//#region src/services/function/signature/createNumberSignature.ts
|
|
710
|
+
// src/services/function/signature/createNumberSignature.ts
|
|
789
711
|
const createNumberSignature = (minArity, maxArity, compute, scalarCompute) => createSignature(["number"], minArity, maxArity, createNumericCompute(compute), scalarCompute);
|
|
790
|
-
|
|
791
|
-
//#region src/services/function/signature/createRangedSignatures.ts
|
|
712
|
+
// src/services/function/signature/createRangedSignatures.ts
|
|
792
713
|
const createRangedSignatures = (minArity, maxArity, compute, scalarCompute) => [createNumberSignature(minArity, maxArity, compute, scalarCompute)];
|
|
793
|
-
|
|
794
|
-
//#region src/services/function/signature/createBinarySignatures.ts
|
|
714
|
+
// src/services/function/signature/createBinarySignatures.ts
|
|
795
715
|
const createBinarySignatures = (compute) => createRangedSignatures(2, 2, (values) => compute(values[0] ?? NaN, values[1] ?? NaN), { computeBinary: compute });
|
|
796
|
-
|
|
797
|
-
//#region src/services/function/signature/createBitwisePair.ts
|
|
716
|
+
// src/services/function/signature/createBitwisePair.ts
|
|
798
717
|
const createBitwisePair = (absorbing, compute) => (left, right) => {
|
|
799
718
|
if (left === absorbing) return absorbing;
|
|
800
719
|
if (!Number.isInteger(left) || !Number.isInteger(right)) return null;
|
|
801
720
|
return compute(left, right);
|
|
802
721
|
};
|
|
803
|
-
|
|
804
|
-
//#region src/services/function/signature/createBitwiseFold.ts
|
|
722
|
+
// src/services/function/signature/createBitwiseFold.ts
|
|
805
723
|
const createBitwiseFold = (absorbing, compute) => {
|
|
806
724
|
const computePair = createBitwisePair(absorbing, compute);
|
|
807
725
|
return (values) => values.slice(1).reduce((result, value) => result === null ? null : computePair(result, value), values[0] ?? NaN);
|
|
808
726
|
};
|
|
809
|
-
|
|
810
|
-
//#region src/services/function/shiftDecimalPlaces.ts
|
|
727
|
+
// src/services/function/shiftDecimalPlaces.ts
|
|
811
728
|
const shiftDecimalPlaces = (value, places) => {
|
|
812
729
|
if (!Number.isFinite(value)) return value;
|
|
813
730
|
const [mantissa = "", exponent = "0"] = value.toExponential().split("e");
|
|
814
731
|
return Number(`${mantissa}e${Number(exponent) + places}`);
|
|
815
732
|
};
|
|
816
|
-
|
|
817
|
-
//#region src/services/function/roundToDigits.ts
|
|
733
|
+
// src/services/function/roundToDigits.ts
|
|
818
734
|
const roundToDigits = (rounder, value, digits) => {
|
|
819
735
|
if (!Number.isInteger(digits) || digits < 0 || digits > 15) return null;
|
|
820
736
|
if (!Number.isFinite(value)) return value;
|
|
@@ -822,8 +738,7 @@ const roundToDigits = (rounder, value, digits) => {
|
|
|
822
738
|
if (digits === 0) return rounder(value) + 0;
|
|
823
739
|
return shiftDecimalPlaces(rounder(shiftDecimalPlaces(value, digits)), -digits);
|
|
824
740
|
};
|
|
825
|
-
|
|
826
|
-
//#region src/services/function/signature/createDigitSignatures.ts
|
|
741
|
+
// src/services/function/signature/createDigitSignatures.ts
|
|
827
742
|
const createDigitSignatures = (rounder) => createRangedSignatures(1, 2, (values) => {
|
|
828
743
|
const [value = NaN, digits = 0] = values;
|
|
829
744
|
return roundToDigits(rounder, value, digits);
|
|
@@ -831,47 +746,33 @@ const createDigitSignatures = (rounder) => createRangedSignatures(1, 2, (values)
|
|
|
831
746
|
computeBinary: (value, digits) => roundToDigits(rounder, value, digits),
|
|
832
747
|
computeUnary: (value) => roundToDigits(rounder, value, 0)
|
|
833
748
|
});
|
|
834
|
-
|
|
835
|
-
//#region src/services/function/signature/createNonEmptyCompute.ts
|
|
749
|
+
// src/services/function/signature/createNonEmptyCompute.ts
|
|
836
750
|
const createNonEmptyCompute = (compute) => (values) => values.length === 0 ? null : compute(values);
|
|
837
|
-
|
|
838
|
-
//#region src/services/function/signature/createListSignature.ts
|
|
751
|
+
// src/services/function/signature/createListSignature.ts
|
|
839
752
|
const createListSignature = (compute) => createSignature(["list"], 1, 1, createNumericCompute(compute));
|
|
840
|
-
|
|
841
|
-
//#region src/services/function/signature/createVariadicSignatures.ts
|
|
753
|
+
// src/services/function/signature/createVariadicSignatures.ts
|
|
842
754
|
const createVariadicSignatures = (minArity, compute, computeBinary) => [createNumberSignature(minArity, Number.POSITIVE_INFINITY, compute, { computeBinary })];
|
|
843
|
-
|
|
844
|
-
//#region src/services/function/signature/createSpreadSignatures.ts
|
|
755
|
+
// src/services/function/signature/createSpreadSignatures.ts
|
|
845
756
|
const createSpreadSignatures = (minArity, compute) => [...createVariadicSignatures(minArity, compute), createListSignature(compute)];
|
|
846
|
-
|
|
847
|
-
//#region src/services/function/signature/createExtremeSignatures.ts
|
|
757
|
+
// src/services/function/signature/createExtremeSignatures.ts
|
|
848
758
|
const createExtremeSignatures = (checkIsPreferred) => createSpreadSignatures(1, createNonEmptyCompute((values) => computeExtreme(values, values[0] ?? NaN, checkIsPreferred)));
|
|
849
|
-
|
|
850
|
-
//#region src/services/function/signature/createSingletonListSignature.ts
|
|
759
|
+
// src/services/function/signature/createSingletonListSignature.ts
|
|
851
760
|
const createSingletonListSignature = (compute) => createListSignature((values) => values.length === 1 ? compute(values[0] ?? NaN) : null);
|
|
852
|
-
|
|
853
|
-
//#region src/services/function/signature/createUnarySignatures.ts
|
|
761
|
+
// src/services/function/signature/createUnarySignatures.ts
|
|
854
762
|
const createUnarySignatures = (compute) => createRangedSignatures(1, 1, (values) => compute(values[0] ?? NaN), { computeUnary: compute });
|
|
855
|
-
|
|
856
|
-
//#region src/services/function/signature/createIdentitySignatures.ts
|
|
763
|
+
// src/services/function/signature/createIdentitySignatures.ts
|
|
857
764
|
const createIdentitySignatures = () => [...createUnarySignatures((value) => value), createSingletonListSignature((value) => value)];
|
|
858
|
-
|
|
859
|
-
//#region src/services/function/signature/createIntegerBinarySignatures.ts
|
|
765
|
+
// src/services/function/signature/createIntegerBinarySignatures.ts
|
|
860
766
|
const createIntegerBinarySignatures = (compute) => createBinarySignatures((left, right) => Number.isInteger(left) && Number.isInteger(right) ? compute(left, right) : null);
|
|
861
|
-
|
|
862
|
-
//#region src/services/function/signature/createIntegerUnarySignatures.ts
|
|
767
|
+
// src/services/function/signature/createIntegerUnarySignatures.ts
|
|
863
768
|
const createIntegerUnarySignatures = (compute) => createUnarySignatures((value) => Number.isInteger(value) ? compute(value) : null);
|
|
864
|
-
|
|
865
|
-
//#region src/services/function/signature/createListFirstCompute.ts
|
|
769
|
+
// src/services/function/signature/createListFirstCompute.ts
|
|
866
770
|
const createListFirstCompute = (compute) => (values) => compute(values.slice(0, 1).flat(), values.slice(1).flat());
|
|
867
|
-
|
|
868
|
-
//#region src/services/function/signature/createListPairCompute.ts
|
|
771
|
+
// src/services/function/signature/createListPairCompute.ts
|
|
869
772
|
const createListPairCompute = (compute) => (values) => compute(values.slice(0, 1).flat(), values.slice(1, 2).flat());
|
|
870
|
-
|
|
871
|
-
//#region src/services/function/signature/createListPairSignature.ts
|
|
773
|
+
// src/services/function/signature/createListPairSignature.ts
|
|
872
774
|
const createListPairSignature = (compute) => createSignature(["list", "list"], 2, 2, createListPairCompute(compute));
|
|
873
|
-
|
|
874
|
-
//#region src/services/function/signature/createOrderedListSignatures.ts
|
|
775
|
+
// src/services/function/signature/createOrderedListSignatures.ts
|
|
875
776
|
const createOrderedListSignatures = (compute) => {
|
|
876
777
|
const computePair = createListPairCompute(compute);
|
|
877
778
|
return [
|
|
@@ -880,11 +781,9 @@ const createOrderedListSignatures = (compute) => {
|
|
|
880
781
|
["list", "list"]
|
|
881
782
|
].map((parameters) => createSignature(parameters, 2, 2, computePair));
|
|
882
783
|
};
|
|
883
|
-
|
|
884
|
-
//#region src/services/shared/toNumber.ts
|
|
784
|
+
// src/services/shared/toNumber.ts
|
|
885
785
|
const toNumber = (flag) => flag ? 1 : 0;
|
|
886
|
-
|
|
887
|
-
//#region src/services/function/MathExpressionFunctionMap.ts
|
|
786
|
+
// src/services/function/MathExpressionFunctionMap.ts
|
|
888
787
|
const MathExpressionFunctionMap = {
|
|
889
788
|
abs: createUnarySignatures(Math.abs),
|
|
890
789
|
acos: createUnarySignatures(Math.acos),
|
|
@@ -1050,14 +949,11 @@ const MathExpressionFunctionMap = {
|
|
|
1050
949
|
xor: createVariadicSignatures(1, (values) => toNumber(computeTruthyCount(values) % 2 === 1), (left, right) => toNumber(checkIsTruthy(left) !== checkIsTruthy(right))),
|
|
1051
950
|
zeta: createUnarySignatures(computeZeta)
|
|
1052
951
|
};
|
|
1053
|
-
|
|
1054
|
-
//#region src/services/shared/getOwnValue.ts
|
|
952
|
+
// src/services/shared/getOwnValue.ts
|
|
1055
953
|
const getOwnValue = (record, key) => Object.hasOwn(record, key) ? record[key] : void 0;
|
|
1056
|
-
|
|
1057
|
-
//#region src/services/shared/getMathExpressionSignatures.ts
|
|
954
|
+
// src/services/shared/getMathExpressionSignatures.ts
|
|
1058
955
|
const getMathExpressionSignatures = (name) => getOwnValue(MathExpressionFunctionMap, name);
|
|
1059
|
-
|
|
1060
|
-
//#region src/services/compiler/getMathExpressionScalarCompute.ts
|
|
956
|
+
// src/services/compiler/getMathExpressionScalarCompute.ts
|
|
1061
957
|
const getMathExpressionScalarCompute = (name, key) => {
|
|
1062
958
|
const signature = getMathExpressionSignatures(name)?.[0];
|
|
1063
959
|
if (signature === void 0) return () => null;
|
|
@@ -1065,8 +961,7 @@ const getMathExpressionScalarCompute = (name, key) => {
|
|
|
1065
961
|
if (scalarCompute !== void 0) return scalarCompute;
|
|
1066
962
|
return (...values) => signature.compute(values);
|
|
1067
963
|
};
|
|
1068
|
-
|
|
1069
|
-
//#region src/services/compiler/node/compileBinary.ts
|
|
964
|
+
// src/services/compiler/node/compileBinary.ts
|
|
1070
965
|
const compileBinary = (node, context) => {
|
|
1071
966
|
const { left, name, right } = node;
|
|
1072
967
|
const compiledLeft = context.compile(left);
|
|
@@ -1100,8 +995,7 @@ const compileBinary = (node, context) => {
|
|
|
1100
995
|
isConstant: compiledLeft.isConstant && compiledRight.isConstant
|
|
1101
996
|
};
|
|
1102
997
|
};
|
|
1103
|
-
|
|
1104
|
-
//#region src/services/compiler/compileList.ts
|
|
998
|
+
// src/services/compiler/compileList.ts
|
|
1105
999
|
const compileList = (elements, context) => {
|
|
1106
1000
|
const compiledElements = elements.map((element) => context.compile(element));
|
|
1107
1001
|
return {
|
|
@@ -1117,29 +1011,22 @@ const compileList = (elements, context) => {
|
|
|
1117
1011
|
isConstant: compiledElements.every((element) => element.isConstant)
|
|
1118
1012
|
};
|
|
1119
1013
|
};
|
|
1120
|
-
|
|
1121
|
-
//#region src/services/compiler/compileArgument.ts
|
|
1014
|
+
// src/services/compiler/compileArgument.ts
|
|
1122
1015
|
const compileArgument = (node, context) => {
|
|
1123
1016
|
if (node.type === "list") return compileList(node.elements, context);
|
|
1124
1017
|
return context.compile(node);
|
|
1125
1018
|
};
|
|
1126
|
-
|
|
1127
|
-
//#region src/services/shared/getMathExpressionParameterType.ts
|
|
1019
|
+
// src/services/shared/getMathExpressionParameterType.ts
|
|
1128
1020
|
const getMathExpressionParameterType = (node) => node.type === "list" ? "list" : "number";
|
|
1129
|
-
|
|
1130
|
-
//#region src/services/shared/checkIsMatchingKind.ts
|
|
1021
|
+
// src/services/shared/checkIsMatchingKind.ts
|
|
1131
1022
|
const checkIsMatchingKind = (parameterType, argumentType) => parameterType === "any" || parameterType === argumentType;
|
|
1132
|
-
|
|
1133
|
-
//#region src/services/shared/getParameterType.ts
|
|
1023
|
+
// src/services/shared/getParameterType.ts
|
|
1134
1024
|
const getParameterType = (signature, index) => signature.parameters[Math.min(index, signature.parameters.length - 1)];
|
|
1135
|
-
|
|
1136
|
-
//#region src/services/shared/checkIsMatching.ts
|
|
1025
|
+
// src/services/shared/checkIsMatching.ts
|
|
1137
1026
|
const checkIsMatching = (signature, parameterTypes) => parameterTypes.length >= signature.minArity && parameterTypes.length <= signature.maxArity && parameterTypes.every((parameterType, index) => checkIsMatchingKind(getParameterType(signature, index), parameterType));
|
|
1138
|
-
|
|
1139
|
-
//#region src/services/shared/matchMathExpressionSignature.ts
|
|
1027
|
+
// src/services/shared/matchMathExpressionSignature.ts
|
|
1140
1028
|
const matchMathExpressionSignature = (signatures, parameterTypes) => signatures.find((signature) => checkIsMatching(signature, parameterTypes));
|
|
1141
|
-
|
|
1142
|
-
//#region src/services/compiler/node/compileCall.ts
|
|
1029
|
+
// src/services/compiler/node/compileCall.ts
|
|
1143
1030
|
const compileCall = (node, context) => {
|
|
1144
1031
|
const signatures = getMathExpressionSignatures(node.name);
|
|
1145
1032
|
const parameterTypes = node.arguments.map((argument) => getMathExpressionParameterType(argument));
|
|
@@ -1183,8 +1070,7 @@ const compileCall = (node, context) => {
|
|
|
1183
1070
|
isConstant
|
|
1184
1071
|
};
|
|
1185
1072
|
};
|
|
1186
|
-
|
|
1187
|
-
//#region src/services/compiler/node/compileComparison.ts
|
|
1073
|
+
// src/services/compiler/node/compileComparison.ts
|
|
1188
1074
|
const compileComparison = (node, context) => {
|
|
1189
1075
|
const compiledOperands = node.operands.map((operand) => context.compile(operand));
|
|
1190
1076
|
const computes = node.names.map((name) => getMathExpressionScalarCompute(name, "computeBinary"));
|
|
@@ -1205,8 +1091,7 @@ const compileComparison = (node, context) => {
|
|
|
1205
1091
|
isConstant: compiledOperands.every((operand) => operand.isConstant)
|
|
1206
1092
|
};
|
|
1207
1093
|
};
|
|
1208
|
-
|
|
1209
|
-
//#region src/services/compiler/node/compileConditional.ts
|
|
1094
|
+
// src/services/compiler/node/compileConditional.ts
|
|
1210
1095
|
const compileConditional = (node, context) => {
|
|
1211
1096
|
const compiledCondition = context.compile(node.condition);
|
|
1212
1097
|
const compiledWhenTrue = context.compile(node.whenTrue);
|
|
@@ -1221,17 +1106,14 @@ const compileConditional = (node, context) => {
|
|
|
1221
1106
|
isConstant: compiledCondition.isConstant && compiledWhenTrue.isConstant && compiledWhenFalse.isConstant
|
|
1222
1107
|
};
|
|
1223
1108
|
};
|
|
1224
|
-
|
|
1225
|
-
//#region src/services/compiler/node/compileGroup.ts
|
|
1109
|
+
// src/services/compiler/node/compileGroup.ts
|
|
1226
1110
|
const compileGroup = (node, context) => context.compile(node.operand);
|
|
1227
|
-
|
|
1228
|
-
//#region src/services/compiler/node/compileListNode.ts
|
|
1111
|
+
// src/services/compiler/node/compileListNode.ts
|
|
1229
1112
|
const compileListNode = () => ({
|
|
1230
1113
|
evaluate: () => null,
|
|
1231
1114
|
isConstant: false
|
|
1232
1115
|
});
|
|
1233
|
-
|
|
1234
|
-
//#region src/services/compiler/node/compileLogical.ts
|
|
1116
|
+
// src/services/compiler/node/compileLogical.ts
|
|
1235
1117
|
const compileLogical = (node, context) => {
|
|
1236
1118
|
const compiledLeft = context.compile(node.left);
|
|
1237
1119
|
if (node.operator === "nullish") return compiledLeft;
|
|
@@ -1261,8 +1143,7 @@ const compileLogical = (node, context) => {
|
|
|
1261
1143
|
default: return exhaustiveGuard(node.operator);
|
|
1262
1144
|
}
|
|
1263
1145
|
};
|
|
1264
|
-
|
|
1265
|
-
//#region src/services/shared/MathExpressionConstantMap.ts
|
|
1146
|
+
// src/services/shared/MathExpressionConstantMap.ts
|
|
1266
1147
|
const MathExpressionConstantMap = {
|
|
1267
1148
|
E: Math.E,
|
|
1268
1149
|
e: Math.E,
|
|
@@ -1281,11 +1162,9 @@ const MathExpressionConstantMap = {
|
|
|
1281
1162
|
tau: 2 * Math.PI,
|
|
1282
1163
|
true: 1
|
|
1283
1164
|
};
|
|
1284
|
-
|
|
1285
|
-
//#region src/services/compiler/getMathExpressionConstant.ts
|
|
1165
|
+
// src/services/compiler/getMathExpressionConstant.ts
|
|
1286
1166
|
const getMathExpressionConstant = (name) => getOwnValue(MathExpressionConstantMap, name);
|
|
1287
|
-
|
|
1288
|
-
//#region src/services/compiler/node/compileName.ts
|
|
1167
|
+
// src/services/compiler/node/compileName.ts
|
|
1289
1168
|
const compileName = (node, context) => {
|
|
1290
1169
|
const slot = context.assignedSlots.get(node.name);
|
|
1291
1170
|
if (slot !== void 0) return {
|
|
@@ -1303,8 +1182,7 @@ const compileName = (node, context) => {
|
|
|
1303
1182
|
isConstant: true
|
|
1304
1183
|
};
|
|
1305
1184
|
};
|
|
1306
|
-
|
|
1307
|
-
//#region src/services/compiler/node/compileNumber.ts
|
|
1185
|
+
// src/services/compiler/node/compileNumber.ts
|
|
1308
1186
|
const compileNumber = (node) => {
|
|
1309
1187
|
const { value } = node;
|
|
1310
1188
|
return {
|
|
@@ -1312,8 +1190,7 @@ const compileNumber = (node) => {
|
|
|
1312
1190
|
isConstant: true
|
|
1313
1191
|
};
|
|
1314
1192
|
};
|
|
1315
|
-
|
|
1316
|
-
//#region src/services/compiler/node/compilePercentage.ts
|
|
1193
|
+
// src/services/compiler/node/compilePercentage.ts
|
|
1317
1194
|
const compilePercentage = (node, context) => {
|
|
1318
1195
|
const compiledOperand = context.compile(node.operand);
|
|
1319
1196
|
return {
|
|
@@ -1324,8 +1201,7 @@ const compilePercentage = (node, context) => {
|
|
|
1324
1201
|
isConstant: compiledOperand.isConstant
|
|
1325
1202
|
};
|
|
1326
1203
|
};
|
|
1327
|
-
|
|
1328
|
-
//#region src/services/compiler/node/compileUnary.ts
|
|
1204
|
+
// src/services/compiler/node/compileUnary.ts
|
|
1329
1205
|
const compileUnary = (node, context) => {
|
|
1330
1206
|
const compute = getMathExpressionScalarCompute(node.name, "computeUnary");
|
|
1331
1207
|
const compiledOperand = context.compile(node.operand);
|
|
@@ -1337,8 +1213,7 @@ const compileUnary = (node, context) => {
|
|
|
1337
1213
|
isConstant: compiledOperand.isConstant
|
|
1338
1214
|
};
|
|
1339
1215
|
};
|
|
1340
|
-
|
|
1341
|
-
//#region src/services/compiler/MathExpressionNodeCompileMap.ts
|
|
1216
|
+
// src/services/compiler/MathExpressionNodeCompileMap.ts
|
|
1342
1217
|
const MathExpressionNodeCompileMap = {
|
|
1343
1218
|
["assignment"]: compileAssignment,
|
|
1344
1219
|
["binary"]: compileBinary,
|
|
@@ -1353,8 +1228,7 @@ const MathExpressionNodeCompileMap = {
|
|
|
1353
1228
|
["percentage"]: compilePercentage,
|
|
1354
1229
|
["unary"]: compileUnary
|
|
1355
1230
|
};
|
|
1356
|
-
|
|
1357
|
-
//#region src/services/shared/getMathExpressionChildren.ts
|
|
1231
|
+
// src/services/shared/getMathExpressionChildren.ts
|
|
1358
1232
|
const getMathExpressionChildren = (node) => {
|
|
1359
1233
|
switch (node.type) {
|
|
1360
1234
|
case "assignment": return [node.value];
|
|
@@ -1376,14 +1250,12 @@ const getMathExpressionChildren = (node) => {
|
|
|
1376
1250
|
default: return exhaustiveGuard(node);
|
|
1377
1251
|
}
|
|
1378
1252
|
};
|
|
1379
|
-
|
|
1380
|
-
//#region src/services/compiler/collectMathExpressionAssignedNames.ts
|
|
1253
|
+
// src/services/compiler/collectMathExpressionAssignedNames.ts
|
|
1381
1254
|
const collectMathExpressionAssignedNames = (node, names) => {
|
|
1382
1255
|
if (node.type === "assignment") names.add(node.name);
|
|
1383
1256
|
for (const child of getMathExpressionChildren(node)) collectMathExpressionAssignedNames(child, names);
|
|
1384
1257
|
};
|
|
1385
|
-
|
|
1386
|
-
//#region src/services/compiler/compileMathExpressionNode.ts
|
|
1258
|
+
// src/services/compiler/compileMathExpressionNode.ts
|
|
1387
1259
|
const compileMathExpressionNode = (node, context) => {
|
|
1388
1260
|
const compileOfType = MathExpressionNodeCompileMap[node.type];
|
|
1389
1261
|
const compiled = compileOfType(node, context);
|
|
@@ -1394,14 +1266,12 @@ const compileMathExpressionNode = (node, context) => {
|
|
|
1394
1266
|
isConstant: true
|
|
1395
1267
|
};
|
|
1396
1268
|
};
|
|
1397
|
-
|
|
1398
|
-
//#region src/services/compiler/getMathExpressionOuterValue.ts
|
|
1269
|
+
// src/services/compiler/getMathExpressionOuterValue.ts
|
|
1399
1270
|
const getMathExpressionOuterValue = (outer, values) => {
|
|
1400
1271
|
if (outer.variableIndex !== void 0) return values[outer.variableIndex] ?? NaN;
|
|
1401
1272
|
return outer.constant ?? null;
|
|
1402
1273
|
};
|
|
1403
|
-
|
|
1404
|
-
//#region src/services/compiler/compileMathExpression.ts
|
|
1274
|
+
// src/services/compiler/compileMathExpression.ts
|
|
1405
1275
|
const compileMathExpression = (node, variableNames) => {
|
|
1406
1276
|
const assignedNames = /* @__PURE__ */ new Set();
|
|
1407
1277
|
collectMathExpressionAssignedNames(node, assignedNames);
|
|
@@ -1422,8 +1292,7 @@ const compileMathExpression = (node, variableNames) => {
|
|
|
1422
1292
|
return compiled.evaluate(values, locals) ?? NaN;
|
|
1423
1293
|
};
|
|
1424
1294
|
};
|
|
1425
|
-
|
|
1426
|
-
//#region src/services/names/walkNode.ts
|
|
1295
|
+
// src/services/names/walkNode.ts
|
|
1427
1296
|
const walkNode = (node, bound, free) => {
|
|
1428
1297
|
switch (node.type) {
|
|
1429
1298
|
case "assignment":
|
|
@@ -1471,16 +1340,14 @@ const walkNode = (node, bound, free) => {
|
|
|
1471
1340
|
default: return exhaustiveGuard(node);
|
|
1472
1341
|
}
|
|
1473
1342
|
};
|
|
1474
|
-
|
|
1475
|
-
//#region src/services/names/getMathExpressionNames.ts
|
|
1343
|
+
// src/services/names/getMathExpressionNames.ts
|
|
1476
1344
|
const getMathExpressionNames = (node) => {
|
|
1477
1345
|
const bound = /* @__PURE__ */ new Set();
|
|
1478
1346
|
const free = /* @__PURE__ */ new Set();
|
|
1479
1347
|
walkNode(node, bound, free);
|
|
1480
1348
|
return [...free].filter((name) => getMathExpressionConstant(name) === void 0);
|
|
1481
1349
|
};
|
|
1482
|
-
|
|
1483
|
-
//#region src/services/parser/MathExpressionBinaryOperatorMap.ts
|
|
1350
|
+
// src/services/parser/MathExpressionBinaryOperatorMap.ts
|
|
1484
1351
|
const MathExpressionBinaryOperatorMap = {
|
|
1485
1352
|
"!=": {
|
|
1486
1353
|
name: "unequal",
|
|
@@ -1598,8 +1465,7 @@ const MathExpressionBinaryOperatorMap = {
|
|
|
1598
1465
|
type: "binary"
|
|
1599
1466
|
}
|
|
1600
1467
|
};
|
|
1601
|
-
|
|
1602
|
-
//#region src/services/parser/MathExpressionOperatorMap.ts
|
|
1468
|
+
// src/services/parser/MathExpressionOperatorMap.ts
|
|
1603
1469
|
const MathExpressionOperatorMap = {
|
|
1604
1470
|
["Nullish"]: { "??": "nullish" },
|
|
1605
1471
|
["Power"]: {
|
|
@@ -1613,40 +1479,32 @@ const MathExpressionOperatorMap = {
|
|
|
1613
1479
|
"~": "bitNot"
|
|
1614
1480
|
}
|
|
1615
1481
|
};
|
|
1616
|
-
|
|
1617
|
-
//#region src/services/parser/constants.ts
|
|
1482
|
+
// src/services/parser/constants.ts
|
|
1618
1483
|
const MAX_MATH_EXPRESSION_DEPTH = 64;
|
|
1619
1484
|
const PLACEHOLDER = {
|
|
1620
1485
|
type: "number",
|
|
1621
1486
|
value: NaN
|
|
1622
1487
|
};
|
|
1623
|
-
|
|
1624
|
-
//#region src/services/parser/failMathExpressionAt.ts
|
|
1488
|
+
// src/services/parser/failMathExpressionAt.ts
|
|
1625
1489
|
const failMathExpressionAt = (state, message, column) => {
|
|
1626
1490
|
if (state.error !== null) return;
|
|
1627
1491
|
state.error = new MathExpressionError(`${message} (char ${column})`);
|
|
1628
1492
|
};
|
|
1629
|
-
|
|
1630
|
-
//#region src/services/parser/getMathExpressionColumn.ts
|
|
1493
|
+
// src/services/parser/getMathExpressionColumn.ts
|
|
1631
1494
|
const getMathExpressionColumn = (state) => state.index - state.token.length + 1;
|
|
1632
|
-
|
|
1633
|
-
//#region src/services/parser/failMathExpression.ts
|
|
1495
|
+
// src/services/parser/failMathExpression.ts
|
|
1634
1496
|
const failMathExpression = (state, message) => failMathExpressionAt(state, message, getMathExpressionColumn(state));
|
|
1635
|
-
|
|
1636
|
-
//#region src/services/parser/checkCanMathExpressionNest.ts
|
|
1497
|
+
// src/services/parser/checkCanMathExpressionNest.ts
|
|
1637
1498
|
const checkCanMathExpressionNest = (state) => {
|
|
1638
1499
|
if (state.depth < 64) return true;
|
|
1639
1500
|
failMathExpression(state, `Formula nests deeper than 64 levels`);
|
|
1640
1501
|
return false;
|
|
1641
1502
|
};
|
|
1642
|
-
|
|
1643
|
-
//#region src/services/parser/checkIsToken.ts
|
|
1503
|
+
// src/services/parser/checkIsToken.ts
|
|
1644
1504
|
const checkIsToken = (state, token) => state.token === token;
|
|
1645
|
-
|
|
1646
|
-
//#region src/services/parser/token/checkIsDigitCharacter.ts
|
|
1505
|
+
// src/services/parser/token/checkIsDigitCharacter.ts
|
|
1647
1506
|
const checkIsDigitCharacter = (character) => character >= "0" && character <= "9";
|
|
1648
|
-
|
|
1649
|
-
//#region src/services/parser/token/constants.ts
|
|
1507
|
+
// src/services/parser/token/constants.ts
|
|
1650
1508
|
const DELIMITERS_OF_THREE = /* @__PURE__ */ new Set([">>>"]);
|
|
1651
1509
|
const DELIMITERS_OF_TWO = /* @__PURE__ */ new Set([
|
|
1652
1510
|
"!=",
|
|
@@ -1702,17 +1560,14 @@ const DECIMAL_MARK_OPERATOR_FOLLOWERS = /* @__PURE__ */ new Set([
|
|
|
1702
1560
|
]);
|
|
1703
1561
|
const WORD_START_REGEX = /^[\p{L}_$]$/u;
|
|
1704
1562
|
const WORD_CHARACTER_REGEX = /^[\p{L}\p{Nd}_$]$/u;
|
|
1705
|
-
|
|
1706
|
-
//#region src/services/parser/token/checkIsWordStartCharacter.ts
|
|
1563
|
+
// src/services/parser/token/checkIsWordStartCharacter.ts
|
|
1707
1564
|
const checkIsWordStartCharacter = (character) => {
|
|
1708
1565
|
if (character >= "") return WORD_START_REGEX.test(character);
|
|
1709
1566
|
return character >= "a" && character <= "z" || character >= "A" && character <= "Z" || character === "_" || character === "$";
|
|
1710
1567
|
};
|
|
1711
|
-
|
|
1712
|
-
//#region src/services/parser/token/getMathExpressionCharacter.ts
|
|
1568
|
+
// src/services/parser/token/getMathExpressionCharacter.ts
|
|
1713
1569
|
const getMathExpressionCharacter = (state, offset) => state.source.charAt(state.index + offset);
|
|
1714
|
-
|
|
1715
|
-
//#region src/services/parser/token/readMathExpressionDelimiter.ts
|
|
1570
|
+
// src/services/parser/token/readMathExpressionDelimiter.ts
|
|
1716
1571
|
const readMathExpressionDelimiter = (state) => {
|
|
1717
1572
|
const character = getMathExpressionCharacter(state, 0);
|
|
1718
1573
|
let length = 0;
|
|
@@ -1727,8 +1582,7 @@ const readMathExpressionDelimiter = (state) => {
|
|
|
1727
1582
|
if ([")", "]"].includes(state.token)) state.nestingLevel--;
|
|
1728
1583
|
return length;
|
|
1729
1584
|
};
|
|
1730
|
-
|
|
1731
|
-
//#region src/services/parser/token/MathExpressionRadixMap.ts
|
|
1585
|
+
// src/services/parser/token/MathExpressionRadixMap.ts
|
|
1732
1586
|
const MathExpressionRadixMap = {
|
|
1733
1587
|
b: {
|
|
1734
1588
|
digit: /^[01]$/u,
|
|
@@ -1743,15 +1597,13 @@ const MathExpressionRadixMap = {
|
|
|
1743
1597
|
radix: 16
|
|
1744
1598
|
}
|
|
1745
1599
|
};
|
|
1746
|
-
|
|
1747
|
-
//#region src/services/parser/token/takeMathExpressionMatching.ts
|
|
1600
|
+
// src/services/parser/token/takeMathExpressionMatching.ts
|
|
1748
1601
|
const takeMathExpressionMatching = (state, checkCharacter) => {
|
|
1749
1602
|
const start = state.index;
|
|
1750
1603
|
while (checkCharacter(getMathExpressionCharacter(state, 0))) state.index++;
|
|
1751
1604
|
return state.source.slice(start, state.index);
|
|
1752
1605
|
};
|
|
1753
|
-
|
|
1754
|
-
//#region src/services/parser/token/readRadixNumber.ts
|
|
1606
|
+
// src/services/parser/token/readRadixNumber.ts
|
|
1755
1607
|
const readRadixNumber = (state, prefix, baseDigits) => {
|
|
1756
1608
|
const checkBaseDigit = (character) => baseDigits.test(character);
|
|
1757
1609
|
state.index += 2;
|
|
@@ -1774,17 +1626,14 @@ const readRadixNumber = (state, prefix, baseDigits) => {
|
|
|
1774
1626
|
state.token = `0${prefix}${digits}${wordSize}`;
|
|
1775
1627
|
state.tokenType = "number";
|
|
1776
1628
|
};
|
|
1777
|
-
|
|
1778
|
-
//#region src/services/parser/token/checkIsDecimalMark.ts
|
|
1629
|
+
// src/services/parser/token/checkIsDecimalMark.ts
|
|
1779
1630
|
const checkIsDecimalMark = (character, nextCharacter) => character === "." && !DECIMAL_MARK_OPERATOR_FOLLOWERS.has(nextCharacter);
|
|
1780
|
-
|
|
1781
|
-
//#region src/services/parser/token/failExponent.ts
|
|
1631
|
+
// src/services/parser/token/failExponent.ts
|
|
1782
1632
|
const failExponent = (state, text) => {
|
|
1783
1633
|
state.token = text;
|
|
1784
1634
|
failMathExpression(state, `Digit expected, got "${getMathExpressionCharacter(state, 0)}"`);
|
|
1785
1635
|
};
|
|
1786
|
-
|
|
1787
|
-
//#region src/services/parser/token/takeExponent.ts
|
|
1636
|
+
// src/services/parser/token/takeExponent.ts
|
|
1788
1637
|
const takeExponent = (state, text) => {
|
|
1789
1638
|
const exponentMarker = getMathExpressionCharacter(state, 0);
|
|
1790
1639
|
if (!["e", "E"].includes(exponentMarker)) return text;
|
|
@@ -1810,8 +1659,7 @@ const takeExponent = (state, text) => {
|
|
|
1810
1659
|
if (checkIsDecimalMark(getMathExpressionCharacter(state, 0), getMathExpressionCharacter(state, 1))) failExponent(state, taken);
|
|
1811
1660
|
return taken;
|
|
1812
1661
|
};
|
|
1813
|
-
|
|
1814
|
-
//#region src/services/parser/token/readMathExpressionNumber.ts
|
|
1662
|
+
// src/services/parser/token/readMathExpressionNumber.ts
|
|
1815
1663
|
const readMathExpressionNumber = (state) => {
|
|
1816
1664
|
const prefix = getMathExpressionCharacter(state, 1);
|
|
1817
1665
|
const radixEntry = MathExpressionRadixMap[prefix];
|
|
@@ -1828,20 +1676,17 @@ const readMathExpressionNumber = (state) => {
|
|
|
1828
1676
|
state.token = takeExponent(state, state.source.slice(start, state.index));
|
|
1829
1677
|
state.tokenType = "number";
|
|
1830
1678
|
};
|
|
1831
|
-
|
|
1832
|
-
//#region src/services/parser/token/checkIsWordCharacter.ts
|
|
1679
|
+
// src/services/parser/token/checkIsWordCharacter.ts
|
|
1833
1680
|
const checkIsWordCharacter = (character) => {
|
|
1834
1681
|
if (character >= "") return WORD_CHARACTER_REGEX.test(character);
|
|
1835
1682
|
return checkIsWordStartCharacter(character) || checkIsDigitCharacter(character);
|
|
1836
1683
|
};
|
|
1837
|
-
|
|
1838
|
-
//#region src/services/parser/token/readMathExpressionWord.ts
|
|
1684
|
+
// src/services/parser/token/readMathExpressionWord.ts
|
|
1839
1685
|
const readMathExpressionWord = (state) => {
|
|
1840
1686
|
state.token = takeMathExpressionMatching(state, checkIsWordCharacter);
|
|
1841
1687
|
state.tokenType = NAMED_DELIMITERS.has(state.token) ? "delimiter" : "symbol";
|
|
1842
1688
|
};
|
|
1843
|
-
|
|
1844
|
-
//#region src/services/parser/token/skipMathExpressionSpaces.ts
|
|
1689
|
+
// src/services/parser/token/skipMathExpressionSpaces.ts
|
|
1845
1690
|
const skipMathExpressionSpaces = (state) => {
|
|
1846
1691
|
while (state.index < state.source.length) {
|
|
1847
1692
|
const character = getMathExpressionCharacter(state, 0);
|
|
@@ -1854,8 +1699,7 @@ const skipMathExpressionSpaces = (state) => {
|
|
|
1854
1699
|
else break;
|
|
1855
1700
|
}
|
|
1856
1701
|
};
|
|
1857
|
-
|
|
1858
|
-
//#region src/services/parser/getMathExpressionToken.ts
|
|
1702
|
+
// src/services/parser/getMathExpressionToken.ts
|
|
1859
1703
|
const getMathExpressionToken = (state) => {
|
|
1860
1704
|
state.token = "";
|
|
1861
1705
|
state.tokenType = "null";
|
|
@@ -1871,8 +1715,7 @@ const getMathExpressionToken = (state) => {
|
|
|
1871
1715
|
state.tokenType = "unknown";
|
|
1872
1716
|
}
|
|
1873
1717
|
};
|
|
1874
|
-
|
|
1875
|
-
//#region src/services/parser/rule/parseAssignment.ts
|
|
1718
|
+
// src/services/parser/rule/parseAssignment.ts
|
|
1876
1719
|
const parseAssignment = (state, parse) => {
|
|
1877
1720
|
if (!checkCanMathExpressionNest(state)) return PLACEHOLDER;
|
|
1878
1721
|
state.depth++;
|
|
@@ -1890,24 +1733,21 @@ const parseAssignment = (state, parse) => {
|
|
|
1890
1733
|
state.depth--;
|
|
1891
1734
|
return node;
|
|
1892
1735
|
};
|
|
1893
|
-
|
|
1894
|
-
//#region src/services/parser/createBinaryNode.ts
|
|
1736
|
+
// src/services/parser/createBinaryNode.ts
|
|
1895
1737
|
const createBinaryNode = (left, name, right) => ({
|
|
1896
1738
|
left,
|
|
1897
1739
|
name,
|
|
1898
1740
|
right,
|
|
1899
1741
|
type: "binary"
|
|
1900
1742
|
});
|
|
1901
|
-
|
|
1902
|
-
//#region src/services/parser/createLogicalNode.ts
|
|
1743
|
+
// src/services/parser/createLogicalNode.ts
|
|
1903
1744
|
const createLogicalNode = (left, operator, right) => ({
|
|
1904
1745
|
left,
|
|
1905
1746
|
operator,
|
|
1906
1747
|
right,
|
|
1907
1748
|
type: "logical"
|
|
1908
1749
|
});
|
|
1909
|
-
|
|
1910
|
-
//#region src/services/parser/createBinaryOperation.ts
|
|
1750
|
+
// src/services/parser/createBinaryOperation.ts
|
|
1911
1751
|
const createBinaryOperation = (left, operator, right) => {
|
|
1912
1752
|
if (operator.type === "logical") return createLogicalNode(left, operator.operator, right);
|
|
1913
1753
|
if (operator.type === "binary") return createBinaryNode(left, operator.name, right);
|
|
@@ -1922,8 +1762,7 @@ const createBinaryOperation = (left, operator, right) => {
|
|
|
1922
1762
|
type: "comparison"
|
|
1923
1763
|
};
|
|
1924
1764
|
};
|
|
1925
|
-
|
|
1926
|
-
//#region src/services/parser/parseBinaryOperators.ts
|
|
1765
|
+
// src/services/parser/parseBinaryOperators.ts
|
|
1927
1766
|
const parseBinaryOperators = (state, parse, minimumPower) => {
|
|
1928
1767
|
let node = parse(state, "ImplicitProduct");
|
|
1929
1768
|
let operator = getOwnValue(MathExpressionBinaryOperatorMap, state.token);
|
|
@@ -1935,11 +1774,9 @@ const parseBinaryOperators = (state, parse, minimumPower) => {
|
|
|
1935
1774
|
}
|
|
1936
1775
|
return node;
|
|
1937
1776
|
};
|
|
1938
|
-
|
|
1939
|
-
//#region src/services/parser/rule/parseBinary.ts
|
|
1777
|
+
// src/services/parser/rule/parseBinary.ts
|
|
1940
1778
|
const parseBinary = (state, parse) => parseBinaryOperators(state, parse, 0);
|
|
1941
|
-
|
|
1942
|
-
//#region src/services/parser/rule/parseConditional.ts
|
|
1779
|
+
// src/services/parser/rule/parseConditional.ts
|
|
1943
1780
|
const parseConditional = (state, parse) => {
|
|
1944
1781
|
const condition = parse(state, "Binary");
|
|
1945
1782
|
if (state.error !== null || !checkIsToken(state, "?")) return condition;
|
|
@@ -1959,14 +1796,12 @@ const parseConditional = (state, parse) => {
|
|
|
1959
1796
|
whenTrue
|
|
1960
1797
|
};
|
|
1961
1798
|
};
|
|
1962
|
-
|
|
1963
|
-
//#region src/services/parser/checkIsSignedNumber.ts
|
|
1799
|
+
// src/services/parser/checkIsSignedNumber.ts
|
|
1964
1800
|
const checkIsSignedNumber = (node) => {
|
|
1965
1801
|
if (node.type === "number") return true;
|
|
1966
1802
|
return node.type === "unary" && (node.name === "unaryMinus" || node.name === "unaryPlus") && node.operand.type === "number";
|
|
1967
1803
|
};
|
|
1968
|
-
|
|
1969
|
-
//#region src/services/parser/rule/parseDivisionBeforeProduct.ts
|
|
1804
|
+
// src/services/parser/rule/parseDivisionBeforeProduct.ts
|
|
1970
1805
|
const parseDivisionBeforeProduct = (state, parse) => {
|
|
1971
1806
|
const dividend = parse(state, "Percentage");
|
|
1972
1807
|
if (state.error !== null || !checkIsToken(state, "/") || !checkIsSignedNumber(dividend)) return dividend;
|
|
@@ -1982,14 +1817,12 @@ const parseDivisionBeforeProduct = (state, parse) => {
|
|
|
1982
1817
|
Object.assign(state, snapshot);
|
|
1983
1818
|
return dividend;
|
|
1984
1819
|
};
|
|
1985
|
-
|
|
1986
|
-
//#region src/services/parser/checkIsOperatorOperand.ts
|
|
1820
|
+
// src/services/parser/checkIsOperatorOperand.ts
|
|
1987
1821
|
const checkIsOperatorOperand = (node) => {
|
|
1988
1822
|
if (node.type === "unary") return node.name !== "factorial";
|
|
1989
1823
|
return node.type === "binary" || node.type === "comparison" || node.type === "logical";
|
|
1990
1824
|
};
|
|
1991
|
-
|
|
1992
|
-
//#region src/services/parser/rule/parseImplicitProduct.ts
|
|
1825
|
+
// src/services/parser/rule/parseImplicitProduct.ts
|
|
1993
1826
|
const parseImplicitProduct = (state, parse) => {
|
|
1994
1827
|
let node = parse(state, "DivisionBeforeProduct");
|
|
1995
1828
|
let last = node;
|
|
@@ -2000,8 +1833,7 @@ const parseImplicitProduct = (state, parse) => {
|
|
|
2000
1833
|
}
|
|
2001
1834
|
return node;
|
|
2002
1835
|
};
|
|
2003
|
-
|
|
2004
|
-
//#region src/services/parser/rule/parseLeftHand.ts
|
|
1836
|
+
// src/services/parser/rule/parseLeftHand.ts
|
|
2005
1837
|
const parseLeftHand = (state, parse) => {
|
|
2006
1838
|
let node = parse(state, "Symbol");
|
|
2007
1839
|
while (state.error === null && (checkIsToken(state, "!") || checkIsToken(state, "'"))) {
|
|
@@ -2015,8 +1847,7 @@ const parseLeftHand = (state, parse) => {
|
|
|
2015
1847
|
}
|
|
2016
1848
|
return node;
|
|
2017
1849
|
};
|
|
2018
|
-
|
|
2019
|
-
//#region src/services/parser/rule/parseNullish.ts
|
|
1850
|
+
// src/services/parser/rule/parseNullish.ts
|
|
2020
1851
|
const parseNullish = (state, parse) => {
|
|
2021
1852
|
const operators = MathExpressionOperatorMap["Nullish"];
|
|
2022
1853
|
let node = parse(state, "LeftHand");
|
|
@@ -2029,14 +1860,11 @@ const parseNullish = (state, parse) => {
|
|
|
2029
1860
|
}
|
|
2030
1861
|
return node;
|
|
2031
1862
|
};
|
|
2032
|
-
|
|
2033
|
-
//#region src/services/parser/checkIsNameToken.ts
|
|
1863
|
+
// src/services/parser/checkIsNameToken.ts
|
|
2034
1864
|
const checkIsNameToken = (state) => state.tokenType === "symbol" || state.tokenType === "delimiter" && getMathExpressionSignatures(state.token) !== void 0;
|
|
2035
|
-
|
|
2036
|
-
//#region src/services/parser/checkIsUnaryStart.ts
|
|
1865
|
+
// src/services/parser/checkIsUnaryStart.ts
|
|
2037
1866
|
const checkIsUnaryStart = (state) => state.tokenType === "number" || checkIsNameToken(state) || checkIsToken(state, "(") || getOwnValue(MathExpressionOperatorMap["Unary"], state.token) !== void 0;
|
|
2038
|
-
|
|
2039
|
-
//#region src/services/parser/rule/parsePercentage.ts
|
|
1867
|
+
// src/services/parser/rule/parsePercentage.ts
|
|
2040
1868
|
const parsePercentage = (state, parse) => {
|
|
2041
1869
|
const node = parse(state, "Unary");
|
|
2042
1870
|
if (state.error !== null || !checkIsToken(state, "%")) return node;
|
|
@@ -2051,8 +1879,7 @@ const parsePercentage = (state, parse) => {
|
|
|
2051
1879
|
type: "percentage"
|
|
2052
1880
|
};
|
|
2053
1881
|
};
|
|
2054
|
-
|
|
2055
|
-
//#region src/services/parser/rule/parsePower.ts
|
|
1882
|
+
// src/services/parser/rule/parsePower.ts
|
|
2056
1883
|
const parsePower = (state, parse) => {
|
|
2057
1884
|
const base = parse(state, "Nullish");
|
|
2058
1885
|
const name = getOwnValue(MathExpressionOperatorMap["Power"], state.token);
|
|
@@ -2061,8 +1888,7 @@ const parsePower = (state, parse) => {
|
|
|
2061
1888
|
const exponent = parse(state, "Unary");
|
|
2062
1889
|
return createBinaryNode(base, name, exponent);
|
|
2063
1890
|
};
|
|
2064
|
-
|
|
2065
|
-
//#region src/services/parser/computeNumberLiteral.ts
|
|
1891
|
+
// src/services/parser/computeNumberLiteral.ts
|
|
2066
1892
|
const computeNumberLiteral = (token) => {
|
|
2067
1893
|
const radixEntry = MathExpressionRadixMap[token.charAt(1)];
|
|
2068
1894
|
if (!token.startsWith("0") || radixEntry === void 0) return Number(token);
|
|
@@ -2081,26 +1907,22 @@ const computeNumberLiteral = (token) => {
|
|
|
2081
1907
|
if (value > 2 ** bits - 1) return null;
|
|
2082
1908
|
return value >= 2 ** (bits - 1) ? value - 2 ** bits : value;
|
|
2083
1909
|
};
|
|
2084
|
-
|
|
2085
|
-
//#region src/services/parser/getArgumentCountText.ts
|
|
1910
|
+
// src/services/parser/getArgumentCountText.ts
|
|
2086
1911
|
const getArgumentCountText = (count) => `${count} ${count === 1 ? "argument" : "arguments"}`;
|
|
2087
|
-
|
|
2088
|
-
//#region src/services/parser/getMathExpressionArityMessage.ts
|
|
1912
|
+
// src/services/parser/getMathExpressionArityMessage.ts
|
|
2089
1913
|
const getMathExpressionArityMessage = (name, minArity, maxArity) => {
|
|
2090
1914
|
if (maxArity === Number.POSITIVE_INFINITY) return `"${name}" takes at least ${getArgumentCountText(minArity)}`;
|
|
2091
1915
|
if (minArity === maxArity) return `"${name}" takes ${getArgumentCountText(minArity)}`;
|
|
2092
1916
|
return `"${name}" takes ${minArity} or ${maxArity} arguments`;
|
|
2093
1917
|
};
|
|
2094
|
-
|
|
2095
|
-
//#region src/services/parser/getMathExpressionSignatureError.ts
|
|
1918
|
+
// src/services/parser/getMathExpressionSignatureError.ts
|
|
2096
1919
|
const getMathExpressionSignatureError = (name, signatures, parameterTypes) => {
|
|
2097
1920
|
const count = parameterTypes.length;
|
|
2098
1921
|
if (signatures.filter((signature) => count >= signature.minArity && count <= signature.maxArity).length === 0) return getMathExpressionArityMessage(name, Math.min(...signatures.map((signature) => signature.minArity)), Math.max(...signatures.map((signature) => signature.maxArity)));
|
|
2099
1922
|
if (parameterTypes.includes("list")) return `"${name}" does not take a list argument`;
|
|
2100
1923
|
return `"${name}" takes a list argument`;
|
|
2101
1924
|
};
|
|
2102
|
-
|
|
2103
|
-
//#region src/services/parser/parseSequence.ts
|
|
1925
|
+
// src/services/parser/parseSequence.ts
|
|
2104
1926
|
const parseSequence = (state, closing, parseItem) => {
|
|
2105
1927
|
const nodes = [];
|
|
2106
1928
|
if (checkIsToken(state, closing)) return nodes;
|
|
@@ -2112,8 +1934,7 @@ const parseSequence = (state, closing, parseItem) => {
|
|
|
2112
1934
|
if (state.error === null && !checkIsToken(state, closing)) failMathExpression(state, closing === ")" ? "Parenthesis ) expected" : "Parenthesis ] expected");
|
|
2113
1935
|
return nodes;
|
|
2114
1936
|
};
|
|
2115
|
-
|
|
2116
|
-
//#region src/services/parser/parseList.ts
|
|
1937
|
+
// src/services/parser/parseList.ts
|
|
2117
1938
|
const parseList = (state, parse) => {
|
|
2118
1939
|
getMathExpressionToken(state);
|
|
2119
1940
|
const elements = parseSequence(state, "]", (item) => parse(item, "Assignment"));
|
|
@@ -2124,11 +1945,9 @@ const parseList = (state, parse) => {
|
|
|
2124
1945
|
type: "list"
|
|
2125
1946
|
};
|
|
2126
1947
|
};
|
|
2127
|
-
|
|
2128
|
-
//#region src/services/parser/parseArgument.ts
|
|
1948
|
+
// src/services/parser/parseArgument.ts
|
|
2129
1949
|
const parseArgument = (state, parse) => checkIsToken(state, "[") ? parseList(state, parse) : parse(state, "Assignment");
|
|
2130
|
-
|
|
2131
|
-
//#region src/services/parser/parseCall.ts
|
|
1950
|
+
// src/services/parser/parseCall.ts
|
|
2132
1951
|
const parseCall = (state, name, column, parse) => {
|
|
2133
1952
|
const signatures = getMathExpressionSignatures(name);
|
|
2134
1953
|
if (signatures === void 0) {
|
|
@@ -2150,8 +1969,7 @@ const parseCall = (state, name, column, parse) => {
|
|
|
2150
1969
|
type: "call"
|
|
2151
1970
|
};
|
|
2152
1971
|
};
|
|
2153
|
-
|
|
2154
|
-
//#region src/services/parser/rule/parseSymbol.ts
|
|
1972
|
+
// src/services/parser/rule/parseSymbol.ts
|
|
2155
1973
|
const parseSymbol = (state, parse) => {
|
|
2156
1974
|
if (state.tokenType === "number") {
|
|
2157
1975
|
const value = computeNumberLiteral(state.token);
|
|
@@ -2191,8 +2009,7 @@ const parseSymbol = (state, parse) => {
|
|
|
2191
2009
|
failMathExpression(state, checkIsToken(state, "") ? "Unexpected end of expression" : "Value expected");
|
|
2192
2010
|
return PLACEHOLDER;
|
|
2193
2011
|
};
|
|
2194
|
-
|
|
2195
|
-
//#region src/services/parser/rule/parseUnary.ts
|
|
2012
|
+
// src/services/parser/rule/parseUnary.ts
|
|
2196
2013
|
const parseUnary = (state, parse) => {
|
|
2197
2014
|
const name = getOwnValue(MathExpressionOperatorMap["Unary"], state.token);
|
|
2198
2015
|
if (name === void 0) return parse(state, "Power");
|
|
@@ -2207,8 +2024,7 @@ const parseUnary = (state, parse) => {
|
|
|
2207
2024
|
type: "unary"
|
|
2208
2025
|
};
|
|
2209
2026
|
};
|
|
2210
|
-
|
|
2211
|
-
//#region src/services/parser/MathExpressionRuleParserMap.ts
|
|
2027
|
+
// src/services/parser/MathExpressionRuleParserMap.ts
|
|
2212
2028
|
const MathExpressionRuleParserMap = {
|
|
2213
2029
|
["Assignment"]: parseAssignment,
|
|
2214
2030
|
["Binary"]: parseBinary,
|
|
@@ -2222,11 +2038,9 @@ const MathExpressionRuleParserMap = {
|
|
|
2222
2038
|
["Symbol"]: parseSymbol,
|
|
2223
2039
|
["Unary"]: parseUnary
|
|
2224
2040
|
};
|
|
2225
|
-
|
|
2226
|
-
//#region src/services/parser/parseMathExpressionRule.ts
|
|
2041
|
+
// src/services/parser/parseMathExpressionRule.ts
|
|
2227
2042
|
const parseMathExpressionRule = (state, rule) => MathExpressionRuleParserMap[rule](state, parseMathExpressionRule);
|
|
2228
|
-
|
|
2229
|
-
//#region src/services/parser/parseMathExpression.ts
|
|
2043
|
+
// src/services/parser/parseMathExpression.ts
|
|
2230
2044
|
const parseMathExpression = (formula) => {
|
|
2231
2045
|
const state = {
|
|
2232
2046
|
depth: 0,
|
|
@@ -2242,5 +2056,4 @@ const parseMathExpression = (formula) => {
|
|
|
2242
2056
|
if (state.error === null && !checkIsToken(state, "")) failMathExpression(state, state.tokenType === "delimiter" ? `Unexpected operator ${state.token}` : `Unexpected part "${state.token}"`);
|
|
2243
2057
|
return state.error === null ? ok(node) : err(state.error);
|
|
2244
2058
|
};
|
|
2245
|
-
//#endregion
|
|
2246
2059
|
export { ADDITIVE_NAMES, BERNOULLI_CLOSED_FORM_INDEX, DECIMAL_MARK_OPERATOR_FOLLOWERS, DELIMITERS_OF_ONE, DELIMITERS_OF_THREE, DELIMITERS_OF_TWO, EULER_MACLAURIN_COEFFICIENTS, FIRST_CHARACTERS_OF_THREE, FIRST_CHARACTERS_OF_TWO, HIGH_TAIL_COEFFICIENTS, LAST_FACTORIAL_ARGUMENT, LOW_TAIL_COEFFICIENTS, MATH_EXPRESSION_ABSOLUTE_TOLERANCE, MATH_EXPRESSION_RELATIVE_TOLERANCE, MAXIMUM_DIGITS, MAXIMUM_STIRLING_WORK, MAX_MATH_EXPRESSION_DEPTH, MILLER_RABIN_BASES, MathExpressionBinaryOperatorMap, MathExpressionBitwiseAbsorptionMap, MathExpressionConstantMap, MathExpressionError, MathExpressionFunctionMap, MathExpressionFunctionName, MathExpressionGrammarRule, MathExpressionLogicalOperator, MathExpressionNodeCompileMap, MathExpressionNodeType, MathExpressionOperatorMap, MathExpressionParameterType, MathExpressionRadixMap, MathExpressionRuleParserMap, MathExpressionTokenType, NAMED_DELIMITERS, NO_LOCALS, NO_VALUES, OVERFLOW_ARGUMENT, PLACEHOLDER, REFINEMENT_STEPS, SQRT_PI, STIRLING_TERMS, STIRLING_THRESHOLD, SUMMATION_LIMIT, WORD_CHARACTER_REGEX, WORD_START_REGEX, checkCanMathExpressionNest, checkIsDecimalMark, checkIsDigitCharacter, checkIsLarger, checkIsMatching, checkIsMatchingKind, checkIsMillerRabinPassing, checkIsNameToken, checkIsNearlyEqual, checkIsOperatorOperand, checkIsPercentageExpression, checkIsPrime, checkIsSignedNumber, checkIsSmaller, checkIsToken, checkIsTruthy, checkIsUnaryStart, checkIsWordCharacter, checkIsWordStartCharacter, collectMathExpressionAssignedNames, compareNumbers, compileArgument, compileAssignment, compileBinary, compileCall, compileComparison, compileConditional, compileGroup, compileList, compileListNode, compileLogical, compileMathExpression, compileMathExpressionNode, compileName, compileNumber, compilePercentage, compileUnary, computeBellNumber, computeBernoulliNumber, computeBitwiseAnd, computeBitwiseOr, computeCatalan, computeCombinations, computeComparison, computeCompositions, computeCorrelation, computeDeterminant, computeDistance, computeDotProduct, computeErf, computeErfInverse, computeExtreme, computeFactorial, computeGamma, computeGreatestCommonDivisor, computeHypotenuse, computeInitialGuess, computeIntegerGreatestCommonDivisor, computeInverseCoth, computeKullbackLeibler, computeLeastCommonMultiple, computeListComparison, computeLogGamma, computeLogGammaOfPositive, computeLogarithm, computeMean, computeMedian, computeMedianAbsoluteDeviation, computeModularInverse, computeModularPower, computeModulo, computeMultinomial, computeNorm, computeNthRoot, computeNumberLiteral, computePartitionSelect, computePermutations, computePointToLine2D, computePointToLine3D, computePolynomial, computeProduct, computeProductOfRange, computeQuantile, computeStirlingColumn, computeStirlingDiagonal, computeStirlingLogGamma, computeStirlingSecondKind, computeSum, computeSummedZeta, computeTruthyCount, computeVariance, computeVectorNorm, computeZeta, createBinaryNode, createBinaryOperation, createBinarySignatures, createBitwiseFold, createBitwisePair, createDigitSignatures, createExtremeSignatures, createIdentitySignatures, createIntegerBinarySignatures, createIntegerUnarySignatures, createListFirstCompute, createListPairCompute, createListPairSignature, createListSignature, createLogicalNode, createNonEmptyCompute, createNumberSignature, createNumericCompute, createOrderedListSignatures, createRangedSignatures, createSignature, createSingletonListSignature, createSpreadSignatures, createUnarySignatures, createVariadicSignatures, failExponent, failMathExpression, failMathExpressionAt, getArgumentCountText, getMathExpressionArityMessage, getMathExpressionCharacter, getMathExpressionChildren, getMathExpressionColumn, getMathExpressionConstant, getMathExpressionNames, getMathExpressionOuterValue, getMathExpressionParameterType, getMathExpressionScalarCompute, getMathExpressionSignatureError, getMathExpressionSignatures, getMathExpressionToken, getOwnValue, getParameterType, matchMathExpressionSignature, multiplyPair, parseArgument, parseAssignment, parseBinary, parseBinaryOperators, parseCall, parseConditional, parseDivisionBeforeProduct, parseImplicitProduct, parseLeftHand, parseList, parseMathExpression, parseMathExpressionRule, parseNullish, parsePercentage, parsePower, parseSequence, parseSymbol, parseUnary, readMathExpressionDelimiter, readMathExpressionNumber, readMathExpressionWord, readRadixNumber, roundToDigits, scaleList, shiftDecimalPlaces, skipMathExpressionSpaces, takeExponent, takeMathExpressionMatching, toNumber, walkNode };
|