nerdamer 2.0.0-rc.2 → 2.0.0
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/README.md +11 -5
- package/dist/bundle.js +1 -1
- package/dist/bundle.js.LICENSE.txt +6 -6
- package/output/algebra/dispatch.js +1 -1
- package/output/algebra/partfrac.js +1 -1
- package/output/algebra/simplify/funcsimp.js +1 -1
- package/output/algebra/simplify/ratsimp.js +1 -1
- package/output/algebra/utils.d.ts +1 -1
- package/output/algebra/utils.js +3 -3
- package/output/api/algebra.d.ts +19 -2
- package/output/api/algebra.js +18 -2
- package/output/api/assumptions.d.ts +1 -1
- package/output/api/assumptions.js +2 -1
- package/output/api/core.d.ts +28 -7
- package/output/api/core.js +28 -2
- package/output/calculus/derivative/diff.js +1 -1
- package/output/calculus/dispatch.js +2 -2
- package/output/calculus/integrate/integrate.js +4 -4
- package/output/calculus/integrate/integrationTable.js +16 -16
- package/output/calculus/laplace/ilaplace.js +1 -1
- package/output/calculus/laplace/ilaplaceTable.js +18 -17
- package/output/calculus/laplace/laplaceTable.js +3 -2
- package/output/calculus/limit/limit.js +1 -1
- package/output/core/classes/assumption/assume.d.ts +6 -0
- package/output/core/classes/assumption/assume.js +9 -0
- package/output/core/classes/expression/CoeffObject.d.ts +1 -1
- package/output/core/classes/expression/Expression.d.ts +8 -16
- package/output/core/classes/expression/Expression.js +11 -33
- package/output/core/classes/matrix/Matrix.d.ts +2 -3
- package/output/core/classes/matrix/Matrix.js +7 -16
- package/output/core/classes/matrix/dispatch.js +1 -1
- package/output/core/classes/parser/Parser.d.ts +17 -4
- package/output/core/classes/parser/Parser.js +312 -450
- package/output/core/classes/parser/operations/functions.d.ts +3 -4
- package/output/core/classes/parser/operations/functions.js +35 -97
- package/output/core/classes/parser/operations/power.js +2 -2
- package/output/core/classes/parser/preprocess.js +14 -7
- package/output/core/classes/parser/scripting/controlFlow.js +49 -25
- package/output/core/classes/parser/scripting/deferred.d.ts +1 -1
- package/output/core/classes/parser/scripting/deferred.js +1 -1
- package/output/core/classes/parser/scripting/scope.js +38 -19
- package/output/core/classes/parser/types.d.ts +0 -5
- package/output/core/classes/parser/wrappers/IndexedReference.d.ts +4 -3
- package/output/core/classes/parser/wrappers/IndexedReference.js +8 -0
- package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +2 -2
- package/output/core/classes/polynomial/Polynomial.js +1 -1
- package/output/core/classes/polynomial/SparsePolynomial.d.ts +11 -11
- package/output/core/classes/polynomial/SparsePolynomial.js +65 -65
- package/output/core/classes/vector/Vector.d.ts +2 -3
- package/output/core/classes/vector/Vector.js +6 -14
- package/output/core/common/classes/StructuredEntity.d.ts +0 -17
- package/output/core/common/classes/StructuredEntity.js +3 -64
- package/output/core/converters/BaseConverter.js +2 -1
- package/output/core/fullFunctions.js +14 -14
- package/output/core/functions/bigint/bigint.d.ts +1 -1
- package/output/core/functions/numeric.d.ts +1 -1
- package/output/core/parserFunctions.js +10 -10
- package/output/index.d.ts +29 -29
- package/output/index.js +124 -20
- package/output/math/dispatch.js +1 -1
- package/output/math/math.js +21 -21
- package/output/math/trig.js +4 -4
- package/output/solve/solve.js +1 -1
- package/package.json +34 -15
- package/dist/parser.js +0 -2
- package/dist/parser.js.LICENSE.txt +0 -7
- package/docs-data/parser-functions.json +0 -2248
- package/output/core/classes/parser/operations/comma.d.ts +0 -7
- package/output/core/classes/parser/operations/comma.js +0 -11
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Equation } from '../../equation/Equation';
|
|
2
2
|
import { Matrix } from '../../matrix/Matrix';
|
|
3
3
|
import { Vector } from '../../vector/Vector';
|
|
4
|
-
import { comma } from './comma';
|
|
5
4
|
import type { ParserEntity } from '../../../types';
|
|
6
|
-
import type { Operation, PreFixFunction, PostFixFunction, EquationConstructorCall,
|
|
5
|
+
import type { Operation, PreFixFunction, PostFixFunction, EquationConstructorCall, DeferredFunctionArgument, DeferredOperation } from '../types';
|
|
7
6
|
/**
|
|
8
7
|
* The wrapper used to call functions within the parser.
|
|
9
8
|
*
|
|
@@ -16,7 +15,7 @@ export declare function callFunction(functionName: string, args: (ParserEntity |
|
|
|
16
15
|
* Combines all base operations into one object for parser.
|
|
17
16
|
*/
|
|
18
17
|
export declare const _: {
|
|
19
|
-
[functionName: string]: Operation | DeferredOperation | PreFixFunction | PostFixFunction | EquationConstructorCall
|
|
18
|
+
[functionName: string]: Operation | DeferredOperation | PreFixFunction | PostFixFunction | EquationConstructorCall;
|
|
20
19
|
};
|
|
21
20
|
/**
|
|
22
21
|
* Applies a scalar function over a copied Vector or Matrix while preserving its shape.
|
|
@@ -43,4 +42,4 @@ export declare function setEqual(a: ParserEntity, b: ParserEntity): Equation;
|
|
|
43
42
|
* @returns The registered function signature.
|
|
44
43
|
*/
|
|
45
44
|
export declare function functionAssign(a: ParserEntity, body: DeferredFunctionArgument): ParserEntity;
|
|
46
|
-
export declare function route(a: ParserEntity, b: ParserEntity, operation: string): ParserEntity
|
|
45
|
+
export declare function route(a: ParserEntity, b: ParserEntity, operation: string): ParserEntity;
|
|
@@ -7,7 +7,6 @@ exports.setEqual = setEqual;
|
|
|
7
7
|
exports.functionAssign = functionAssign;
|
|
8
8
|
exports.route = route;
|
|
9
9
|
const math_1 = require("../../../../math/math");
|
|
10
|
-
const structuredEntityUtils_1 = require("../../../common/functions/structuredEntityUtils");
|
|
11
10
|
const dispatch_1 = require("../../../dispatch");
|
|
12
11
|
const errors_1 = require("../../../errors");
|
|
13
12
|
const setFunction_1 = require("../../../functions/setFunction");
|
|
@@ -24,7 +23,6 @@ const controlFlow_1 = require("../scripting/controlFlow");
|
|
|
24
23
|
const functions_1 = require("../scripting/functions");
|
|
25
24
|
const scope_1 = require("../scripting/scope");
|
|
26
25
|
const add_1 = require("./add");
|
|
27
|
-
const comma_1 = require("./comma");
|
|
28
26
|
const divide_1 = require("./divide");
|
|
29
27
|
const multiply_1 = require("./multiply");
|
|
30
28
|
const power_1 = require("./power");
|
|
@@ -87,18 +85,15 @@ function callFunction(functionName, args) {
|
|
|
87
85
|
}
|
|
88
86
|
entityArgs.push(arg);
|
|
89
87
|
}
|
|
90
|
-
// A structured entity carrying symbolic bracket access represents one unresolved
|
|
91
|
-
// scalar value. Normalize it before equation checks, distribution, or invocation.
|
|
92
|
-
const normalizedArgs = entityArgs.map(arg => Expression_1.Expression.fromSymbolicAccess(arg) ?? arg);
|
|
93
88
|
if (attributes.level === 'system') {
|
|
94
|
-
for (let i = 0; i <
|
|
95
|
-
if (Equation_1.Equation.isEquation(
|
|
89
|
+
for (let i = 0; i < entityArgs.length; i++) {
|
|
90
|
+
if (Equation_1.Equation.isEquation(entityArgs[i]) && !equationArgs?.includes(i)) {
|
|
96
91
|
throw new errors_1.UnexpectedDataType((0, errors_1.message)('expressionExpected', { type: 'Equation' }));
|
|
97
92
|
}
|
|
98
93
|
}
|
|
99
94
|
}
|
|
100
95
|
const elementWiseArgs = distElWise
|
|
101
|
-
?
|
|
96
|
+
? entityArgs.filter((arg) => Vector_1.Vector.isVector(arg) || Matrix_1.Matrix.isMatrix(arg))
|
|
102
97
|
: [];
|
|
103
98
|
if (elementWiseArgs.length > 0) {
|
|
104
99
|
const structure = elementWiseArgs[0];
|
|
@@ -115,7 +110,7 @@ function callFunction(functionName, args) {
|
|
|
115
110
|
}
|
|
116
111
|
}
|
|
117
112
|
result = distribute((_element, i, j) => {
|
|
118
|
-
const scalarArgs =
|
|
113
|
+
const scalarArgs = entityArgs.map(arg => {
|
|
119
114
|
let scalarArg = arg;
|
|
120
115
|
if (Vector_1.Vector.isVector(arg)) {
|
|
121
116
|
scalarArg = arg.__get__([i]);
|
|
@@ -130,15 +125,15 @@ function callFunction(functionName, args) {
|
|
|
130
125
|
}
|
|
131
126
|
// Call and return
|
|
132
127
|
else if (!fn || Settings_1.Settings.DEFER_SIMPLIFICATION) {
|
|
133
|
-
result = Expression_1.Expression.toFunction(functionName,
|
|
128
|
+
result = Expression_1.Expression.toFunction(functionName, entityArgs);
|
|
134
129
|
}
|
|
135
130
|
else {
|
|
136
|
-
result = invokeMathFunction(fn,
|
|
131
|
+
result = invokeMathFunction(fn, entityArgs);
|
|
137
132
|
}
|
|
138
133
|
// Ensure that this function always returns even if it's a symbolic function. This will
|
|
139
134
|
// occur if the function didn't return a value.
|
|
140
135
|
if (!result) {
|
|
141
|
-
result = Expression_1.Expression.toFunction(functionName,
|
|
136
|
+
result = Expression_1.Expression.toFunction(functionName, entityArgs);
|
|
142
137
|
}
|
|
143
138
|
}
|
|
144
139
|
// Let all future calls know that an inferior precision was used.
|
|
@@ -164,7 +159,6 @@ exports._ = {
|
|
|
164
159
|
assertGTE: assertiveFunctions_1.assertGTE,
|
|
165
160
|
assertLT: assertiveFunctions_1.assertLT,
|
|
166
161
|
assertLTE: assertiveFunctions_1.assertLTE,
|
|
167
|
-
comma: comma_1.comma,
|
|
168
162
|
assign: scope_1.assign,
|
|
169
163
|
functionAssign: functionAssign,
|
|
170
164
|
setEqual: setEqual,
|
|
@@ -297,7 +291,7 @@ function percentage(a) {
|
|
|
297
291
|
if (!Expression_1.Expression.isExpression(a)) {
|
|
298
292
|
throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
|
|
299
293
|
}
|
|
300
|
-
const retval = a.div(100);
|
|
294
|
+
const retval = a.div(Expression_1.Expression.create(100));
|
|
301
295
|
return retval;
|
|
302
296
|
}
|
|
303
297
|
/**
|
|
@@ -318,25 +312,8 @@ function gte(a, b) {
|
|
|
318
312
|
function lte(a, b) {
|
|
319
313
|
return Expression_1.Expression.create(Number(a.lte(b)));
|
|
320
314
|
}
|
|
321
|
-
function isRoutedOperation(operation) {
|
|
322
|
-
return (operation === 'pow' ||
|
|
323
|
-
operation === 'times' ||
|
|
324
|
-
operation === 'div' ||
|
|
325
|
-
operation === 'minus' ||
|
|
326
|
-
operation === 'plus' ||
|
|
327
|
-
operation === 'eq' ||
|
|
328
|
-
operation === 'lt' ||
|
|
329
|
-
operation === 'lte' ||
|
|
330
|
-
operation === 'gt' ||
|
|
331
|
-
operation === 'gte');
|
|
332
|
-
}
|
|
333
|
-
function routeOperation(target, operand, operation) {
|
|
334
|
-
const retval = target[operation](operand);
|
|
335
|
-
return typeof retval === 'boolean' ? Expression_1.Expression.create(Number(retval)) : retval;
|
|
336
|
-
}
|
|
337
315
|
function dispatchDynamicOperation(a, b, operation) {
|
|
338
|
-
// Preserve the parser's historically loose dispatch for operator actions
|
|
339
|
-
// RoutedOperation. Tightening these actions may change existing runtime behavior.
|
|
316
|
+
// Preserve the parser's historically loose method dispatch for operator actions.
|
|
340
317
|
const useA = a.isEnumerable || Equation_1.Equation.isEquation(a);
|
|
341
318
|
const target = useA ? a : b;
|
|
342
319
|
const operand = useA ? b : a;
|
|
@@ -354,82 +331,43 @@ function route(a, b, operation) {
|
|
|
354
331
|
if (operation === 'assign') {
|
|
355
332
|
retval = (0, scope_1.assign)(a, b);
|
|
356
333
|
}
|
|
357
|
-
else if (operation === 'comma') {
|
|
358
|
-
retval = (0, comma_1.comma)(a, b);
|
|
359
|
-
}
|
|
360
334
|
else if (operation === 'in') {
|
|
361
335
|
// Membership is the infix form of contains(container, value), so reverse the operands.
|
|
362
336
|
retval = callFunction('contains', [b, a]);
|
|
363
337
|
}
|
|
364
|
-
else if (
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
338
|
+
else if (a.isEnumerable) {
|
|
339
|
+
retval = dispatchDynamicOperation(a, b, operation);
|
|
340
|
+
}
|
|
341
|
+
else if ((Vector_1.Vector.isVector(b) || Matrix_1.Matrix.isMatrix(b)) &&
|
|
342
|
+
(operation === 'minus' || operation === 'div' || operation === 'pow')) {
|
|
343
|
+
// Scalar-left operations are not commutative. Preserve operand order while
|
|
344
|
+
// distributing the operation over the structured right-hand operand.
|
|
345
|
+
if (!Expression_1.Expression.isExpression(a)) {
|
|
346
|
+
throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
|
|
347
|
+
}
|
|
348
|
+
// A scalar base with a Matrix exponent is a matrix-function question. It must
|
|
349
|
+
// not be reversed into Matrix.pow() or silently treated as element-wise power.
|
|
350
|
+
if (Matrix_1.Matrix.isMatrix(b) && operation === 'pow') {
|
|
351
|
+
throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
|
|
352
|
+
}
|
|
353
|
+
retval = distribute(element => {
|
|
354
|
+
let elementResult;
|
|
355
|
+
if (Expression_1.Expression.isExpression(element)) {
|
|
356
|
+
if (operation === 'minus') {
|
|
357
|
+
elementResult = (0, subtract_1.subtract)(a, element);
|
|
372
358
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
if (['plus', 'minus', 'times', 'div'].includes(operation)) {
|
|
376
|
-
retval = dispatchDynamicOperation(a, b, operation);
|
|
359
|
+
else if (operation === 'div') {
|
|
360
|
+
elementResult = (0, divide_1.divide)(a, element);
|
|
377
361
|
}
|
|
378
362
|
else {
|
|
379
|
-
|
|
363
|
+
elementResult = (0, power_1.power)(a, element);
|
|
380
364
|
}
|
|
381
365
|
}
|
|
382
|
-
else if (operation === 'plus' || operation === 'times') {
|
|
383
|
-
retval = dispatchDynamicOperation(a, b, operation);
|
|
384
|
-
}
|
|
385
366
|
else {
|
|
386
|
-
|
|
367
|
+
elementResult = route(a, element, operation);
|
|
387
368
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
retval = routeOperation(a, b, operation);
|
|
391
|
-
}
|
|
392
|
-
else if ((Vector_1.Vector.isVector(b) || Matrix_1.Matrix.isMatrix(b)) &&
|
|
393
|
-
(operation === 'minus' || operation === 'div' || operation === 'pow')) {
|
|
394
|
-
// Scalar-left operations are not commutative. Preserve operand order while
|
|
395
|
-
// distributing the operation over the structured right-hand operand.
|
|
396
|
-
if (!Expression_1.Expression.isExpression(a)) {
|
|
397
|
-
throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
|
|
398
|
-
}
|
|
399
|
-
// A scalar base with a Matrix exponent is a matrix-function question. It must
|
|
400
|
-
// not be reversed into Matrix.pow() or silently treated as element-wise power.
|
|
401
|
-
if (Matrix_1.Matrix.isMatrix(b) && operation === 'pow') {
|
|
402
|
-
throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
|
|
403
|
-
}
|
|
404
|
-
retval = distribute(element => {
|
|
405
|
-
let elementResult;
|
|
406
|
-
if (Expression_1.Expression.isExpression(element)) {
|
|
407
|
-
if (operation === 'minus') {
|
|
408
|
-
elementResult = (0, subtract_1.subtract)(a, element);
|
|
409
|
-
}
|
|
410
|
-
else if (operation === 'div') {
|
|
411
|
-
elementResult = (0, divide_1.divide)(a, element);
|
|
412
|
-
}
|
|
413
|
-
else {
|
|
414
|
-
elementResult = (0, power_1.power)(a, element);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
else {
|
|
418
|
-
const nestedResult = route(a, element, operation);
|
|
419
|
-
if (Array.isArray(nestedResult)) {
|
|
420
|
-
throw new errors_1.UnsupportedOperationError((0, errors_1.message)('unsupportedOperation'));
|
|
421
|
-
}
|
|
422
|
-
elementResult = nestedResult;
|
|
423
|
-
}
|
|
424
|
-
return elementResult;
|
|
425
|
-
}, b);
|
|
426
|
-
}
|
|
427
|
-
else if ((0, structuredEntityUtils_1.isEnumerable)(b)) {
|
|
428
|
-
retval = routeOperation(b, a, operation);
|
|
429
|
-
}
|
|
430
|
-
else {
|
|
431
|
-
retval = dispatchDynamicOperation(a, b, operation);
|
|
432
|
-
}
|
|
369
|
+
return elementResult;
|
|
370
|
+
}, b);
|
|
433
371
|
}
|
|
434
372
|
else {
|
|
435
373
|
retval = dispatchDynamicOperation(a, b, operation);
|
|
@@ -224,7 +224,7 @@ function power(a, b) {
|
|
|
224
224
|
let remainder = (0, shortcuts_1.one)();
|
|
225
225
|
let changed = false;
|
|
226
226
|
for (const element of a.elementsArray()) {
|
|
227
|
-
if (!element.isComplex() && element.gt(0)) {
|
|
227
|
+
if (!element.isComplex() && element.gt((0, shortcuts_1.zero)())) {
|
|
228
228
|
extracted = extracted.times(power(element, b));
|
|
229
229
|
changed = true;
|
|
230
230
|
}
|
|
@@ -512,7 +512,7 @@ function setPower(a, b) {
|
|
|
512
512
|
if (p.isNUM() &&
|
|
513
513
|
a.isEXP() &&
|
|
514
514
|
!a.getBase().isComplex() &&
|
|
515
|
-
a.getBase().gt(0) &&
|
|
515
|
+
a.getBase().gt((0, shortcuts_1.zero)()) &&
|
|
516
516
|
(0, complex_1.imagPart)(a.getPower()).isZero()) {
|
|
517
517
|
retval = power(a.getBase(), p).times(a.getMultiplier());
|
|
518
518
|
}
|
|
@@ -190,40 +190,47 @@ function findArgumentEnd(input, start, maxArgs, consumeStatement = false) {
|
|
|
190
190
|
continue;
|
|
191
191
|
}
|
|
192
192
|
if (isClosingBracket(character)) {
|
|
193
|
-
if (depth === 0)
|
|
193
|
+
if (depth === 0) {
|
|
194
194
|
break;
|
|
195
|
+
}
|
|
195
196
|
depth--;
|
|
196
197
|
previousSignificant = character;
|
|
197
198
|
continue;
|
|
198
199
|
}
|
|
199
200
|
if (depth > 0) {
|
|
200
|
-
if (!/\s/.test(character))
|
|
201
|
+
if (!/\s/.test(character)) {
|
|
201
202
|
previousSignificant = character;
|
|
203
|
+
}
|
|
202
204
|
continue;
|
|
203
205
|
}
|
|
204
206
|
if (consumeStatement) {
|
|
205
|
-
if (character === ',')
|
|
207
|
+
if (character === ',') {
|
|
206
208
|
break;
|
|
207
|
-
|
|
209
|
+
}
|
|
210
|
+
if (!/\s/.test(character)) {
|
|
208
211
|
previousSignificant = character;
|
|
212
|
+
}
|
|
209
213
|
continue;
|
|
210
214
|
}
|
|
211
215
|
if (/\s/.test(character)) {
|
|
212
|
-
if (multipleArguments && previousSignificant === ',')
|
|
216
|
+
if (multipleArguments && previousSignificant === ',') {
|
|
213
217
|
continue;
|
|
218
|
+
}
|
|
214
219
|
break;
|
|
215
220
|
}
|
|
216
221
|
if (character === ',') {
|
|
217
|
-
if (!multipleArguments)
|
|
222
|
+
if (!multipleArguments) {
|
|
218
223
|
break;
|
|
224
|
+
}
|
|
219
225
|
previousSignificant = character;
|
|
220
226
|
continue;
|
|
221
227
|
}
|
|
222
228
|
const isPrefixSign = (character === '+' || character === '-') &&
|
|
223
229
|
(index === start || previousSignificant === ',' || previousSignificant === '^');
|
|
224
230
|
const isBinaryBoundary = /[+\-*/=<>:&|]/.test(character) && !isPrefixSign;
|
|
225
|
-
if (isBinaryBoundary)
|
|
231
|
+
if (isBinaryBoundary) {
|
|
226
232
|
break;
|
|
233
|
+
}
|
|
227
234
|
previousSignificant = character;
|
|
228
235
|
}
|
|
229
236
|
return index;
|
|
@@ -73,14 +73,18 @@ function functionBoundary(evaluate) {
|
|
|
73
73
|
retval = evaluate();
|
|
74
74
|
}
|
|
75
75
|
catch (error) {
|
|
76
|
-
if (controlFlowSignals_1.ReturnSignal.isReturnSignal(error))
|
|
76
|
+
if (controlFlowSignals_1.ReturnSignal.isReturnSignal(error)) {
|
|
77
77
|
retval = error.value;
|
|
78
|
-
|
|
78
|
+
}
|
|
79
|
+
else if (controlFlowSignals_1.BreakSignal.isBreakSignal(error)) {
|
|
79
80
|
throw new errors_1.ParserError((0, errors_1.message)('breakOutsideLoop'));
|
|
80
|
-
|
|
81
|
+
}
|
|
82
|
+
else if (controlFlowSignals_1.ContinueSignal.isContinueSignal(error)) {
|
|
81
83
|
throw new errors_1.ParserError((0, errors_1.message)('continueOutsideLoop'));
|
|
82
|
-
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
83
86
|
throw error;
|
|
87
|
+
}
|
|
84
88
|
}
|
|
85
89
|
finally {
|
|
86
90
|
symbolicFunctionDepth--;
|
|
@@ -91,13 +95,15 @@ function RETURN(x) {
|
|
|
91
95
|
throw new controlFlowSignals_1.ReturnSignal(x);
|
|
92
96
|
}
|
|
93
97
|
function BREAK() {
|
|
94
|
-
if (loopBodyDepth === 0)
|
|
98
|
+
if (loopBodyDepth === 0) {
|
|
95
99
|
throw new errors_1.ParserError((0, errors_1.message)('breakOutsideLoop'));
|
|
100
|
+
}
|
|
96
101
|
throw BREAK_SIGNAL_INSTANCE;
|
|
97
102
|
}
|
|
98
103
|
function CONTINUE() {
|
|
99
|
-
if (loopBodyDepth === 0)
|
|
104
|
+
if (loopBodyDepth === 0) {
|
|
100
105
|
throw new errors_1.ParserError((0, errors_1.message)('continueOutsideLoop'));
|
|
106
|
+
}
|
|
101
107
|
throw CONTINUE_SIGNAL_INSTANCE;
|
|
102
108
|
}
|
|
103
109
|
function AND(...args) {
|
|
@@ -125,9 +131,11 @@ function NOT(value) {
|
|
|
125
131
|
}
|
|
126
132
|
function XOR(...args) {
|
|
127
133
|
let odd = false;
|
|
128
|
-
for (const arg of args)
|
|
129
|
-
if (isTruthy(arg))
|
|
134
|
+
for (const arg of args) {
|
|
135
|
+
if (isTruthy(arg)) {
|
|
130
136
|
odd = !odd;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
131
139
|
return odd ? (0, shortcuts_1.one)() : (0, shortcuts_1.zero)();
|
|
132
140
|
}
|
|
133
141
|
function IFERROR(expression, fallback) {
|
|
@@ -136,8 +144,9 @@ function IFERROR(expression, fallback) {
|
|
|
136
144
|
retval = expression();
|
|
137
145
|
}
|
|
138
146
|
catch (error) {
|
|
139
|
-
if (error instanceof controlFlowSignals_1.ControlFlowSignal)
|
|
147
|
+
if (error instanceof controlFlowSignals_1.ControlFlowSignal) {
|
|
140
148
|
throw error;
|
|
149
|
+
}
|
|
141
150
|
retval = fallback();
|
|
142
151
|
}
|
|
143
152
|
return retval;
|
|
@@ -148,8 +157,9 @@ function ISERROR(expression) {
|
|
|
148
157
|
expression();
|
|
149
158
|
}
|
|
150
159
|
catch (error) {
|
|
151
|
-
if (error instanceof controlFlowSignals_1.ControlFlowSignal)
|
|
160
|
+
if (error instanceof controlFlowSignals_1.ControlFlowSignal) {
|
|
152
161
|
throw error;
|
|
162
|
+
}
|
|
153
163
|
retval = (0, shortcuts_1.one)();
|
|
154
164
|
}
|
|
155
165
|
return retval;
|
|
@@ -161,11 +171,13 @@ function controlFlowReturnBoundary(evaluate) {
|
|
|
161
171
|
}
|
|
162
172
|
catch (error) {
|
|
163
173
|
if (parserReturnBoundaryDepth > 0 &&
|
|
164
|
-
|
|
165
|
-
controlFlowSignals_1.ReturnSignal.isReturnSignal(error))
|
|
174
|
+
shouldConsumeLocalReturn() &&
|
|
175
|
+
controlFlowSignals_1.ReturnSignal.isReturnSignal(error)) {
|
|
166
176
|
retval = error.value;
|
|
167
|
-
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
168
179
|
throw error;
|
|
180
|
+
}
|
|
169
181
|
}
|
|
170
182
|
return retval;
|
|
171
183
|
}
|
|
@@ -173,12 +185,15 @@ function IF(condition, branch1, branch2) {
|
|
|
173
185
|
return controlFlowReturnBoundary(() => {
|
|
174
186
|
const evaluatedCondition = condition();
|
|
175
187
|
let retval;
|
|
176
|
-
if (isTruthy(evaluatedCondition))
|
|
188
|
+
if (isTruthy(evaluatedCondition)) {
|
|
177
189
|
retval = branch1();
|
|
178
|
-
|
|
190
|
+
}
|
|
191
|
+
else if (branch2) {
|
|
179
192
|
retval = branch2();
|
|
180
|
-
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
181
195
|
return throwNullSignal();
|
|
196
|
+
}
|
|
182
197
|
return retval;
|
|
183
198
|
});
|
|
184
199
|
}
|
|
@@ -189,8 +204,9 @@ function WHILE(condition, body) {
|
|
|
189
204
|
let iterations = 0;
|
|
190
205
|
while (continueLoop) {
|
|
191
206
|
const evaluatedCondition = condition();
|
|
192
|
-
if (!isTruthy(evaluatedCondition))
|
|
207
|
+
if (!isTruthy(evaluatedCondition)) {
|
|
193
208
|
continueLoop = false;
|
|
209
|
+
}
|
|
194
210
|
else {
|
|
195
211
|
if (iterations >= Settings_1.Settings.MAX_LOOP_ITERATIONS) {
|
|
196
212
|
throw new errors_1.ParserError((0, errors_1.message)('loopIterationLimitExceeded', { max: String(Settings_1.Settings.MAX_LOOP_ITERATIONS) }));
|
|
@@ -203,10 +219,12 @@ function WHILE(condition, body) {
|
|
|
203
219
|
if (controlFlowSignals_1.NullSignal.isNullSignal(error)) {
|
|
204
220
|
// A loop body may legitimately complete without producing a value.
|
|
205
221
|
}
|
|
206
|
-
else if (controlFlowSignals_1.BreakSignal.isBreakSignal(error))
|
|
222
|
+
else if (controlFlowSignals_1.BreakSignal.isBreakSignal(error)) {
|
|
207
223
|
continueLoop = false;
|
|
208
|
-
|
|
224
|
+
}
|
|
225
|
+
else if (!controlFlowSignals_1.ContinueSignal.isContinueSignal(error)) {
|
|
209
226
|
throw error;
|
|
227
|
+
}
|
|
210
228
|
}
|
|
211
229
|
finally {
|
|
212
230
|
loopBodyDepth--;
|
|
@@ -230,8 +248,9 @@ function FOR(initializer, condition, update, body) {
|
|
|
230
248
|
}
|
|
231
249
|
catch (error) {
|
|
232
250
|
if (controlFlowSignals_1.ContinueSignal.isContinueSignal(error) ||
|
|
233
|
-
controlFlowSignals_1.NullSignal.isNullSignal(error))
|
|
251
|
+
controlFlowSignals_1.NullSignal.isNullSignal(error)) {
|
|
234
252
|
update();
|
|
253
|
+
}
|
|
235
254
|
throw error;
|
|
236
255
|
}
|
|
237
256
|
update();
|
|
@@ -240,20 +259,23 @@ function FOR(initializer, condition, update, body) {
|
|
|
240
259
|
});
|
|
241
260
|
}
|
|
242
261
|
function BLOCK(...args) {
|
|
243
|
-
if (args.length === 0)
|
|
262
|
+
if (args.length === 0) {
|
|
244
263
|
return throwNullSignal();
|
|
264
|
+
}
|
|
245
265
|
let retval;
|
|
246
266
|
for (const arg of args) {
|
|
247
267
|
try {
|
|
248
268
|
retval = arg();
|
|
249
269
|
}
|
|
250
270
|
catch (error) {
|
|
251
|
-
if (!controlFlowSignals_1.NullSignal.isNullSignal(error))
|
|
271
|
+
if (!controlFlowSignals_1.NullSignal.isNullSignal(error)) {
|
|
252
272
|
throw error;
|
|
273
|
+
}
|
|
253
274
|
}
|
|
254
275
|
}
|
|
255
|
-
if (retval === undefined)
|
|
276
|
+
if (retval === undefined) {
|
|
256
277
|
return throwNullSignal();
|
|
278
|
+
}
|
|
257
279
|
return retval;
|
|
258
280
|
}
|
|
259
281
|
function parserReturnBoundary(evaluate) {
|
|
@@ -264,10 +286,12 @@ function parserReturnBoundary(evaluate) {
|
|
|
264
286
|
retval = evaluate();
|
|
265
287
|
}
|
|
266
288
|
catch (error) {
|
|
267
|
-
if (consumesReturn && controlFlowSignals_1.ReturnSignal.isReturnSignal(error))
|
|
289
|
+
if (consumesReturn && controlFlowSignals_1.ReturnSignal.isReturnSignal(error)) {
|
|
268
290
|
retval = error.value;
|
|
269
|
-
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
270
293
|
throw error;
|
|
294
|
+
}
|
|
271
295
|
}
|
|
272
296
|
finally {
|
|
273
297
|
parserReturnBoundaryDepth--;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DeferredFunctionArgument } from '../types';
|
|
2
1
|
import type { ParserEntity } from '../../../types';
|
|
2
|
+
import type { DeferredFunctionArgument } from '../types';
|
|
3
3
|
/** Iterates parser containers while keeping iteration variables local to each body call. */
|
|
4
4
|
export declare function each(collection: DeferredFunctionArgument, variable: DeferredFunctionArgument, bodyOrValueVariable: DeferredFunctionArgument, dictionaryBody?: DeferredFunctionArgument): ParserEntity;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.each = each;
|
|
4
|
+
const errors_1 = require("../../../errors");
|
|
4
5
|
const Collection_1 = require("../../collection/Collection");
|
|
5
6
|
const Dictionary_1 = require("../../dictionary/Dictionary");
|
|
6
7
|
const Expression_1 = require("../../expression/Expression");
|
|
@@ -8,7 +9,6 @@ const shortcuts_1 = require("../../expression/shortcuts");
|
|
|
8
9
|
const Matrix_1 = require("../../matrix/Matrix");
|
|
9
10
|
const ValuesSet_1 = require("../../valuesSet/ValuesSet");
|
|
10
11
|
const Vector_1 = require("../../vector/Vector");
|
|
11
|
-
const errors_1 = require("../../../errors");
|
|
12
12
|
const constants_1 = require("../constants");
|
|
13
13
|
const controlFlow_1 = require("./controlFlow");
|
|
14
14
|
const scope_1 = require("./scope");
|
|
@@ -19,16 +19,20 @@ function assign(a, b) {
|
|
|
19
19
|
if (Expression_1.Expression.isExpression(a) && !a.isPlainVariable()) {
|
|
20
20
|
throw new errors_1.UnexpectedInputError((0, errors_1.message)('plainVariableExpected', { input: String(a) }));
|
|
21
21
|
}
|
|
22
|
-
if (Settings_1.RESTRICTED.includes(a.value))
|
|
22
|
+
if (Settings_1.RESTRICTED.includes(a.value)) {
|
|
23
23
|
throw new errors_1.AssignmentError((0, errors_1.message)('restrictedVariableName', { name: a.value }));
|
|
24
|
+
}
|
|
24
25
|
let value;
|
|
25
26
|
try {
|
|
26
|
-
if (typeof b === 'function')
|
|
27
|
+
if (typeof b === 'function') {
|
|
27
28
|
value = b();
|
|
28
|
-
|
|
29
|
+
}
|
|
30
|
+
else if (typeof b === 'string') {
|
|
29
31
|
value = Parser_1.Parser.parse(b);
|
|
30
|
-
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
31
34
|
value = b;
|
|
35
|
+
}
|
|
32
36
|
}
|
|
33
37
|
catch (error) {
|
|
34
38
|
if (controlFlowSignals_1.NullSignal.isNullSignal(error)) {
|
|
@@ -58,20 +62,24 @@ function normalizeLetArguments(argumentScopes) {
|
|
|
58
62
|
if (assignmentIndex > 0 && assignmentIndex < argumentScope.length - 1) {
|
|
59
63
|
const nameScope = new Scope_1.Scope(argumentScope.type, argumentScope.column);
|
|
60
64
|
const valueScope = new Scope_1.Scope(argumentScope.type, argumentScope.column);
|
|
61
|
-
for (let j = 0; j < assignmentIndex; j++)
|
|
65
|
+
for (let j = 0; j < assignmentIndex; j++) {
|
|
62
66
|
nameScope.push(argumentScope[j]);
|
|
63
|
-
|
|
67
|
+
}
|
|
68
|
+
for (let j = assignmentIndex + 1; j < argumentScope.length; j++) {
|
|
64
69
|
valueScope.push(argumentScope[j]);
|
|
70
|
+
}
|
|
65
71
|
normalizedScopes.push(nameScope, valueScope);
|
|
66
72
|
}
|
|
67
|
-
else
|
|
73
|
+
else {
|
|
68
74
|
normalizedScopes.push(argumentScope);
|
|
75
|
+
}
|
|
69
76
|
}
|
|
70
77
|
return normalizedScopes;
|
|
71
78
|
}
|
|
72
79
|
function LET(...args) {
|
|
73
|
-
if (args.length < 3 || args.length % 2 === 0)
|
|
80
|
+
if (args.length < 3 || args.length % 2 === 0) {
|
|
74
81
|
throw new errors_1.ParserError((0, errors_1.message)('letRequiresBindingsAndBody'));
|
|
82
|
+
}
|
|
75
83
|
const previousValues = new Map();
|
|
76
84
|
const previouslyUndefined = new Set();
|
|
77
85
|
const localNames = [];
|
|
@@ -85,30 +93,37 @@ function LET(...args) {
|
|
|
85
93
|
const name = (0, utils_1.assertPlainVariableAndGetString)(nameExpression);
|
|
86
94
|
const value = args[i + 1]({ excludeValues: localNames });
|
|
87
95
|
if (!previousValues.has(name) && !previouslyUndefined.has(name)) {
|
|
88
|
-
if (Object.prototype.hasOwnProperty.call(Parser_1.Parser.KNOWN_VALUES, name))
|
|
96
|
+
if (Object.prototype.hasOwnProperty.call(Parser_1.Parser.KNOWN_VALUES, name)) {
|
|
89
97
|
previousValues.set(name, Parser_1.Parser.KNOWN_VALUES[name]);
|
|
90
|
-
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
91
100
|
previouslyUndefined.add(name);
|
|
101
|
+
}
|
|
92
102
|
}
|
|
93
103
|
assign(nameExpression, value);
|
|
94
|
-
if (!localNames.includes(name))
|
|
104
|
+
if (!localNames.includes(name)) {
|
|
95
105
|
localNames.push(name);
|
|
106
|
+
}
|
|
96
107
|
}
|
|
97
108
|
try {
|
|
98
109
|
retval = args[args.length - 1]({ excludeValues: localNames });
|
|
99
110
|
}
|
|
100
111
|
catch (error) {
|
|
101
|
-
if ((0, controlFlow_1.shouldConsumeLocalReturn)() && controlFlow_1.ReturnSignal.isReturnSignal(error))
|
|
112
|
+
if ((0, controlFlow_1.shouldConsumeLocalReturn)() && controlFlow_1.ReturnSignal.isReturnSignal(error)) {
|
|
102
113
|
retval = error.value;
|
|
103
|
-
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
104
116
|
throw error;
|
|
117
|
+
}
|
|
105
118
|
}
|
|
106
119
|
}
|
|
107
120
|
finally {
|
|
108
|
-
for (const [name, value] of previousValues)
|
|
121
|
+
for (const [name, value] of previousValues) {
|
|
109
122
|
Parser_1.Parser.KNOWN_VALUES[name] = value;
|
|
110
|
-
|
|
123
|
+
}
|
|
124
|
+
for (const name of previouslyUndefined) {
|
|
111
125
|
delete Parser_1.Parser.KNOWN_VALUES[name];
|
|
126
|
+
}
|
|
112
127
|
}
|
|
113
128
|
return retval;
|
|
114
129
|
}
|
|
@@ -117,16 +132,20 @@ function unassign(x) {
|
|
|
117
132
|
let name;
|
|
118
133
|
if (typeof x === 'function') {
|
|
119
134
|
const parsed = x({ inheritValues: false, substitute: false });
|
|
120
|
-
if (!Expression_1.Expression.isExpression(parsed))
|
|
135
|
+
if (!Expression_1.Expression.isExpression(parsed)) {
|
|
121
136
|
throw new errors_1.UnexpectedInputError((0, errors_1.message)('plainVariableExpected', { input: parsed.text() }));
|
|
137
|
+
}
|
|
122
138
|
variable = parsed;
|
|
123
139
|
}
|
|
124
|
-
else
|
|
140
|
+
else {
|
|
125
141
|
variable = x;
|
|
126
|
-
|
|
142
|
+
}
|
|
143
|
+
if (Expression_1.Expression.isExpression(variable)) {
|
|
127
144
|
name = (0, utils_1.assertPlainVariableAndGetString)(variable);
|
|
128
|
-
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
129
147
|
name = variable;
|
|
148
|
+
}
|
|
130
149
|
delete Parser_1.Parser.KNOWN_VALUES[name];
|
|
131
150
|
return Expression_1.Expression.create(variable);
|
|
132
151
|
}
|
|
@@ -8,11 +8,6 @@ import type Decimal from 'decimal.js';
|
|
|
8
8
|
* The type used to defined a operation function for the parser
|
|
9
9
|
*/
|
|
10
10
|
export type Operation = (a: ParserEntity, b?: ParserEntity) => ParserEntity;
|
|
11
|
-
/**
|
|
12
|
-
* The comma operation returns both operands so the parser can place them back
|
|
13
|
-
* on the output stack as separate values.
|
|
14
|
-
*/
|
|
15
|
-
export type CommaOperation = (a: ParserStackValue, b: ParserStackValue) => ParserStackValue[];
|
|
16
11
|
/**
|
|
17
12
|
* The type used to defined a prefix for the parser
|
|
18
13
|
*/
|