nerdamer 2.0.0-rc.1 → 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/BREAKING_CHANGES.md +244 -0
- package/README.md +168 -229
- package/dist/bundle.js +1 -1
- package/dist/bundle.js.LICENSE.txt +6 -6
- package/output/algebra/adapters.d.ts +3 -33
- package/output/algebra/adapters.js +7 -105
- package/output/algebra/algorithms/arith.js +10 -9
- package/output/algebra/algorithms/groebnerBase.d.ts +24 -20
- package/output/algebra/algorithms/groebnerBase.js +486 -723
- package/output/algebra/dispatch.d.ts +1 -0
- package/output/algebra/dispatch.js +25 -0
- package/output/algebra/factor/factor.d.ts +15 -0
- package/output/algebra/factor/factor.js +99 -12
- package/output/algebra/gcd/gcd.d.ts +8 -7
- package/output/algebra/gcd/gcd.js +32 -78
- package/output/algebra/groebner.d.ts +2 -2
- package/output/algebra/groebner.js +6 -12
- package/output/algebra/partfrac.d.ts +3 -3
- package/output/algebra/partfrac.js +28 -61
- package/output/algebra/polynomial/ModularSparsePolynomial.d.ts +131 -0
- package/output/algebra/polynomial/ModularSparsePolynomial.js +378 -0
- package/output/algebra/polynomial/ModularSparsePolynomialFactor.d.ts +40 -0
- package/output/algebra/polynomial/ModularSparsePolynomialFactor.js +661 -0
- package/output/algebra/polynomial/SparsePolynomialFactor.d.ts +64 -0
- package/output/algebra/polynomial/SparsePolynomialFactor.js +492 -0
- package/output/algebra/polynomial/SparsePolynomialGcd.d.ts +29 -0
- package/output/algebra/polynomial/SparsePolynomialGcd.js +259 -0
- package/output/algebra/polynomial/SparsePolynomialMultivariateFactor.d.ts +82 -0
- package/output/algebra/polynomial/SparsePolynomialMultivariateFactor.js +604 -0
- package/output/algebra/polynomial/modularGcd.d.ts +40 -0
- package/output/algebra/polynomial/modularGcd.js +365 -0
- package/output/algebra/polynomialize.js +4 -2
- package/output/algebra/simplify/funcsimp.js +1 -1
- package/output/algebra/simplify/ratsimp.js +1 -1
- package/output/algebra/simplify/simplify.js +11 -2
- package/output/algebra/utils.d.ts +1 -1
- package/output/algebra/utils.js +3 -3
- package/output/api/advanced.d.ts +2 -1
- package/output/api/advanced.js +3 -3
- package/output/api/algebra.d.ts +21 -4
- package/output/api/algebra.js +22 -3
- package/output/api/assumptions.d.ts +1 -1
- package/output/api/assumptions.js +2 -1
- package/output/api/calculus.d.ts +2 -1
- package/output/api/calculus.js +2 -1
- package/output/api/core.d.ts +28 -7
- package/output/api/core.js +28 -2
- package/output/api/languages/deu.d.ts +3 -0
- package/output/api/languages/deu.js +266 -0
- package/output/api/languages/fra.d.ts +3 -0
- package/output/api/languages/fra.js +266 -0
- package/output/api/languages/ita.d.ts +3 -0
- package/output/api/languages/ita.js +266 -0
- package/output/api/languages/nld.d.ts +3 -0
- package/output/api/languages/nld.js +266 -0
- package/output/api/languages/por.d.ts +3 -0
- package/output/api/languages/por.js +266 -0
- package/output/api/languages/spa.d.ts +3 -0
- package/output/api/languages/spa.js +266 -0
- package/output/api/parser.d.ts +10 -2
- package/output/api/parser.js +2 -0
- package/output/api/solve.d.ts +1 -1
- package/output/api/solve.js +2 -1
- package/output/api/structures.d.ts +1 -1
- package/output/api/structures.js +2 -1
- package/output/calculus/adapters.d.ts +8 -0
- package/output/calculus/adapters.js +41 -0
- package/output/calculus/derivative/diff.js +6 -3
- package/output/calculus/dispatch.d.ts +1 -0
- package/output/calculus/dispatch.js +25 -0
- 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/Assumption.js +14 -10
- package/output/core/classes/assumption/assume.d.ts +6 -0
- package/output/core/classes/assumption/assume.js +9 -0
- package/output/core/classes/assumption/dispatch.d.ts +1 -0
- package/output/core/classes/assumption/dispatch.js +11 -0
- package/output/core/classes/collection/Collection.js +11 -2
- package/output/core/classes/complex/Complex.d.ts +10 -0
- package/output/core/classes/complex/Complex.js +19 -1
- package/output/core/classes/decimalSet/DecimalSet.js +5 -4
- package/output/core/classes/dictionary/Dictionary.js +4 -1
- package/output/core/classes/expression/CoeffObject.d.ts +1 -1
- package/output/core/classes/expression/CoeffObject.js +1 -2
- package/output/core/classes/expression/Expression.d.ts +35 -26
- package/output/core/classes/expression/Expression.js +77 -50
- package/output/core/classes/expression/analysis.d.ts +1 -1
- package/output/core/classes/expression/analysis.js +7 -7
- package/output/core/classes/expression/format.d.ts +9 -0
- package/output/core/classes/expression/format.js +130 -7
- package/output/core/classes/expression/utils.d.ts +9 -0
- package/output/core/classes/expression/utils.js +52 -6
- package/output/core/classes/matrix/Matrix.d.ts +2 -3
- package/output/core/classes/matrix/Matrix.js +26 -23
- package/output/core/classes/matrix/dispatch.d.ts +1 -0
- package/output/core/classes/matrix/dispatch.js +19 -0
- package/output/core/classes/matrix/functions.d.ts +2 -0
- package/output/core/classes/matrix/functions.js +5 -0
- package/output/core/classes/parser/Parser.d.ts +31 -5
- package/output/core/classes/parser/Parser.js +357 -444
- package/output/core/classes/parser/constants.d.ts +2 -0
- package/output/core/classes/parser/constants.js +4 -2
- package/output/core/classes/parser/controlFlowSignals.d.ts +38 -0
- package/output/core/classes/parser/controlFlowSignals.js +60 -0
- package/output/core/classes/parser/operations/add.js +14 -16
- package/output/core/classes/parser/operations/compare.js +13 -0
- package/output/core/classes/parser/operations/functions.d.ts +3 -4
- package/output/core/classes/parser/operations/functions.js +48 -102
- package/output/core/classes/parser/operations/multiply.js +22 -15
- package/output/core/classes/parser/operations/power.js +11 -11
- package/output/core/classes/parser/operations/subtract.js +2 -1
- package/output/core/classes/parser/preprocess.d.ts +0 -7
- package/output/core/classes/parser/preprocess.js +33 -39
- package/output/core/classes/parser/scripting/controlFlow.d.ts +4 -102
- package/output/core/classes/parser/scripting/controlFlow.js +134 -186
- package/output/core/classes/parser/scripting/deferred.d.ts +4 -0
- package/output/core/classes/parser/scripting/deferred.js +65 -0
- package/output/core/classes/parser/scripting/dispatch.d.ts +1 -0
- package/output/core/classes/parser/scripting/dispatch.js +62 -0
- package/output/core/classes/parser/scripting/evaluate.d.ts +13 -0
- package/output/core/classes/parser/scripting/evaluate.js +17 -1
- package/output/core/classes/parser/scripting/scope.d.ts +1 -28
- package/output/core/classes/parser/scripting/scope.js +36 -40
- package/output/core/classes/parser/types.d.ts +5 -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.d.ts +5 -1
- package/output/core/classes/polynomial/Polynomial.js +53 -7
- package/output/core/classes/polynomial/SparsePolynomial.d.ts +221 -0
- package/output/core/classes/polynomial/SparsePolynomial.js +824 -0
- package/output/core/classes/polynomial/SparsePolynomialAdapter.d.ts +56 -0
- package/output/core/classes/polynomial/SparsePolynomialAdapter.js +241 -0
- package/output/core/classes/polynomial/Term.js +2 -2
- package/output/core/{adapters.d.ts → classes/polynomial/adapters.d.ts} +2 -2
- package/output/core/classes/polynomial/adapters.js +33 -0
- package/output/core/classes/polynomial/dispatch.d.ts +1 -0
- package/output/core/classes/polynomial/dispatch.js +14 -0
- package/output/core/classes/polynomial/functions.d.ts +8 -0
- package/output/core/classes/polynomial/functions.js +71 -8
- package/output/core/classes/polynomial/utils.js +2 -1
- package/output/core/classes/rational/Rational.d.ts +8 -11
- package/output/core/classes/rational/Rational.js +70 -20
- package/output/core/classes/seq/SEQ.js +4 -4
- package/output/core/classes/valuesSet/ValuesSet.d.ts +9 -1
- package/output/core/classes/valuesSet/ValuesSet.js +22 -4
- package/output/core/classes/vector/Vector.d.ts +2 -3
- package/output/core/classes/vector/Vector.js +11 -15
- package/output/core/classes/vector/dispatch.d.ts +1 -0
- package/output/core/classes/vector/dispatch.js +11 -0
- package/output/core/common/classes/MathematicalAggregate.js +11 -2
- package/output/core/common/classes/StructuredEntity.d.ts +0 -17
- package/output/core/common/classes/StructuredEntity.js +3 -64
- package/output/core/common/common.d.ts +0 -1
- package/output/core/common/common.js +29 -234
- package/output/core/converters/BaseConverter.js +3 -2
- package/output/core/converters/Converter.js +9 -5
- package/output/core/converters/Pattern.js +1 -1
- package/output/core/dispatch.d.ts +18 -0
- package/output/core/dispatch.js +3 -281
- package/output/core/errors.d.ts +259 -474
- package/output/core/errors.js +270 -542
- package/output/core/fullFunctions.d.ts +7 -0
- package/output/core/fullFunctions.js +31 -0
- package/output/core/functions/bigint/bigint.d.ts +13 -1
- package/output/core/functions/bigint/bigint.js +56 -4
- package/output/core/functions/bigint/primeFactor.d.ts +2 -0
- package/output/core/functions/bigint/primeFactor.js +13 -13
- package/output/core/functions/build/definitions.js +6 -0
- package/output/core/functions/complex.d.ts +2 -2
- package/output/core/functions/complex.dispatch.d.ts +1 -0
- package/output/core/functions/complex.dispatch.js +16 -0
- package/output/core/functions/complex.js +7 -7
- package/output/core/functions/decimal.js +2 -1
- package/output/core/functions/expand/expand.js +2 -2
- package/output/core/functions/numeric.d.ts +1 -1
- package/output/core/functions/string.js +2 -1
- package/output/core/functions/subst.js +21 -13
- package/output/core/parserFunctions.d.ts +7 -0
- package/output/core/parserFunctions.js +25 -0
- package/output/index.d.ts +50 -30
- package/output/index.js +147 -19
- package/output/math/defint/defint.d.ts +18 -0
- package/output/math/defint/defint.js +60 -0
- package/output/math/defint/defintDecimal.js +6 -5
- package/output/math/defint/defintNative.js +7 -18
- package/output/math/dispatch.d.ts +1 -0
- package/output/math/dispatch.js +101 -0
- package/output/math/geometry.d.ts +4 -0
- package/output/math/geometry.js +23 -0
- package/output/math/math.d.ts +59 -19
- package/output/math/math.js +244 -100
- package/output/math/trig.js +4 -4
- package/output/math/utils.d.ts +6 -0
- package/output/math/utils.js +39 -0
- package/output/solve/classes/PolynomialSolver.d.ts +33 -14
- package/output/solve/classes/PolynomialSolver.js +267 -67
- package/output/solve/classes/SolutionSet.d.ts +20 -1
- package/output/solve/classes/SolutionSet.js +82 -5
- package/output/solve/dispatch.d.ts +1 -0
- package/output/solve/dispatch.js +13 -0
- package/output/solve/linsolve.d.ts +2 -0
- package/output/solve/linsolve.js +13 -5
- package/output/solve/solve.d.ts +10 -0
- package/output/solve/solve.js +128 -20
- package/output/solve/solveSystem.d.ts +1 -1
- package/output/solve/solveSystem.js +8 -32
- package/output/solve/utils.d.ts +2 -1
- package/output/solve/utils.js +18 -22
- package/output/utils/array.d.ts +1 -1
- package/output/utils/debug.js +2 -1
- package/package.json +22 -38
- package/dist/parser.js +0 -2
- package/dist/parser.js.LICENSE.txt +0 -7
- package/docs-data/parser-functions.json +0 -1960
- package/output/algebra/algorithms/factor.d.ts +0 -3
- package/output/algebra/algorithms/factor.js +0 -5
- package/output/algebra/algorithms/factorMultivariate.d.ts +0 -23
- package/output/algebra/algorithms/factorMultivariate.js +0 -2393
- package/output/algebra/algorithms/factorUnivariate.d.ts +0 -72
- package/output/algebra/algorithms/factorUnivariate.js +0 -1072
- package/output/algebra/algorithms/gcd.d.ts +0 -22
- package/output/algebra/algorithms/gcd.js +0 -690
- package/output/algebra/algorithms/multiPoly/MultiPoly.d.ts +0 -137
- package/output/algebra/algorithms/multiPoly/MultiPoly.js +0 -346
- package/output/algebra/algorithms/poly.d.ts +0 -228
- package/output/algebra/algorithms/poly.js +0 -1299
- package/output/algebra/algorithms/rational.d.ts +0 -17
- package/output/algebra/algorithms/rational.js +0 -115
- package/output/core/adapters.js +0 -40
- package/output/core/classes/parser/operations/comma.d.ts +0 -7
- package/output/core/classes/parser/operations/comma.js +0 -11
|
@@ -47,9 +47,9 @@ function power(a, b) {
|
|
|
47
47
|
throw new errors_1.ZeroToZeroPowerError((0, errors_1.message)('zeroToZeroPower'));
|
|
48
48
|
}
|
|
49
49
|
if (Settings_1.Settings.DEFER_SIMPLIFICATION) {
|
|
50
|
-
retval =
|
|
50
|
+
retval = a.copy();
|
|
51
51
|
// Convert it to an EXP
|
|
52
|
-
retval = Expression_1.Expression.toEXP(retval,
|
|
52
|
+
retval = Expression_1.Expression.toEXP(retval, b.copy());
|
|
53
53
|
retval.deferred = true;
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
@@ -59,7 +59,7 @@ function power(a, b) {
|
|
|
59
59
|
}
|
|
60
60
|
// Handle e^(i*pi)
|
|
61
61
|
else if (a.isE() && b.isComplex()) {
|
|
62
|
-
const p =
|
|
62
|
+
const p = b.copy();
|
|
63
63
|
const m = p.getMultiplier();
|
|
64
64
|
delete p.multiplier;
|
|
65
65
|
if ((0, compare_1.equal)(p, `${Expression_1.Expression.imaginary}*${constants_1.PI[0]}`)) {
|
|
@@ -163,7 +163,7 @@ function power(a, b) {
|
|
|
163
163
|
retval = (0, shortcuts_1.one)();
|
|
164
164
|
}
|
|
165
165
|
else if (b.isOne()) {
|
|
166
|
-
retval =
|
|
166
|
+
retval = a.copy();
|
|
167
167
|
}
|
|
168
168
|
else if (a.isInf() || bIsInf) {
|
|
169
169
|
const aIsInf = a.isInf();
|
|
@@ -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
|
}
|
|
@@ -255,7 +255,7 @@ function power(a, b) {
|
|
|
255
255
|
retval = a.getBase().times(a.getMultiplier());
|
|
256
256
|
}
|
|
257
257
|
else {
|
|
258
|
-
retval =
|
|
258
|
+
retval = a.copy();
|
|
259
259
|
retval.power = p;
|
|
260
260
|
}
|
|
261
261
|
}
|
|
@@ -289,7 +289,7 @@ function power(a, b) {
|
|
|
289
289
|
// powers. Positive magnitude has already been extracted for symbolic
|
|
290
290
|
// bases, while numeric bases keep their exact magnitude in c.
|
|
291
291
|
if (root !== 1n && !a.isNUM() && a.getMultiplier().isNegative()) {
|
|
292
|
-
retval = Expression_1.Expression.toEXP(
|
|
292
|
+
retval = Expression_1.Expression.toEXP(a.copy(), b);
|
|
293
293
|
retval = retval.times(c);
|
|
294
294
|
retval = rationalizeRadical(retval);
|
|
295
295
|
}
|
|
@@ -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
|
}
|
|
@@ -542,7 +542,7 @@ function setPower(a, b) {
|
|
|
542
542
|
function sqrtToPow(x) {
|
|
543
543
|
let retval;
|
|
544
544
|
if (x.isFunction(constants_1.SQRT)) {
|
|
545
|
-
retval =
|
|
545
|
+
retval = x.getArguments()[0].copy();
|
|
546
546
|
// The the power. Pass in true to get it as a Expression
|
|
547
547
|
const pow = x.getPower();
|
|
548
548
|
// set the power
|
|
@@ -551,7 +551,7 @@ function sqrtToPow(x) {
|
|
|
551
551
|
retval.multiplier = x.getMultiplier().copy();
|
|
552
552
|
}
|
|
553
553
|
else {
|
|
554
|
-
retval =
|
|
554
|
+
retval = x.copy();
|
|
555
555
|
}
|
|
556
556
|
return retval;
|
|
557
557
|
}
|
|
@@ -573,7 +573,7 @@ function powToSqrt(x) {
|
|
|
573
573
|
retval.multiplier = x.getMultiplier().copy();
|
|
574
574
|
}
|
|
575
575
|
else {
|
|
576
|
-
retval =
|
|
576
|
+
retval = x.copy();
|
|
577
577
|
}
|
|
578
578
|
return retval;
|
|
579
579
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.subtract = subtract;
|
|
4
4
|
exports.subtractPrefix = subtractPrefix;
|
|
5
|
+
const errors_1 = require("../../../errors");
|
|
5
6
|
const Settings_1 = require("../../../Settings");
|
|
6
7
|
const Expression_1 = require("../../expression/Expression");
|
|
7
8
|
const add_1 = require("./add");
|
|
@@ -23,7 +24,7 @@ function subtract(a, b) {
|
|
|
23
24
|
retval = (0, add_1.add)(a, b.neg());
|
|
24
25
|
}
|
|
25
26
|
if (!retval) {
|
|
26
|
-
throw new Error(
|
|
27
|
+
throw new Error((0, errors_1.message)('subtractionNotDefined', { leftType: String(a.type), rightType: String(b.type), left: String(a), right: String(b) }));
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
return retval;
|
|
@@ -3,12 +3,5 @@ type FunctionMetadata = {
|
|
|
3
3
|
maxArgs: number;
|
|
4
4
|
};
|
|
5
5
|
type FunctionRegistry = Record<string, FunctionMetadata>;
|
|
6
|
-
/**
|
|
7
|
-
* Converts accepted parser shorthand to the ordinary notation consumed by the tokenizer.
|
|
8
|
-
* Paired-hash comments are removed before root-level semicolon sequences are mapped to the
|
|
9
|
-
* existing block construct and legacy bracketless function calls are normalized. Existing
|
|
10
|
-
* parenthesized calls are untouched; only a registered function followed by whitespace is
|
|
11
|
-
* considered a bracketless call.
|
|
12
|
-
*/
|
|
13
6
|
export declare function preprocess(input: string, functions: FunctionRegistry): string;
|
|
14
7
|
export {};
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.preprocess = preprocess;
|
|
4
4
|
const errors_1 = require("../../errors");
|
|
5
5
|
const BLOCK_FUNCTION = 'block';
|
|
6
|
-
const
|
|
6
|
+
const LET_FUNCTION = 'let';
|
|
7
7
|
function isIdentifierStart(character) {
|
|
8
8
|
return /[a-z_]/i.test(character);
|
|
9
9
|
}
|
|
@@ -29,29 +29,23 @@ function getNextSignificantCharacter(input, at) {
|
|
|
29
29
|
}
|
|
30
30
|
return input[index];
|
|
31
31
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Removes paired-hash comments before any other parser-input normalization occurs.
|
|
34
|
-
*
|
|
35
|
-
* A comment begins at `##` and ends at the next `##`. Comment contents are replaced
|
|
36
|
-
* with whitespace so adjacent tokens do not accidentally merge. A lone `#` is left
|
|
37
|
-
* untouched and retains its ordinary parser meaning.
|
|
38
|
-
*/
|
|
39
32
|
function normalizeComments(input) {
|
|
40
33
|
let retval = '';
|
|
41
34
|
let index = 0;
|
|
42
35
|
while (index < input.length) {
|
|
43
|
-
const opening = input.indexOf(
|
|
36
|
+
const opening = input.indexOf('#', index);
|
|
44
37
|
if (opening === -1) {
|
|
45
38
|
retval += input.slice(index);
|
|
46
39
|
break;
|
|
47
40
|
}
|
|
48
41
|
retval += input.slice(index, opening);
|
|
49
|
-
const
|
|
42
|
+
const delimiter = input.startsWith('##', opening) ? '##' : '#';
|
|
43
|
+
const closing = input.indexOf(delimiter, opening + delimiter.length);
|
|
50
44
|
if (closing === -1) {
|
|
51
|
-
throw new errors_1.ParserError(
|
|
45
|
+
throw new errors_1.ParserError((0, errors_1.message)('missingCommentDelimiter', { delimiter }));
|
|
52
46
|
}
|
|
53
47
|
retval += ' ';
|
|
54
|
-
index = closing +
|
|
48
|
+
index = closing + delimiter.length;
|
|
55
49
|
}
|
|
56
50
|
return retval;
|
|
57
51
|
}
|
|
@@ -59,10 +53,9 @@ function normalizeComments(input) {
|
|
|
59
53
|
* Normalizes semicolon statement syntax onto the parser's existing block sequencing.
|
|
60
54
|
*
|
|
61
55
|
* Root-level statement sequences become an implicit block. Inside an explicit block,
|
|
62
|
-
* semicolons separate block arguments just like
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* ordinary parser can reject syntax whose sequencing semantics have not been defined.
|
|
56
|
+
* semicolons separate block arguments just like commas. A statement sequence in LET's body is
|
|
57
|
+
* wrapped in an implicit block so the sequence remains one LET body argument rather than being
|
|
58
|
+
* mistaken for additional bindings. A trailing semicolon is discarded.
|
|
66
59
|
*/
|
|
67
60
|
function normalizeStatementSeparators(input) {
|
|
68
61
|
const scopes = [];
|
|
@@ -72,21 +65,33 @@ function normalizeStatementSeparators(input) {
|
|
|
72
65
|
const character = input[index];
|
|
73
66
|
if (character === '(' || character === '[' || character === '{') {
|
|
74
67
|
const closingBracket = character === '(' ? ')' : character === '[' ? ']' : '}';
|
|
68
|
+
retval += character;
|
|
75
69
|
scopes.push({
|
|
70
|
+
argumentStart: retval.length,
|
|
76
71
|
closingBracket,
|
|
77
72
|
functionName: character === '(' ? getPreviousIdentifier(input, index) : undefined,
|
|
78
73
|
});
|
|
79
|
-
retval += character;
|
|
80
74
|
continue;
|
|
81
75
|
}
|
|
82
76
|
if (character === ')' || character === ']' || character === '}') {
|
|
83
77
|
const currentScope = scopes[scopes.length - 1];
|
|
84
78
|
if (currentScope?.closingBracket === character) {
|
|
79
|
+
if (currentScope.statementBlockOpened) {
|
|
80
|
+
retval += ')';
|
|
81
|
+
}
|
|
85
82
|
scopes.pop();
|
|
86
83
|
}
|
|
87
84
|
retval += character;
|
|
88
85
|
continue;
|
|
89
86
|
}
|
|
87
|
+
if (character === ',') {
|
|
88
|
+
retval += character;
|
|
89
|
+
const currentScope = scopes[scopes.length - 1];
|
|
90
|
+
if (currentScope && !currentScope.statementBlockOpened) {
|
|
91
|
+
currentScope.argumentStart = retval.length;
|
|
92
|
+
}
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
90
95
|
if (character === ';') {
|
|
91
96
|
const nextCharacter = getNextSignificantCharacter(input, index + 1);
|
|
92
97
|
const currentScope = scopes[scopes.length - 1];
|
|
@@ -105,6 +110,16 @@ function normalizeStatementSeparators(input) {
|
|
|
105
110
|
else if (currentScope?.functionName === BLOCK_FUNCTION) {
|
|
106
111
|
retval += ',';
|
|
107
112
|
}
|
|
113
|
+
else if (currentScope?.functionName === LET_FUNCTION) {
|
|
114
|
+
if (!currentScope.statementBlockOpened) {
|
|
115
|
+
retval =
|
|
116
|
+
retval.slice(0, currentScope.argumentStart) +
|
|
117
|
+
`${BLOCK_FUNCTION}(` +
|
|
118
|
+
retval.slice(currentScope.argumentStart);
|
|
119
|
+
currentScope.statementBlockOpened = true;
|
|
120
|
+
}
|
|
121
|
+
retval += ',';
|
|
122
|
+
}
|
|
108
123
|
else {
|
|
109
124
|
retval += character;
|
|
110
125
|
}
|
|
@@ -117,11 +132,6 @@ function normalizeStatementSeparators(input) {
|
|
|
117
132
|
}
|
|
118
133
|
return retval;
|
|
119
134
|
}
|
|
120
|
-
/**
|
|
121
|
-
* Finds the right-most registered function that is separated from its argument by whitespace.
|
|
122
|
-
* Processing from the inside out lets nested input such as `sin sin x` normalize without
|
|
123
|
-
* introducing a separate parser mode.
|
|
124
|
-
*/
|
|
125
135
|
function findBracketlessFunction(input, functions) {
|
|
126
136
|
let retval;
|
|
127
137
|
let index = 0;
|
|
@@ -146,12 +156,8 @@ function findBracketlessFunction(input, functions) {
|
|
|
146
156
|
if (index < input.length) {
|
|
147
157
|
const firstArgumentCharacter = input[index];
|
|
148
158
|
const nextCharacter = input[index + 1] ?? '';
|
|
149
|
-
// Whitespace around an ordinary binary operator must not turn a registered
|
|
150
|
-
// function name used as a variable into a bracketless call. A sign glued to
|
|
151
|
-
// its operand remains valid prefix syntax, as in `sin -x`.
|
|
152
159
|
const startsWithOperatorBoundary = /[*/=<>:&|]/.test(firstArgumentCharacter) ||
|
|
153
|
-
((firstArgumentCharacter === '+' || firstArgumentCharacter === '-') &&
|
|
154
|
-
/\s/.test(nextCharacter));
|
|
160
|
+
((firstArgumentCharacter === '+' || firstArgumentCharacter === '-') && /\s/.test(nextCharacter));
|
|
155
161
|
if (!startsWithOperatorBoundary) {
|
|
156
162
|
retval = {
|
|
157
163
|
argumentStart: index,
|
|
@@ -171,11 +177,6 @@ function isOpeningBracket(character) {
|
|
|
171
177
|
function isClosingBracket(character) {
|
|
172
178
|
return character === ')' || character === ']' || character === '}';
|
|
173
179
|
}
|
|
174
|
-
/**
|
|
175
|
-
* Finds the end of one bracketless function application. Function application binds more
|
|
176
|
-
* tightly than ordinary binary arithmetic but less tightly than powers and postfix operators.
|
|
177
|
-
* Multi-argument functions keep comma-separated arguments in the same application.
|
|
178
|
-
*/
|
|
179
180
|
function findArgumentEnd(input, start, maxArgs, consumeStatement = false) {
|
|
180
181
|
let depth = 0;
|
|
181
182
|
let index = start;
|
|
@@ -234,13 +235,6 @@ function findArgumentEnd(input, start, maxArgs, consumeStatement = false) {
|
|
|
234
235
|
}
|
|
235
236
|
return index;
|
|
236
237
|
}
|
|
237
|
-
/**
|
|
238
|
-
* Converts accepted parser shorthand to the ordinary notation consumed by the tokenizer.
|
|
239
|
-
* Paired-hash comments are removed before root-level semicolon sequences are mapped to the
|
|
240
|
-
* existing block construct and legacy bracketless function calls are normalized. Existing
|
|
241
|
-
* parenthesized calls are untouched; only a registered function followed by whitespace is
|
|
242
|
-
* considered a bracketless call.
|
|
243
|
-
*/
|
|
244
238
|
function preprocess(input, functions) {
|
|
245
239
|
let retval = normalizeComments(input);
|
|
246
240
|
retval = normalizeStatementSeparators(retval);
|
|
@@ -1,121 +1,23 @@
|
|
|
1
1
|
import { Expression } from '../../expression/Expression';
|
|
2
2
|
import type { ParserEntity } from '../../../types';
|
|
3
3
|
import type { DeferredFunctionArgument } from '../types';
|
|
4
|
-
export
|
|
5
|
-
export declare
|
|
6
|
-
export declare
|
|
7
|
-
|
|
8
|
-
export declare abstract class ControlFlowSignal extends Error {
|
|
9
|
-
constructor();
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Internal control-flow signal used to carry a symbolic function's return value to its
|
|
13
|
-
* function boundary. It is not a mathematical parser result.
|
|
14
|
-
*/
|
|
15
|
-
export declare class ReturnSignal extends ControlFlowSignal {
|
|
16
|
-
readonly value: ParserEntity;
|
|
17
|
-
readonly dataType: typeof RETURN_SIGNAL;
|
|
18
|
-
constructor(value: ParserEntity);
|
|
19
|
-
static isReturnSignal(obj: unknown): obj is ReturnSignal;
|
|
20
|
-
}
|
|
21
|
-
/** Internal control-flow signal consumed by the nearest parser loop. */
|
|
22
|
-
export declare class BreakSignal extends ControlFlowSignal {
|
|
23
|
-
readonly dataType: typeof BREAK_SIGNAL;
|
|
24
|
-
static isBreakSignal(obj: unknown): obj is BreakSignal;
|
|
25
|
-
}
|
|
26
|
-
/** Internal control-flow signal consumed by the nearest parser loop. */
|
|
27
|
-
export declare class ContinueSignal extends ControlFlowSignal {
|
|
28
|
-
readonly dataType: typeof CONTINUE_SIGNAL;
|
|
29
|
-
static isContinueSignal(obj: unknown): obj is ContinueSignal;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Evaluates one symbolic-function body and consumes control flow at the function boundary.
|
|
33
|
-
* RETURN becomes the function result, while BREAK and CONTINUE cannot escape a function call.
|
|
34
|
-
*/
|
|
4
|
+
export { BREAK_SIGNAL, CONTINUE_SIGNAL, NULL_SIGNAL, RETURN_SIGNAL, BreakSignal, ContinueSignal, ControlFlowSignal, NullSignal, ReturnSignal, } from '../controlFlowSignals';
|
|
5
|
+
export declare function isInsideSymbolicFunction(): boolean;
|
|
6
|
+
export declare function shouldConsumeLocalReturn(): boolean;
|
|
7
|
+
export declare function withReturnPropagation(evaluate: () => ParserEntity): ParserEntity;
|
|
35
8
|
export declare function functionBoundary(evaluate: () => ParserEntity): ParserEntity;
|
|
36
|
-
/**
|
|
37
|
-
* Returns a value from the current symbolic function.
|
|
38
|
-
* @param x
|
|
39
|
-
* @returns
|
|
40
|
-
*/
|
|
41
9
|
export declare function RETURN(x: ParserEntity): never;
|
|
42
|
-
/** Exits the nearest parser control-flow loop. */
|
|
43
10
|
export declare function BREAK(): never;
|
|
44
|
-
/** Skips to the next iteration of the nearest parser control-flow loop. */
|
|
45
11
|
export declare function CONTINUE(): never;
|
|
46
|
-
/**
|
|
47
|
-
* Returns 1 when every deferred argument is nonzero, otherwise 0.
|
|
48
|
-
* Evaluation stops as soon as a false argument is found.
|
|
49
|
-
*/
|
|
50
12
|
export declare function AND(...args: DeferredFunctionArgument[]): Expression;
|
|
51
|
-
/**
|
|
52
|
-
* Returns 1 when at least one deferred argument is nonzero, otherwise 0.
|
|
53
|
-
* Evaluation stops as soon as a true argument is found.
|
|
54
|
-
*/
|
|
55
13
|
export declare function OR(...args: DeferredFunctionArgument[]): Expression;
|
|
56
|
-
/** Returns 1 when the argument is zero and 0 otherwise. */
|
|
57
14
|
export declare function NOT(value: ParserEntity): Expression;
|
|
58
|
-
/** Returns 1 when an odd number of arguments are nonzero, otherwise 0. */
|
|
59
15
|
export declare function XOR(...args: ParserEntity[]): Expression;
|
|
60
|
-
/**
|
|
61
|
-
* Evaluates an expression and returns its result unless evaluation throws an ordinary error.
|
|
62
|
-
* The fallback is evaluated only after an error. Internal parser control-flow signals continue
|
|
63
|
-
* unwinding to their enclosing function or loop boundary.
|
|
64
|
-
*/
|
|
65
16
|
export declare function IFERROR(expression: DeferredFunctionArgument, fallback: DeferredFunctionArgument): ParserEntity;
|
|
66
|
-
/**
|
|
67
|
-
* Returns 1 when deferred evaluation throws an ordinary error and 0 otherwise.
|
|
68
|
-
* Internal parser control-flow signals are not errors and continue unwinding normally.
|
|
69
|
-
*/
|
|
70
17
|
export declare function ISERROR(expression: DeferredFunctionArgument): Expression;
|
|
71
|
-
/**
|
|
72
|
-
* A branching function. Its arguments are deferred so only the selected branch is evaluated.
|
|
73
|
-
* When the false branch is omitted, a false condition produces the parser's empty result.
|
|
74
|
-
* @param condition
|
|
75
|
-
* @param branch1
|
|
76
|
-
* @param branch2
|
|
77
|
-
* @returns
|
|
78
|
-
*/
|
|
79
18
|
export declare function IF(condition: DeferredFunctionArgument, branch1: DeferredFunctionArgument, branch2?: DeferredFunctionArgument): ParserEntity;
|
|
80
|
-
/**
|
|
81
|
-
* Repeatedly evaluates a deferred body while a deferred condition is nonzero.
|
|
82
|
-
* The condition is reevaluated before every iteration. BREAK and CONTINUE are consumed here so
|
|
83
|
-
* they apply only to the nearest loop; other control-flow signals continue to unwind outward.
|
|
84
|
-
* The final completed body result is returned; if the body never completes, an empty Vector is
|
|
85
|
-
* returned.
|
|
86
|
-
* @param condition
|
|
87
|
-
* @param body
|
|
88
|
-
* @returns
|
|
89
|
-
*/
|
|
90
19
|
export declare function WHILE(condition: DeferredFunctionArgument, body: DeferredFunctionArgument): ParserEntity;
|
|
91
|
-
/**
|
|
92
|
-
* Evaluates a deferred initializer once, then delegates repeated condition and body evaluation
|
|
93
|
-
* to WHILE. The update runs after each completed body evaluation and also before a CONTINUE
|
|
94
|
-
* advances to the next condition check. BREAK and RETURN skip the pending update. The final
|
|
95
|
-
* completed body result is returned; if the body never completes, WHILE's empty-Vector result
|
|
96
|
-
* is preserved.
|
|
97
|
-
* @param initializer
|
|
98
|
-
* @param condition
|
|
99
|
-
* @param update
|
|
100
|
-
* @param body
|
|
101
|
-
* @returns
|
|
102
|
-
*/
|
|
103
20
|
export declare function FOR(initializer: DeferredFunctionArgument, condition: DeferredFunctionArgument, update: DeferredFunctionArgument, body: DeferredFunctionArgument): ParserEntity;
|
|
104
|
-
/**
|
|
105
|
-
* Evaluates a sequence of deferred parser commands in order.
|
|
106
|
-
* The final command's result is returned. Control-flow signals are not consumed here, allowing
|
|
107
|
-
* RETURN, BREAK, and CONTINUE to unwind to their enclosing function or loop boundary. An empty
|
|
108
|
-
* block retains the historical empty-vector result.
|
|
109
|
-
* @param args
|
|
110
|
-
* @returns
|
|
111
|
-
*/
|
|
112
21
|
export declare function BLOCK(...args: DeferredFunctionArgument[]): ParserEntity;
|
|
113
|
-
/**
|
|
114
|
-
* Evaluates one parser-dispatched function through the outer return boundary.
|
|
115
|
-
*
|
|
116
|
-
* Nested parser calls keep propagating RETURN. The outermost parser call consumes it when
|
|
117
|
-
* execution is not already inside a symbolic function.
|
|
118
|
-
*/
|
|
119
22
|
export declare function parserReturnBoundary(evaluate: () => ParserEntity): ParserEntity;
|
|
120
|
-
/** Evaluates BLOCK through the parser return boundary. */
|
|
121
23
|
export declare function parserBlock(...args: DeferredFunctionArgument[]): ParserEntity;
|