nerdamer 1.1.13 → 2.0.0-rc.1
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/LICENSE.md +184 -0
- package/README.md +293 -312
- package/dist/bundle.js +2 -0
- package/dist/bundle.js.LICENSE.txt +7 -0
- package/dist/parser.js +2 -0
- package/dist/parser.js.LICENSE.txt +7 -0
- package/docs-data/parser-functions.json +1960 -0
- package/index.d.ts +10 -426
- package/output/algebra/adapters.d.ts +33 -0
- package/output/algebra/adapters.js +109 -0
- package/output/algebra/algorithms/arith.d.ts +84 -0
- package/output/algebra/algorithms/arith.js +323 -0
- package/output/algebra/algorithms/factor.d.ts +3 -0
- package/output/algebra/algorithms/factor.js +5 -0
- package/output/algebra/algorithms/factorMultivariate.d.ts +23 -0
- package/output/algebra/algorithms/factorMultivariate.js +2393 -0
- package/output/algebra/algorithms/factorUnivariate.d.ts +72 -0
- package/output/algebra/algorithms/factorUnivariate.js +1072 -0
- package/output/algebra/algorithms/gcd.d.ts +22 -0
- package/output/algebra/algorithms/gcd.js +690 -0
- package/output/algebra/algorithms/groebnerBase.d.ts +157 -0
- package/output/algebra/algorithms/groebnerBase.js +1166 -0
- package/output/algebra/algorithms/multiPoly/MultiPoly.d.ts +137 -0
- package/output/algebra/algorithms/multiPoly/MultiPoly.js +346 -0
- package/output/algebra/algorithms/poly.d.ts +228 -0
- package/output/algebra/algorithms/poly.js +1299 -0
- package/output/algebra/algorithms/rational.d.ts +17 -0
- package/output/algebra/algorithms/rational.js +115 -0
- package/output/algebra/factor/factor.d.ts +62 -0
- package/output/algebra/factor/factor.js +158 -0
- package/output/algebra/gcd/gcd.d.ts +29 -0
- package/output/algebra/gcd/gcd.js +141 -0
- package/output/algebra/groebner.d.ts +21 -0
- package/output/algebra/groebner.js +42 -0
- package/output/algebra/partfrac.d.ts +19 -0
- package/output/algebra/partfrac.js +398 -0
- package/output/algebra/polynomialize.d.ts +20 -0
- package/output/algebra/polynomialize.js +24 -0
- package/output/algebra/simplify/complexsimp.d.ts +7 -0
- package/output/algebra/simplify/complexsimp.js +24 -0
- package/output/algebra/simplify/factorCommon.d.ts +13 -0
- package/output/algebra/simplify/factorCommon.js +136 -0
- package/output/algebra/simplify/funcsimp.d.ts +26 -0
- package/output/algebra/simplify/funcsimp.js +633 -0
- package/output/algebra/simplify/invtrigrewrite.d.ts +10 -0
- package/output/algebra/simplify/invtrigrewrite.js +96 -0
- package/output/algebra/simplify/ratsimp.d.ts +21 -0
- package/output/algebra/simplify/ratsimp.js +140 -0
- package/output/algebra/simplify/simplify.d.ts +25 -0
- package/output/algebra/simplify/simplify.js +228 -0
- package/output/algebra/simplify/trigreduce.d.ts +38 -0
- package/output/algebra/simplify/trigreduce.js +424 -0
- package/output/algebra/simplify/trigrewrite.d.ts +17 -0
- package/output/algebra/simplify/trigrewrite.js +156 -0
- package/output/algebra/simplify/trigsimp.d.ts +11 -0
- package/output/algebra/simplify/trigsimp.js +369 -0
- package/output/algebra/simplify/utils.d.ts +32 -0
- package/output/algebra/simplify/utils.js +56 -0
- package/output/algebra/utils.d.ts +32 -0
- package/output/algebra/utils.js +48 -0
- package/output/api/advanced.d.ts +7 -0
- package/output/api/advanced.js +18 -0
- package/output/api/algebra.d.ts +17 -0
- package/output/api/algebra.js +32 -0
- package/output/api/assumptions.d.ts +4 -0
- package/output/api/assumptions.js +11 -0
- package/output/api/calculus.d.ts +9 -0
- package/output/api/calculus.js +21 -0
- package/output/api/core.d.ts +17 -0
- package/output/api/core.js +41 -0
- package/output/api/debug.d.ts +16 -0
- package/output/api/debug.js +23 -0
- package/output/api/parser.d.ts +85 -0
- package/output/api/parser.js +16 -0
- package/output/api/solve.d.ts +10 -0
- package/output/api/solve.js +16 -0
- package/output/api/structures.d.ts +10 -0
- package/output/api/structures.js +22 -0
- package/output/calculus/derivative/diff.d.ts +30 -0
- package/output/calculus/derivative/diff.js +238 -0
- package/output/calculus/fresnel.d.ts +16 -0
- package/output/calculus/fresnel.js +39 -0
- package/output/calculus/integrate/byParts.d.ts +18 -0
- package/output/calculus/integrate/byParts.js +339 -0
- package/output/calculus/integrate/bySubstitution.d.ts +135 -0
- package/output/calculus/integrate/bySubstitution.js +411 -0
- package/output/calculus/integrate/integrate.d.ts +38 -0
- package/output/calculus/integrate/integrate.js +652 -0
- package/output/calculus/integrate/integrationTable.d.ts +2 -0
- package/output/calculus/integrate/integrationTable.js +914 -0
- package/output/calculus/integrate/utils.d.ts +28 -0
- package/output/calculus/integrate/utils.js +96 -0
- package/output/calculus/laplace/ilaplace.d.ts +31 -0
- package/output/calculus/laplace/ilaplace.js +192 -0
- package/output/calculus/laplace/ilaplaceTable.d.ts +2 -0
- package/output/calculus/laplace/ilaplaceTable.js +200 -0
- package/output/calculus/laplace/laplace.d.ts +22 -0
- package/output/calculus/laplace/laplace.js +109 -0
- package/output/calculus/laplace/laplaceTable.d.ts +2 -0
- package/output/calculus/laplace/laplaceTable.js +187 -0
- package/output/calculus/limit/limit.d.ts +35 -0
- package/output/calculus/limit/limit.js +1183 -0
- package/output/calculus/limit/limitsTable.d.ts +2 -0
- package/output/calculus/limit/limitsTable.js +7 -0
- package/output/core/Settings.d.ts +32 -0
- package/output/core/Settings.js +68 -0
- package/output/core/adapters.d.ts +18 -0
- package/output/core/adapters.js +40 -0
- package/output/core/classes/assumption/Assumption.d.ts +218 -0
- package/output/core/classes/assumption/Assumption.js +605 -0
- package/output/core/classes/assumption/assertiveFunctions.d.ts +6 -0
- package/output/core/classes/assumption/assertiveFunctions.js +64 -0
- package/output/core/classes/assumption/assume.d.ts +90 -0
- package/output/core/classes/assumption/assume.js +145 -0
- package/output/core/classes/collection/Collection.d.ts +107 -0
- package/output/core/classes/collection/Collection.js +231 -0
- package/output/core/classes/complex/Complex.d.ts +99 -0
- package/output/core/classes/complex/Complex.js +135 -0
- package/output/core/classes/decimalSet/DecimalSet.d.ts +226 -0
- package/output/core/classes/decimalSet/DecimalSet.js +453 -0
- package/output/core/classes/dictionary/Dictionary.d.ts +102 -0
- package/output/core/classes/dictionary/Dictionary.js +213 -0
- package/output/core/classes/equation/Equation.d.ts +256 -0
- package/output/core/classes/equation/Equation.js +350 -0
- package/output/core/classes/expression/CoeffObject.d.ts +100 -0
- package/output/core/classes/expression/CoeffObject.js +198 -0
- package/output/core/classes/expression/Expression.d.ts +1674 -0
- package/output/core/classes/expression/Expression.js +2332 -0
- package/output/core/classes/expression/analysis.d.ts +25 -0
- package/output/core/classes/expression/analysis.js +218 -0
- package/output/core/classes/expression/collect.d.ts +9 -0
- package/output/core/classes/expression/collect.js +49 -0
- package/output/core/classes/expression/format.d.ts +45 -0
- package/output/core/classes/expression/format.js +217 -0
- package/output/core/classes/expression/products.d.ts +23 -0
- package/output/core/classes/expression/products.js +115 -0
- package/output/core/classes/expression/shortcuts.d.ts +35 -0
- package/output/core/classes/expression/shortcuts.js +129 -0
- package/output/core/classes/expression/traversal.d.ts +31 -0
- package/output/core/classes/expression/traversal.js +216 -0
- package/output/core/classes/expression/trig.d.ts +25 -0
- package/output/core/classes/expression/trig.js +40 -0
- package/output/core/classes/expression/utils.d.ts +52 -0
- package/output/core/classes/expression/utils.js +189 -0
- package/output/core/classes/lookupTable/LookupTable.d.ts +12 -0
- package/output/core/classes/lookupTable/LookupTable.js +55 -0
- package/output/core/classes/matrix/Matrix.d.ts +227 -0
- package/output/core/classes/matrix/Matrix.js +889 -0
- package/output/core/classes/matrix/Sylvester.d.ts +11 -0
- package/output/core/classes/matrix/Sylvester.js +54 -0
- package/output/core/classes/matrix/functions.d.ts +26 -0
- package/output/core/classes/matrix/functions.js +52 -0
- package/output/core/classes/matrix/utils.d.ts +9 -0
- package/output/core/classes/matrix/utils.js +22 -0
- package/output/core/classes/parser/Parser.d.ts +480 -0
- package/output/core/classes/parser/Parser.js +1812 -0
- package/output/core/classes/parser/Token.d.ts +58 -0
- package/output/core/classes/parser/Token.js +137 -0
- package/output/core/classes/parser/constants.d.ts +160 -0
- package/output/core/classes/parser/constants.js +227 -0
- package/output/core/classes/parser/helpers.d.ts +21 -0
- package/output/core/classes/parser/helpers.js +42 -0
- package/output/core/classes/parser/operations/add.d.ts +15 -0
- package/output/core/classes/parser/operations/add.js +238 -0
- package/output/core/classes/parser/operations/comma.d.ts +7 -0
- package/output/core/classes/parser/operations/comma.js +11 -0
- package/output/core/classes/parser/operations/compare.d.ts +21 -0
- package/output/core/classes/parser/operations/compare.js +461 -0
- package/output/core/classes/parser/operations/divide.d.ts +2 -0
- package/output/core/classes/parser/operations/divide.js +72 -0
- package/output/core/classes/parser/operations/functions.d.ts +46 -0
- package/output/core/classes/parser/operations/functions.js +430 -0
- package/output/core/classes/parser/operations/multiply.d.ts +11 -0
- package/output/core/classes/parser/operations/multiply.js +321 -0
- package/output/core/classes/parser/operations/power.d.ts +48 -0
- package/output/core/classes/parser/operations/power.js +673 -0
- package/output/core/classes/parser/operations/subtract.d.ts +3 -0
- package/output/core/classes/parser/operations/subtract.js +35 -0
- package/output/core/classes/parser/preprocess.d.ts +14 -0
- package/output/core/classes/parser/preprocess.js +259 -0
- package/output/core/classes/parser/scripting/controlFlow.d.ts +121 -0
- package/output/core/classes/parser/scripting/controlFlow.js +355 -0
- package/output/core/classes/parser/scripting/evaluate.d.ts +10 -0
- package/output/core/classes/parser/scripting/evaluate.js +112 -0
- package/output/core/classes/parser/scripting/functions.d.ts +14 -0
- package/output/core/classes/parser/scripting/functions.js +59 -0
- package/output/core/classes/parser/scripting/scope.d.ts +35 -0
- package/output/core/classes/parser/scripting/scope.js +155 -0
- package/output/core/classes/parser/types.d.ts +125 -0
- package/output/core/classes/parser/types.js +2 -0
- package/output/core/classes/parser/wrappers/IndexedReference.d.ts +31 -0
- package/output/core/classes/parser/wrappers/IndexedReference.js +68 -0
- package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +24 -0
- package/output/core/classes/parser/wrappers/KeyValuePair.js +51 -0
- package/output/core/classes/polynomial/Polynomial.d.ts +500 -0
- package/output/core/classes/polynomial/Polynomial.js +1149 -0
- package/output/core/classes/polynomial/Term.d.ts +222 -0
- package/output/core/classes/polynomial/Term.js +430 -0
- package/output/core/classes/polynomial/functions.d.ts +69 -0
- package/output/core/classes/polynomial/functions.js +126 -0
- package/output/core/classes/polynomial/utils.d.ts +62 -0
- package/output/core/classes/polynomial/utils.js +206 -0
- package/output/core/classes/rational/Rational.d.ts +504 -0
- package/output/core/classes/rational/Rational.js +779 -0
- package/output/core/classes/seq/SEQ.d.ts +13 -0
- package/output/core/classes/seq/SEQ.js +137 -0
- package/output/core/classes/valuesSet/ValuesSet.d.ts +179 -0
- package/output/core/classes/valuesSet/ValuesSet.js +381 -0
- package/output/core/classes/vector/Vector.d.ts +222 -0
- package/output/core/classes/vector/Vector.js +497 -0
- package/output/core/classes/vector/functions.d.ts +28 -0
- package/output/core/classes/vector/functions.js +47 -0
- package/output/core/common/classes/MathematicalAggregate.d.ts +53 -0
- package/output/core/common/classes/MathematicalAggregate.js +140 -0
- package/output/core/common/classes/Scope.d.ts +62 -0
- package/output/core/common/classes/Scope.js +122 -0
- package/output/core/common/classes/StructuredEntity.d.ts +55 -0
- package/output/core/common/classes/StructuredEntity.js +151 -0
- package/output/core/common/common.d.ts +63 -0
- package/output/core/common/common.js +279 -0
- package/output/core/common/functions/functions.d.ts +14 -0
- package/output/core/common/functions/functions.js +33 -0
- package/output/core/common/functions/structuredEntityUtils.d.ts +27 -0
- package/output/core/common/functions/structuredEntityUtils.js +40 -0
- package/output/core/converters/BaseConverter.d.ts +97 -0
- package/output/core/converters/BaseConverter.js +405 -0
- package/output/core/converters/Converter.d.ts +111 -0
- package/output/core/converters/Converter.js +802 -0
- package/output/core/converters/Pattern.d.ts +71 -0
- package/output/core/converters/Pattern.js +302 -0
- package/output/core/dispatch.d.ts +34 -0
- package/output/core/dispatch.js +304 -0
- package/output/core/errors.d.ts +531 -0
- package/output/core/errors.js +621 -0
- package/output/core/functions/bigint/bigint.d.ts +121 -0
- package/output/core/functions/bigint/bigint.js +392 -0
- package/output/core/functions/bigint/primeFactor.d.ts +49 -0
- package/output/core/functions/bigint/primeFactor.js +267 -0
- package/output/core/functions/bigint/primes.d.ts +1 -0
- package/output/core/functions/bigint/primes.js +11 -0
- package/output/core/functions/build/definitions.d.ts +12 -0
- package/output/core/functions/build/definitions.js +133 -0
- package/output/core/functions/build/index.d.ts +32 -0
- package/output/core/functions/build/index.js +136 -0
- package/output/core/functions/complex.d.ts +90 -0
- package/output/core/functions/complex.js +482 -0
- package/output/core/functions/decimal.d.ts +24 -0
- package/output/core/functions/decimal.js +664 -0
- package/output/core/functions/expand/expand.d.ts +42 -0
- package/output/core/functions/expand/expand.js +376 -0
- package/output/core/functions/fresnelNumeric.d.ts +12 -0
- package/output/core/functions/fresnelNumeric.js +123 -0
- package/output/core/functions/numeric.d.ts +140 -0
- package/output/core/functions/numeric.js +790 -0
- package/output/core/functions/rationalNormalization.d.ts +11 -0
- package/output/core/functions/rationalNormalization.js +117 -0
- package/output/core/functions/setFunction.d.ts +19 -0
- package/output/core/functions/setFunction.js +75 -0
- package/output/core/functions/string.d.ts +26 -0
- package/output/core/functions/string.js +101 -0
- package/output/core/functions/subst.d.ts +90 -0
- package/output/core/functions/subst.js +498 -0
- package/output/core/functions/utils.d.ts +24 -0
- package/output/core/functions/utils.js +51 -0
- package/output/core/types.d.ts +48 -0
- package/output/core/types.js +2 -0
- package/output/index.d.ts +339 -0
- package/output/index.js +715 -0
- package/output/math/defint/defintDecimal.d.ts +37 -0
- package/output/math/defint/defintDecimal.js +320 -0
- package/output/math/defint/defintNative.d.ts +57 -0
- package/output/math/defint/defintNative.js +292 -0
- package/output/math/geometry.d.ts +8 -0
- package/output/math/geometry.js +32 -0
- package/output/math/math.d.ts +655 -0
- package/output/math/math.js +1811 -0
- package/output/math/trig.d.ts +518 -0
- package/output/math/trig.js +1444 -0
- package/output/math/trunc.d.ts +19 -0
- package/output/math/trunc.js +36 -0
- package/output/math/utils.d.ts +60 -0
- package/output/math/utils.js +180 -0
- package/output/solve/classes/DecimalMatrix.d.ts +17 -0
- package/output/solve/classes/DecimalMatrix.js +86 -0
- package/output/solve/classes/FunctionSolver.d.ts +135 -0
- package/output/solve/classes/FunctionSolver.js +433 -0
- package/output/solve/classes/MultivariateSolver.d.ts +84 -0
- package/output/solve/classes/MultivariateSolver.js +240 -0
- package/output/solve/classes/PolynomialSolver.d.ts +85 -0
- package/output/solve/classes/PolynomialSolver.js +292 -0
- package/output/solve/classes/SolutionSet.d.ts +153 -0
- package/output/solve/classes/SolutionSet.js +357 -0
- package/output/solve/classes/Solver.d.ts +17 -0
- package/output/solve/classes/Solver.js +132 -0
- package/output/solve/classes/SymbolicSolver.d.ts +74 -0
- package/output/solve/classes/SymbolicSolver.js +601 -0
- package/output/solve/linsolve.d.ts +51 -0
- package/output/solve/linsolve.js +225 -0
- package/output/solve/solve.d.ts +34 -0
- package/output/solve/solve.js +260 -0
- package/output/solve/solveSystem.d.ts +31 -0
- package/output/solve/solveSystem.js +290 -0
- package/output/solve/utils.d.ts +9 -0
- package/output/solve/utils.js +62 -0
- package/output/utils/array.d.ts +42 -0
- package/output/utils/array.js +98 -0
- package/output/utils/debug.d.ts +131 -0
- package/output/utils/debug.js +295 -0
- package/output/utils/decimal.d.ts +3 -0
- package/output/utils/decimal.js +16 -0
- package/output/utils/numeric.d.ts +14 -0
- package/output/utils/numeric.js +51 -0
- package/output/utils/object.d.ts +26 -0
- package/output/utils/object.js +56 -0
- package/package.json +213 -57
- package/.travis.yml +0 -3
- package/Algebra.js +0 -4568
- package/BREAKING_CHANGES.md +0 -5
- package/CODE_OF_CONDUCT.md +0 -46
- package/CONTRIBUTING.md +0 -14
- package/Calculus.js +0 -2675
- package/Extra.js +0 -622
- package/Solve.js +0 -1783
- package/all.js +0 -16
- package/all.min.js +0 -1
- package/gulpfile.js +0 -16
- package/index.html +0 -158
- package/license.txt +0 -19
- package/nerdamer.core.js +0 -12510
- package/spec/LaTeX.spec.js +0 -302
- package/spec/TeXConvert.spec.js +0 -8
- package/spec/algebra.spec.js +0 -287
- package/spec/basic_parser.spec.js +0 -134
- package/spec/build.spec.js +0 -131
- package/spec/calculus.spec.js +0 -183
- package/spec/core.spec.js +0 -2970
- package/spec/extra.spec.js +0 -54
- package/spec/solve.spec.js +0 -126
- package/spec/support/jasmine.json +0 -11
- package/spec/support/utils.js +0 -42
- package/spec/text.spec.js +0 -132
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assign = assign;
|
|
4
|
+
exports.normalizeLetArguments = normalizeLetArguments;
|
|
5
|
+
exports.LET = LET;
|
|
6
|
+
exports.unassign = unassign;
|
|
7
|
+
const Scope_1 = require("../../../common/classes/Scope");
|
|
8
|
+
const errors_1 = require("../../../errors");
|
|
9
|
+
const Settings_1 = require("../../../Settings");
|
|
10
|
+
const Expression_1 = require("../../expression/Expression");
|
|
11
|
+
const utils_1 = require("../../expression/utils");
|
|
12
|
+
const constants_1 = require("../constants");
|
|
13
|
+
const Parser_1 = require("../Parser");
|
|
14
|
+
const Token_1 = require("../Token");
|
|
15
|
+
/**
|
|
16
|
+
* Adds a known value to a variable in the parser
|
|
17
|
+
* @param a
|
|
18
|
+
* @param b
|
|
19
|
+
*/
|
|
20
|
+
function assign(a, b) {
|
|
21
|
+
a = Expression_1.Expression.create(a);
|
|
22
|
+
if (typeof b === 'string') {
|
|
23
|
+
b = Parser_1.Parser.parse(b);
|
|
24
|
+
}
|
|
25
|
+
// We can only assign to plain variables
|
|
26
|
+
if (Expression_1.Expression.isExpression(a) && !a.isPlainVariable()) {
|
|
27
|
+
throw new errors_1.UnexpectedInputError((0, errors_1.message)('plainVariableExpected', { input: String(a) }));
|
|
28
|
+
}
|
|
29
|
+
// We cannot assign to restricted values
|
|
30
|
+
if (Settings_1.RESTRICTED.includes(a.value)) {
|
|
31
|
+
throw new errors_1.AssignmentError((0, errors_1.message)('restrictedVariableName', { name: a.value }));
|
|
32
|
+
}
|
|
33
|
+
Parser_1.Parser.KNOWN_VALUES[a.value] = b;
|
|
34
|
+
return b;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Converts colon-style LET bindings into the alternating name/value scopes consumed by LET.
|
|
38
|
+
*/
|
|
39
|
+
function normalizeLetArguments(argumentScopes) {
|
|
40
|
+
const normalizedScopes = [];
|
|
41
|
+
for (let i = 0; i < argumentScopes.length; i++) {
|
|
42
|
+
const argumentScope = argumentScopes[i];
|
|
43
|
+
let assignmentIndex = -1;
|
|
44
|
+
if (i < argumentScopes.length - 1) {
|
|
45
|
+
for (let j = 0; j < argumentScope.length; j++) {
|
|
46
|
+
const argumentToken = argumentScope[j];
|
|
47
|
+
if (Token_1.Token.isToken(argumentToken) &&
|
|
48
|
+
argumentToken.type === Token_1.Token.OPERATOR &&
|
|
49
|
+
argumentToken.value === constants_1.ASSIGN) {
|
|
50
|
+
assignmentIndex = j;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (assignmentIndex > 0 && assignmentIndex < argumentScope.length - 1) {
|
|
56
|
+
const nameScope = new Scope_1.Scope(argumentScope.type, argumentScope.column);
|
|
57
|
+
const valueScope = new Scope_1.Scope(argumentScope.type, argumentScope.column);
|
|
58
|
+
for (let j = 0; j < assignmentIndex; j++) {
|
|
59
|
+
nameScope.push(argumentScope[j]);
|
|
60
|
+
}
|
|
61
|
+
for (let j = assignmentIndex + 1; j < argumentScope.length; j++) {
|
|
62
|
+
valueScope.push(argumentScope[j]);
|
|
63
|
+
}
|
|
64
|
+
normalizedScopes.push(nameScope, valueScope);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
normalizedScopes.push(argumentScope);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return normalizedScopes;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Evaluates sequential local bindings and restores only those bindings after the body.
|
|
74
|
+
*
|
|
75
|
+
* Arguments are alternating variable/value pairs followed by a body expression. Each value
|
|
76
|
+
* is evaluated after earlier bindings have been installed, so later initializers can reference
|
|
77
|
+
* earlier locals. Ordinary assignment is reused for validation and storage. Any assignment to
|
|
78
|
+
* a name not declared by LET keeps its normal parser behavior.
|
|
79
|
+
*
|
|
80
|
+
* @param args Deferred variable/value pairs followed by the deferred body.
|
|
81
|
+
* @returns The body's result.
|
|
82
|
+
*/
|
|
83
|
+
function LET(...args) {
|
|
84
|
+
if (args.length < 3 || args.length % 2 === 0) {
|
|
85
|
+
throw new errors_1.ParserError((0, errors_1.message)('letRequiresBindingsAndBody'));
|
|
86
|
+
}
|
|
87
|
+
const previousValues = new Map();
|
|
88
|
+
const previouslyUndefined = new Set();
|
|
89
|
+
const localNames = [];
|
|
90
|
+
let retval;
|
|
91
|
+
try {
|
|
92
|
+
for (let i = 0; i < args.length - 1; i += 2) {
|
|
93
|
+
// Binding names are syntax, not values. Suppress both call-scoped and known-value
|
|
94
|
+
// substitution while resolving the plain variable name.
|
|
95
|
+
const nameExpression = args[i]({ inheritValues: false, substitute: false });
|
|
96
|
+
if (!Expression_1.Expression.isExpression(nameExpression)) {
|
|
97
|
+
throw new errors_1.UnexpectedInputError((0, errors_1.message)('plainVariableExpected', { input: nameExpression.text() }));
|
|
98
|
+
}
|
|
99
|
+
const name = (0, utils_1.assertPlainVariableAndGetString)(nameExpression);
|
|
100
|
+
const value = args[i + 1]({ excludeValues: localNames });
|
|
101
|
+
if (!previousValues.has(name) && !previouslyUndefined.has(name)) {
|
|
102
|
+
if (Object.prototype.hasOwnProperty.call(Parser_1.Parser.KNOWN_VALUES, name)) {
|
|
103
|
+
previousValues.set(name, Parser_1.Parser.KNOWN_VALUES[name]);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
previouslyUndefined.add(name);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
assign(nameExpression, value);
|
|
110
|
+
if (!localNames.includes(name)) {
|
|
111
|
+
localNames.push(name);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
retval = args[args.length - 1]({ excludeValues: localNames });
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
for (const [name, value] of previousValues) {
|
|
118
|
+
Parser_1.Parser.KNOWN_VALUES[name] = value;
|
|
119
|
+
}
|
|
120
|
+
for (const name of previouslyUndefined) {
|
|
121
|
+
delete Parser_1.Parser.KNOWN_VALUES[name];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return retval;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Removes a known parser value by variable name.
|
|
128
|
+
*
|
|
129
|
+
* Parser calls defer the argument so an assigned variable can be read as its name rather than
|
|
130
|
+
* substituted value. Direct callers may still pass an Expression or string.
|
|
131
|
+
*
|
|
132
|
+
* @param x Variable name or deferred variable-name expression.
|
|
133
|
+
*/
|
|
134
|
+
function unassign(x) {
|
|
135
|
+
let variable;
|
|
136
|
+
let name;
|
|
137
|
+
if (typeof x === 'function') {
|
|
138
|
+
const parsed = x({ inheritValues: false, substitute: false });
|
|
139
|
+
if (!Expression_1.Expression.isExpression(parsed)) {
|
|
140
|
+
throw new errors_1.UnexpectedInputError((0, errors_1.message)('plainVariableExpected', { input: parsed.text() }));
|
|
141
|
+
}
|
|
142
|
+
variable = parsed;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
variable = x;
|
|
146
|
+
}
|
|
147
|
+
if (Expression_1.Expression.isExpression(variable)) {
|
|
148
|
+
name = (0, utils_1.assertPlainVariableAndGetString)(variable);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
name = variable;
|
|
152
|
+
}
|
|
153
|
+
delete Parser_1.Parser.KNOWN_VALUES[name];
|
|
154
|
+
return Expression_1.Expression.create(variable);
|
|
155
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { type Equation } from '../equation/Equation';
|
|
2
|
+
import { type Expression } from '../expression/Expression';
|
|
3
|
+
import type { NerdamerInput, ParserEntity } from '../../types';
|
|
4
|
+
import type { IndexedReference } from './wrappers/IndexedReference';
|
|
5
|
+
import type { KeyValuePair } from './wrappers/KeyValuePair';
|
|
6
|
+
import type Decimal from 'decimal.js';
|
|
7
|
+
/**
|
|
8
|
+
* The type used to defined a operation function for the parser
|
|
9
|
+
*/
|
|
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
|
+
/**
|
|
17
|
+
* The type used to defined a prefix for the parser
|
|
18
|
+
*/
|
|
19
|
+
export type PreFixFunction = (a: ParserEntity) => ParserEntity;
|
|
20
|
+
/**
|
|
21
|
+
* The type used to defined a prefix for the parser
|
|
22
|
+
*/
|
|
23
|
+
export type PostFixFunction = (b: ParserEntity) => ParserEntity;
|
|
24
|
+
/**
|
|
25
|
+
* The call used to construct an equation
|
|
26
|
+
*/
|
|
27
|
+
export type EquationConstructorCall = (a: ParserEntity, b: ParserEntity) => Equation;
|
|
28
|
+
/** Controls the parser context used when a deferred function evaluates one argument. */
|
|
29
|
+
export interface DeferredArgumentOptions {
|
|
30
|
+
/** Call-scoped substitution names to omit while evaluating this argument. */
|
|
31
|
+
excludeValues?: readonly string[];
|
|
32
|
+
/** Whether this argument should inherit the enclosing call-scoped substitutions. */
|
|
33
|
+
inheritValues?: boolean;
|
|
34
|
+
/** Optional temporary override for known-value substitution. */
|
|
35
|
+
substitute?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A parser argument whose evaluation is delayed until the receiving function decides to
|
|
39
|
+
* execute it. The callback may be invoked once or repeatedly, and may narrow the inherited
|
|
40
|
+
* substitution context for lexical control functions.
|
|
41
|
+
*/
|
|
42
|
+
export type DeferredFunctionArgument = (options?: DeferredArgumentOptions) => ParserEntity;
|
|
43
|
+
/** An operator action whose right-hand operand is deferred. */
|
|
44
|
+
export type DeferredOperation = (a: ParserEntity, b: DeferredFunctionArgument) => ParserEntity;
|
|
45
|
+
/**
|
|
46
|
+
* Named values substituted while parsing or evaluating an input expression.
|
|
47
|
+
*
|
|
48
|
+
* Keys are parser variable names. This compatibility type accepts the same broad value
|
|
49
|
+
* union as the root API, but not every substitution path can consume every structured
|
|
50
|
+
* entity. The receiving operation's documentation defines the narrower requirements when
|
|
51
|
+
* one applies.
|
|
52
|
+
*/
|
|
53
|
+
export type ParserValuesObject = Record<string, NerdamerInput>;
|
|
54
|
+
/**
|
|
55
|
+
* Constant definitions accepted by the parser's constant registry.
|
|
56
|
+
*
|
|
57
|
+
* String definitions are parsed when the constant is encountered. Function
|
|
58
|
+
* definitions are deferred factories that return parser text, allowing constants such
|
|
59
|
+
* as `pi` and `e` to reflect the active numerical precision. The registry itself is
|
|
60
|
+
* process-wide; this type does not imply isolated parser state.
|
|
61
|
+
*/
|
|
62
|
+
export type ParserConstants = Record<string, (() => string) | string>;
|
|
63
|
+
/**
|
|
64
|
+
* Values currently accepted by Nerdamer's broad settings objects.
|
|
65
|
+
*
|
|
66
|
+
* @remarks
|
|
67
|
+
* Parser and formatting settings share this recursive value type. Each API still decides
|
|
68
|
+
* which setting names and value shapes it understands.
|
|
69
|
+
*/
|
|
70
|
+
export type OptionValue = string | boolean | number | string[] | OptionsObject;
|
|
71
|
+
/**
|
|
72
|
+
* Compatibility settings bag used by several parser and formatter entry points.
|
|
73
|
+
*
|
|
74
|
+
* The index signature reflects the values that settings APIs currently pass around. It
|
|
75
|
+
* does not make arbitrary setting names part of the supported public method.
|
|
76
|
+
*/
|
|
77
|
+
export interface OptionsObject {
|
|
78
|
+
[key: string]: OptionValue;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Formatting options accepted by {@link Expression.text}.
|
|
82
|
+
*
|
|
83
|
+
* These options affect only the returned string. They do not change the expression or
|
|
84
|
+
* Nerdamer's process-wide settings.
|
|
85
|
+
*/
|
|
86
|
+
export type TextOptions = {
|
|
87
|
+
/** Render rational values as decimals instead of exact fractions. */
|
|
88
|
+
decimal?: boolean;
|
|
89
|
+
/** Significant-digit precision used when decimal output is requested. */
|
|
90
|
+
precision?: number;
|
|
91
|
+
/** Sort sum and product elements with {@link Expression.sortFunction} before rendering. */
|
|
92
|
+
sort?: boolean;
|
|
93
|
+
/** Parenthesize powers for output that will be embedded in JavaScript-style expressions. */
|
|
94
|
+
wrapPow?: boolean;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* The type used when passing settings
|
|
98
|
+
*/
|
|
99
|
+
export type SimpleOptionsObject = Record<string, string | number | Expression>;
|
|
100
|
+
/**
|
|
101
|
+
* The type supported by Decimal implementations of algorithms
|
|
102
|
+
*/
|
|
103
|
+
export type DecimalType = Decimal | number | string;
|
|
104
|
+
/**
|
|
105
|
+
* Native JavaScript function produced or consumed by numerical compilation APIs.
|
|
106
|
+
*
|
|
107
|
+
* Arguments and numeric results use JavaScript `number` arithmetic rather than
|
|
108
|
+
* Nerdamer's exact rational or arbitrary-precision symbolic representation. Boolean
|
|
109
|
+
* results support compiled comparison expressions.
|
|
110
|
+
*/
|
|
111
|
+
export type JsFunction = (...args: number[]) => number | boolean;
|
|
112
|
+
/**
|
|
113
|
+
* A simple expression function call
|
|
114
|
+
*/
|
|
115
|
+
export type ExpressionFunction = (...args: Expression[]) => Expression;
|
|
116
|
+
/**
|
|
117
|
+
* Internal values that may temporarily exist on the parser output stack.
|
|
118
|
+
* IndexedReference and KeyValuePair are resolved or consumed before parseRPN returns.
|
|
119
|
+
* Deferred callbacks are consumed only by operators that explicitly request them.
|
|
120
|
+
*/
|
|
121
|
+
export type ParserStackValue = ParserEntity | IndexedReference | KeyValuePair | DeferredFunctionArgument;
|
|
122
|
+
/**
|
|
123
|
+
* An array containing numerator and denominator
|
|
124
|
+
*/
|
|
125
|
+
export type FracArray = [string, string];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { INDEXED_REFERENCE } from '../constants';
|
|
2
|
+
import type { ParserEntity } from '../../../types';
|
|
3
|
+
import type { Dictionary } from '../../dictionary/Dictionary';
|
|
4
|
+
/**
|
|
5
|
+
* A lightweight wrapper that holds a reference to a structured entity and the indices
|
|
6
|
+
* used to access it. This is pushed onto the output stack during indexing so that
|
|
7
|
+
* the assign operator can detect it and call setter instead of getter.
|
|
8
|
+
*
|
|
9
|
+
* For any non-assign operator, the IndexedReference is resolved to its value via resolve().
|
|
10
|
+
* The resolved value is cached so that repeated calls don't re-invoke the getter.
|
|
11
|
+
*/
|
|
12
|
+
export declare class IndexedReference {
|
|
13
|
+
target: ParserEntity;
|
|
14
|
+
indices: number[] | string;
|
|
15
|
+
targetName?: string | undefined;
|
|
16
|
+
private _resolved;
|
|
17
|
+
dataType: typeof INDEXED_REFERENCE;
|
|
18
|
+
isEnumerable: boolean;
|
|
19
|
+
constructor(target: ParserEntity, indices: number[] | string, targetName?: string | undefined);
|
|
20
|
+
static isIndexedReference(obj: unknown): obj is IndexedReference;
|
|
21
|
+
copy(): import("../../expression/Expression").Expression | import("../../vector/Vector").Vector | import("../../valuesSet/ValuesSet").ValuesSet | import("../../collection/Collection").Collection | import("../../matrix/Matrix").Matrix | Dictionary | import("../../equation/Equation").Equation;
|
|
22
|
+
eq(other: ParserEntity): boolean;
|
|
23
|
+
evaluate(): import("../../expression/Expression").Expression | import("../../vector/Vector").Vector | import("../../valuesSet/ValuesSet").ValuesSet | import("../../collection/Collection").Collection | import("../../matrix/Matrix").Matrix | Dictionary | import("../../equation/Equation").Equation;
|
|
24
|
+
expand(): import("../../expression/Expression").Expression | import("../../vector/Vector").Vector | import("../../valuesSet/ValuesSet").ValuesSet | import("../../collection/Collection").Collection | import("../../matrix/Matrix").Matrix | Dictionary | import("../../equation/Equation").Equation;
|
|
25
|
+
gt(other: ParserEntity): boolean;
|
|
26
|
+
gte(other: ParserEntity): boolean;
|
|
27
|
+
lt(other: ParserEntity): boolean;
|
|
28
|
+
lte(other: ParserEntity): boolean;
|
|
29
|
+
resolve(): ParserEntity;
|
|
30
|
+
text(): string;
|
|
31
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IndexedReference = void 0;
|
|
4
|
+
const common_1 = require("../../../common/common");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
/**
|
|
7
|
+
* A lightweight wrapper that holds a reference to a structured entity and the indices
|
|
8
|
+
* used to access it. This is pushed onto the output stack during indexing so that
|
|
9
|
+
* the assign operator can detect it and call setter instead of getter.
|
|
10
|
+
*
|
|
11
|
+
* For any non-assign operator, the IndexedReference is resolved to its value via resolve().
|
|
12
|
+
* The resolved value is cached so that repeated calls don't re-invoke the getter.
|
|
13
|
+
*/
|
|
14
|
+
class IndexedReference {
|
|
15
|
+
target;
|
|
16
|
+
indices;
|
|
17
|
+
targetName;
|
|
18
|
+
_resolved = null;
|
|
19
|
+
dataType = constants_1.INDEXED_REFERENCE;
|
|
20
|
+
isEnumerable = false;
|
|
21
|
+
constructor(target, indices, targetName) {
|
|
22
|
+
this.target = target;
|
|
23
|
+
this.indices = indices;
|
|
24
|
+
this.targetName = targetName;
|
|
25
|
+
}
|
|
26
|
+
static isIndexedReference(obj) {
|
|
27
|
+
return (0, common_1.isNerdamerNativeType)(obj, constants_1.INDEXED_REFERENCE);
|
|
28
|
+
}
|
|
29
|
+
copy() {
|
|
30
|
+
return this.resolve().copy();
|
|
31
|
+
}
|
|
32
|
+
eq(other) {
|
|
33
|
+
return this.resolve().eq(other);
|
|
34
|
+
}
|
|
35
|
+
evaluate() {
|
|
36
|
+
return this.resolve().evaluate();
|
|
37
|
+
}
|
|
38
|
+
expand() {
|
|
39
|
+
return this.resolve().expand();
|
|
40
|
+
}
|
|
41
|
+
gt(other) {
|
|
42
|
+
return this.resolve().gt(other);
|
|
43
|
+
}
|
|
44
|
+
gte(other) {
|
|
45
|
+
return this.resolve().gte(other);
|
|
46
|
+
}
|
|
47
|
+
lt(other) {
|
|
48
|
+
return this.resolve().lt(other);
|
|
49
|
+
}
|
|
50
|
+
lte(other) {
|
|
51
|
+
return this.resolve().lte(other);
|
|
52
|
+
}
|
|
53
|
+
resolve() {
|
|
54
|
+
if (this._resolved === null) {
|
|
55
|
+
if (typeof this.indices === 'string') {
|
|
56
|
+
this._resolved = this.target.__get__(this.indices);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
this._resolved = this.target.__get__(this.indices);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return this._resolved;
|
|
63
|
+
}
|
|
64
|
+
text() {
|
|
65
|
+
return this.resolve().text();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.IndexedReference = IndexedReference;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { KEY_VALUE_PAIR } from '../constants';
|
|
2
|
+
import type { ParserEntity } from '../../../types';
|
|
3
|
+
/**
|
|
4
|
+
* Internal marker produced by the '=>' (mapTo) operator inside curly braces.
|
|
5
|
+
* Holds a key-value pair that gets collected into a Dictionary at the end
|
|
6
|
+
* of curly scope parsing.
|
|
7
|
+
*/
|
|
8
|
+
export declare class KeyValuePair {
|
|
9
|
+
key: string;
|
|
10
|
+
value: ParserEntity;
|
|
11
|
+
dataType: typeof KEY_VALUE_PAIR;
|
|
12
|
+
isEnumerable: boolean;
|
|
13
|
+
constructor(key: string, value: ParserEntity);
|
|
14
|
+
static isKeyValuePair(obj: unknown): obj is KeyValuePair;
|
|
15
|
+
copy(): KeyValuePair;
|
|
16
|
+
eq(): boolean;
|
|
17
|
+
evaluate(): import("../../expression/Expression").Expression | import("../../vector/Vector").Vector | import("../../valuesSet/ValuesSet").ValuesSet | import("../../collection/Collection").Collection | import("../../matrix/Matrix").Matrix | import("../../dictionary/Dictionary").Dictionary | import("../../equation/Equation").Equation;
|
|
18
|
+
expand(): import("../../expression/Expression").Expression | import("../../vector/Vector").Vector | import("../../valuesSet/ValuesSet").ValuesSet | import("../../collection/Collection").Collection | import("../../matrix/Matrix").Matrix | import("../../dictionary/Dictionary").Dictionary | import("../../equation/Equation").Equation;
|
|
19
|
+
gt(): boolean;
|
|
20
|
+
gte(): boolean;
|
|
21
|
+
lt(): boolean;
|
|
22
|
+
lte(): boolean;
|
|
23
|
+
text(): string;
|
|
24
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KeyValuePair = void 0;
|
|
4
|
+
const common_1 = require("../../../common/common");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
/**
|
|
7
|
+
* Internal marker produced by the '=>' (mapTo) operator inside curly braces.
|
|
8
|
+
* Holds a key-value pair that gets collected into a Dictionary at the end
|
|
9
|
+
* of curly scope parsing.
|
|
10
|
+
*/
|
|
11
|
+
class KeyValuePair {
|
|
12
|
+
key;
|
|
13
|
+
value;
|
|
14
|
+
dataType = constants_1.KEY_VALUE_PAIR;
|
|
15
|
+
isEnumerable = false;
|
|
16
|
+
constructor(key, value) {
|
|
17
|
+
this.key = key;
|
|
18
|
+
this.value = value;
|
|
19
|
+
}
|
|
20
|
+
static isKeyValuePair(obj) {
|
|
21
|
+
return (0, common_1.isNerdamerNativeType)(obj, constants_1.KEY_VALUE_PAIR);
|
|
22
|
+
}
|
|
23
|
+
copy() {
|
|
24
|
+
return new KeyValuePair(this.key, this.value.copy());
|
|
25
|
+
}
|
|
26
|
+
eq() {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
evaluate() {
|
|
30
|
+
return this.value.evaluate();
|
|
31
|
+
}
|
|
32
|
+
expand() {
|
|
33
|
+
return this.value.expand();
|
|
34
|
+
}
|
|
35
|
+
gt() {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
gte() {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
lt() {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
lte() {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
text() {
|
|
48
|
+
return `${this.key} => ${this.value.text()}`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.KeyValuePair = KeyValuePair;
|