nerdamer 1.1.13 → 2.0.0-rc.2
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 -5
- package/LICENSE.md +184 -0
- package/README.md +232 -318
- 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 +2248 -0
- package/index.d.ts +10 -426
- package/output/algebra/adapters.d.ts +3 -0
- package/output/algebra/adapters.js +11 -0
- package/output/algebra/algorithms/arith.d.ts +84 -0
- package/output/algebra/algorithms/arith.js +324 -0
- package/output/algebra/algorithms/groebnerBase.d.ts +161 -0
- package/output/algebra/algorithms/groebnerBase.js +929 -0
- package/output/algebra/dispatch.d.ts +1 -0
- package/output/algebra/dispatch.js +25 -0
- package/output/algebra/factor/factor.d.ts +77 -0
- package/output/algebra/factor/factor.js +245 -0
- package/output/algebra/gcd/gcd.d.ts +30 -0
- package/output/algebra/gcd/gcd.js +95 -0
- package/output/algebra/groebner.d.ts +21 -0
- package/output/algebra/groebner.js +36 -0
- package/output/algebra/partfrac.d.ts +19 -0
- package/output/algebra/partfrac.js +365 -0
- 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.d.ts +20 -0
- package/output/algebra/polynomialize.js +26 -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 +237 -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 +8 -0
- package/output/api/advanced.js +18 -0
- package/output/api/algebra.d.ts +17 -0
- package/output/api/algebra.js +35 -0
- package/output/api/assumptions.d.ts +4 -0
- package/output/api/assumptions.js +11 -0
- package/output/api/calculus.d.ts +10 -0
- package/output/api/calculus.js +22 -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/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 +93 -0
- package/output/api/parser.js +18 -0
- package/output/api/solve.d.ts +10 -0
- package/output/api/solve.js +17 -0
- package/output/api/structures.d.ts +10 -0
- package/output/api/structures.js +23 -0
- package/output/calculus/adapters.d.ts +8 -0
- package/output/calculus/adapters.js +41 -0
- package/output/calculus/derivative/diff.d.ts +30 -0
- package/output/calculus/derivative/diff.js +241 -0
- package/output/calculus/dispatch.d.ts +1 -0
- package/output/calculus/dispatch.js +25 -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/classes/assumption/Assumption.d.ts +218 -0
- package/output/core/classes/assumption/Assumption.js +609 -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/assumption/dispatch.d.ts +1 -0
- package/output/core/classes/assumption/dispatch.js +11 -0
- package/output/core/classes/collection/Collection.d.ts +107 -0
- package/output/core/classes/collection/Collection.js +240 -0
- package/output/core/classes/complex/Complex.d.ts +109 -0
- package/output/core/classes/complex/Complex.js +153 -0
- package/output/core/classes/decimalSet/DecimalSet.d.ts +226 -0
- package/output/core/classes/decimalSet/DecimalSet.js +454 -0
- package/output/core/classes/dictionary/Dictionary.d.ts +102 -0
- package/output/core/classes/dictionary/Dictionary.js +216 -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 +197 -0
- package/output/core/classes/expression/Expression.d.ts +1691 -0
- package/output/core/classes/expression/Expression.js +2381 -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 +54 -0
- package/output/core/classes/expression/format.js +340 -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 +61 -0
- package/output/core/classes/expression/utils.js +235 -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 +901 -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/dispatch.d.ts +1 -0
- package/output/core/classes/matrix/dispatch.js +19 -0
- package/output/core/classes/matrix/functions.d.ts +28 -0
- package/output/core/classes/matrix/functions.js +57 -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 +493 -0
- package/output/core/classes/parser/Parser.js +1863 -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 +162 -0
- package/output/core/classes/parser/constants.js +229 -0
- package/output/core/classes/parser/controlFlowSignals.d.ts +38 -0
- package/output/core/classes/parser/controlFlowSignals.js +60 -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 +236 -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 +474 -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 +438 -0
- package/output/core/classes/parser/operations/multiply.d.ts +11 -0
- package/output/core/classes/parser/operations/multiply.js +328 -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 +36 -0
- package/output/core/classes/parser/preprocess.d.ts +7 -0
- package/output/core/classes/parser/preprocess.js +246 -0
- package/output/core/classes/parser/scripting/controlFlow.d.ts +23 -0
- package/output/core/classes/parser/scripting/controlFlow.js +279 -0
- 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 +23 -0
- package/output/core/classes/parser/scripting/evaluate.js +128 -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 +8 -0
- package/output/core/classes/parser/scripting/scope.js +132 -0
- package/output/core/classes/parser/types.d.ts +130 -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 +504 -0
- package/output/core/classes/polynomial/Polynomial.js +1195 -0
- 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.d.ts +222 -0
- package/output/core/classes/polynomial/Term.js +430 -0
- package/output/core/classes/polynomial/adapters.d.ts +18 -0
- 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 +77 -0
- package/output/core/classes/polynomial/functions.js +189 -0
- package/output/core/classes/polynomial/utils.d.ts +62 -0
- package/output/core/classes/polynomial/utils.js +207 -0
- package/output/core/classes/rational/Rational.d.ts +501 -0
- package/output/core/classes/rational/Rational.js +829 -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 +187 -0
- package/output/core/classes/valuesSet/ValuesSet.js +399 -0
- package/output/core/classes/vector/Vector.d.ts +222 -0
- package/output/core/classes/vector/Vector.js +501 -0
- package/output/core/classes/vector/dispatch.d.ts +1 -0
- package/output/core/classes/vector/dispatch.js +11 -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 +149 -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 +62 -0
- package/output/core/common/common.js +74 -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 +806 -0
- package/output/core/converters/Pattern.d.ts +71 -0
- package/output/core/converters/Pattern.js +302 -0
- package/output/core/dispatch.d.ts +52 -0
- package/output/core/dispatch.js +26 -0
- package/output/core/errors.d.ts +316 -0
- package/output/core/errors.js +349 -0
- package/output/core/fullFunctions.d.ts +7 -0
- package/output/core/fullFunctions.js +31 -0
- package/output/core/functions/bigint/bigint.d.ts +133 -0
- package/output/core/functions/bigint/bigint.js +444 -0
- package/output/core/functions/bigint/primeFactor.d.ts +51 -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 +139 -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.dispatch.d.ts +1 -0
- package/output/core/functions/complex.dispatch.js +16 -0
- package/output/core/functions/complex.js +482 -0
- package/output/core/functions/decimal.d.ts +24 -0
- package/output/core/functions/decimal.js +665 -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 +102 -0
- package/output/core/functions/subst.d.ts +90 -0
- package/output/core/functions/subst.js +506 -0
- package/output/core/functions/utils.d.ts +24 -0
- package/output/core/functions/utils.js +51 -0
- package/output/core/parserFunctions.d.ts +7 -0
- package/output/core/parserFunctions.js +25 -0
- package/output/core/types.d.ts +48 -0
- package/output/core/types.js +2 -0
- package/output/index.d.ts +359 -0
- package/output/index.js +739 -0
- package/output/math/defint/defint.d.ts +18 -0
- package/output/math/defint/defint.js +60 -0
- package/output/math/defint/defintDecimal.d.ts +37 -0
- package/output/math/defint/defintDecimal.js +321 -0
- package/output/math/defint/defintNative.d.ts +57 -0
- package/output/math/defint/defintNative.js +281 -0
- package/output/math/dispatch.d.ts +1 -0
- package/output/math/dispatch.js +101 -0
- package/output/math/geometry.d.ts +12 -0
- package/output/math/geometry.js +55 -0
- package/output/math/math.d.ts +695 -0
- package/output/math/math.js +1955 -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 +66 -0
- package/output/math/utils.js +219 -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 +104 -0
- package/output/solve/classes/PolynomialSolver.js +492 -0
- package/output/solve/classes/SolutionSet.d.ts +172 -0
- package/output/solve/classes/SolutionSet.js +434 -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/dispatch.d.ts +1 -0
- package/output/solve/dispatch.js +13 -0
- package/output/solve/linsolve.d.ts +53 -0
- package/output/solve/linsolve.js +233 -0
- package/output/solve/solve.d.ts +44 -0
- package/output/solve/solve.js +368 -0
- package/output/solve/solveSystem.d.ts +31 -0
- package/output/solve/solveSystem.js +266 -0
- package/output/solve/utils.d.ts +10 -0
- package/output/solve/utils.js +58 -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 +296 -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 +178 -57
- package/.travis.yml +0 -3
- package/Algebra.js +0 -4568
- 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,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadScriptingFunctions = loadScriptingFunctions;
|
|
4
|
+
const dispatch_1 = require("../../../dispatch");
|
|
5
|
+
const controlFlow_1 = require("./controlFlow");
|
|
6
|
+
const deferred_1 = require("./deferred");
|
|
7
|
+
const evaluate_1 = require("./evaluate");
|
|
8
|
+
const scope_1 = require("./scope");
|
|
9
|
+
function loadScriptingFunctions() {
|
|
10
|
+
Object.assign(dispatch_1.mathFunctionRegistry, {
|
|
11
|
+
unassign: (0, dispatch_1.systemFunction)({ fn: scope_1.unassign, minArgs: 1, maxArgs: 1, distElWise: false, deferArguments: true }),
|
|
12
|
+
evaluate: (0, dispatch_1.systemFunction)({
|
|
13
|
+
fn: evaluate_1.evaluate,
|
|
14
|
+
minArgs: 1,
|
|
15
|
+
maxArgs: 3,
|
|
16
|
+
equationArgs: [0],
|
|
17
|
+
distElWise: false,
|
|
18
|
+
deferArguments: true,
|
|
19
|
+
usage: 'scripting',
|
|
20
|
+
}),
|
|
21
|
+
return: (0, dispatch_1.systemFunction)({
|
|
22
|
+
fn: controlFlow_1.RETURN,
|
|
23
|
+
minArgs: 1,
|
|
24
|
+
maxArgs: 1,
|
|
25
|
+
equationArgs: [0],
|
|
26
|
+
distElWise: false,
|
|
27
|
+
bracketlessStatement: true,
|
|
28
|
+
usage: 'scripting',
|
|
29
|
+
}),
|
|
30
|
+
break: (0, dispatch_1.systemFunction)({ fn: controlFlow_1.BREAK, minArgs: 0, maxArgs: 0, distElWise: false, usage: 'scripting' }),
|
|
31
|
+
continue: (0, dispatch_1.systemFunction)({ fn: controlFlow_1.CONTINUE, minArgs: 0, maxArgs: 0, distElWise: false, usage: 'scripting' }),
|
|
32
|
+
and: (0, dispatch_1.systemFunction)({ fn: controlFlow_1.AND, minArgs: 2, maxArgs: -1, distElWise: false, deferArguments: true, usage: 'scripting' }),
|
|
33
|
+
or: (0, dispatch_1.systemFunction)({ fn: controlFlow_1.OR, minArgs: 2, maxArgs: -1, distElWise: false, deferArguments: true, usage: 'scripting' }),
|
|
34
|
+
not: (0, dispatch_1.systemFunction)({ fn: controlFlow_1.NOT, minArgs: 1, maxArgs: 1, distElWise: false, usage: 'scripting' }),
|
|
35
|
+
xor: (0, dispatch_1.systemFunction)({ fn: controlFlow_1.XOR, minArgs: 2, maxArgs: -1, distElWise: false, usage: 'scripting' }),
|
|
36
|
+
iferror: (0, dispatch_1.systemFunction)({ fn: controlFlow_1.IFERROR, minArgs: 2, maxArgs: 2, distElWise: false, deferArguments: true, usage: 'scripting' }),
|
|
37
|
+
iserror: (0, dispatch_1.systemFunction)({ fn: controlFlow_1.ISERROR, minArgs: 1, maxArgs: 1, distElWise: false, deferArguments: true, usage: 'scripting' }),
|
|
38
|
+
if: (0, dispatch_1.systemFunction)({ fn: controlFlow_1.IF, minArgs: 2, maxArgs: 3, distElWise: false, deferArguments: true, returnBoundary: true, usage: 'scripting' }),
|
|
39
|
+
while: (0, dispatch_1.systemFunction)({ fn: controlFlow_1.WHILE, minArgs: 2, maxArgs: 2, distElWise: false, deferArguments: true, returnBoundary: true, usage: 'scripting' }),
|
|
40
|
+
for: (0, dispatch_1.systemFunction)({ fn: controlFlow_1.FOR, minArgs: 4, maxArgs: 4, distElWise: false, deferArguments: true, returnBoundary: true, usage: 'scripting' }),
|
|
41
|
+
each: (0, dispatch_1.systemFunction)({ fn: deferred_1.each, minArgs: 3, maxArgs: 4, distElWise: false, deferArguments: true, usage: 'scripting' }),
|
|
42
|
+
let: (0, dispatch_1.systemFunction)({
|
|
43
|
+
fn: scope_1.LET,
|
|
44
|
+
minArgs: 3,
|
|
45
|
+
maxArgs: -1,
|
|
46
|
+
distElWise: false,
|
|
47
|
+
deferArguments: true,
|
|
48
|
+
normalizeDeferredArguments: scope_1.normalizeLetArguments,
|
|
49
|
+
returnBoundary: true,
|
|
50
|
+
usage: 'scripting',
|
|
51
|
+
}),
|
|
52
|
+
block: (0, dispatch_1.systemFunction)({
|
|
53
|
+
fn: controlFlow_1.BLOCK,
|
|
54
|
+
minArgs: -1,
|
|
55
|
+
maxArgs: -1,
|
|
56
|
+
distElWise: false,
|
|
57
|
+
deferArguments: true,
|
|
58
|
+
returnBoundary: true,
|
|
59
|
+
usage: 'scripting',
|
|
60
|
+
}),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ParserEntity } from '../../../types';
|
|
2
|
+
import type { DeferredFunctionArgument } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Evaluates a deferred parser value and returns the resolved input if evaluation cannot complete.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* A Dictionary supplied as the second argument provides substitutions for this evaluation only.
|
|
8
|
+
* Those names are passed through the same call-scoped parser-value mechanism used by
|
|
9
|
+
* `Parser.parse(..., values)`; they are not written to the parser's known-value table.
|
|
10
|
+
*
|
|
11
|
+
* This distinction matters for reserved names. The solver index `_n` cannot be assigned
|
|
12
|
+
* globally with `_n: value`, but it can be supplied locally when evaluating a parametric
|
|
13
|
+
* `SolutionSet`. For example, `evaluate(solve(sin(x),x),{_n=>0})` returns `{0}`.
|
|
14
|
+
*
|
|
15
|
+
* When a solver result is stored first in Nerdamer Scripting, use `:` for assignment:
|
|
16
|
+
* `sol: solve(sin(x),x); evaluate(sol,{_n=>0})`. The `=` operator denotes an equation;
|
|
17
|
+
* it does not store a parser value in a variable.
|
|
18
|
+
*/
|
|
19
|
+
export declare function evaluate(value: DeferredFunctionArgument, substitutions?: DeferredFunctionArgument, point?: DeferredFunctionArgument): ParserEntity;
|
|
20
|
+
/**
|
|
21
|
+
* Evaluates a parser value numerically at a finite significant-digit precision.
|
|
22
|
+
*/
|
|
23
|
+
export declare function numeric(value: DeferredFunctionArgument, precision?: DeferredFunctionArgument): ParserEntity;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluate = evaluate;
|
|
4
|
+
exports.numeric = numeric;
|
|
5
|
+
const math_1 = require("../../../../math/math");
|
|
6
|
+
const errors_1 = require("../../../errors");
|
|
7
|
+
const Collection_1 = require("../../collection/Collection");
|
|
8
|
+
const Dictionary_1 = require("../../dictionary/Dictionary");
|
|
9
|
+
const Equation_1 = require("../../equation/Equation");
|
|
10
|
+
const Expression_1 = require("../../expression/Expression");
|
|
11
|
+
const utils_1 = require("../../expression/utils");
|
|
12
|
+
const Matrix_1 = require("../../matrix/Matrix");
|
|
13
|
+
const ValuesSet_1 = require("../../valuesSet/ValuesSet");
|
|
14
|
+
const Vector_1 = require("../../vector/Vector");
|
|
15
|
+
const constants_1 = require("../constants");
|
|
16
|
+
const EVALUATE_FUNCTION = 'evaluate';
|
|
17
|
+
/**
|
|
18
|
+
* Evaluates a deferred parser value and returns the resolved input if evaluation cannot complete.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* A Dictionary supplied as the second argument provides substitutions for this evaluation only.
|
|
22
|
+
* Those names are passed through the same call-scoped parser-value mechanism used by
|
|
23
|
+
* `Parser.parse(..., values)`; they are not written to the parser's known-value table.
|
|
24
|
+
*
|
|
25
|
+
* This distinction matters for reserved names. The solver index `_n` cannot be assigned
|
|
26
|
+
* globally with `_n: value`, but it can be supplied locally when evaluating a parametric
|
|
27
|
+
* `SolutionSet`. For example, `evaluate(solve(sin(x),x),{_n=>0})` returns `{0}`.
|
|
28
|
+
*
|
|
29
|
+
* When a solver result is stored first in Nerdamer Scripting, use `:` for assignment:
|
|
30
|
+
* `sol: solve(sin(x),x); evaluate(sol,{_n=>0})`. The `=` operator denotes an equation;
|
|
31
|
+
* it does not store a parser value in a variable.
|
|
32
|
+
*/
|
|
33
|
+
function evaluate(value, substitutions, point) {
|
|
34
|
+
const input = value();
|
|
35
|
+
let values;
|
|
36
|
+
if (substitutions) {
|
|
37
|
+
const resolved = substitutions();
|
|
38
|
+
values = {};
|
|
39
|
+
if (point) {
|
|
40
|
+
const resolvedPoint = point();
|
|
41
|
+
if (!Vector_1.Vector.isVector(resolved)) {
|
|
42
|
+
throw new errors_1.UnexpectedDataType((0, errors_1.message)('vectorExpected', { type: constants_1.dataTypes[resolved.dataType] }));
|
|
43
|
+
}
|
|
44
|
+
if (!Vector_1.Vector.isVector(resolvedPoint)) {
|
|
45
|
+
throw new errors_1.UnexpectedDataType((0, errors_1.message)('vectorExpected', { type: constants_1.dataTypes[resolvedPoint.dataType] }));
|
|
46
|
+
}
|
|
47
|
+
if (resolved.count() !== resolvedPoint.count()) {
|
|
48
|
+
throw new errors_1.DimensionError((0, errors_1.message)('mismatchedDimensions', { function: EVALUATE_FUNCTION }));
|
|
49
|
+
}
|
|
50
|
+
for (let i = 0; i < resolved.count(); i++) {
|
|
51
|
+
const variable = resolved.elements[i];
|
|
52
|
+
if (!Expression_1.Expression.isExpression(variable)) {
|
|
53
|
+
throw new errors_1.UnexpectedDataType((0, errors_1.message)('expressionExpected', { type: constants_1.dataTypes[variable.dataType] }));
|
|
54
|
+
}
|
|
55
|
+
values[(0, utils_1.assertPlainVariableAndGetString)(variable)] = resolvedPoint.elements[i];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
if (!Dictionary_1.Dictionary.isDictionary(resolved)) {
|
|
60
|
+
throw new errors_1.UnexpectedDataType((0, errors_1.message)('unsupportedType', { type: constants_1.dataTypes[resolved.dataType] }));
|
|
61
|
+
}
|
|
62
|
+
for (const [name, substitution] of resolved) {
|
|
63
|
+
values[name] = substitution;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
let retval = input;
|
|
68
|
+
try {
|
|
69
|
+
if (values &&
|
|
70
|
+
(Expression_1.Expression.isExpression(input) ||
|
|
71
|
+
Vector_1.Vector.isVector(input) ||
|
|
72
|
+
Matrix_1.Matrix.isMatrix(input) ||
|
|
73
|
+
ValuesSet_1.ValuesSet.isValuesSet(input))) {
|
|
74
|
+
retval = input.evaluate(values);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
retval = input.evaluate();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
retval = input;
|
|
82
|
+
}
|
|
83
|
+
return retval;
|
|
84
|
+
}
|
|
85
|
+
function applyNumeric(value, precision) {
|
|
86
|
+
let retval;
|
|
87
|
+
if (Expression_1.Expression.isExpression(value)) {
|
|
88
|
+
retval = (0, math_1.numeric)(value, precision);
|
|
89
|
+
}
|
|
90
|
+
else if (Equation_1.Equation.isEquation(value)) {
|
|
91
|
+
retval = value.copy().each(e => Expression_1.Expression.isExpression(e) ? (0, math_1.numeric)(e, precision) : e);
|
|
92
|
+
}
|
|
93
|
+
else if (Vector_1.Vector.isVector(value)) {
|
|
94
|
+
retval = value.copy().each(e => applyNumeric(e, precision));
|
|
95
|
+
}
|
|
96
|
+
else if (Matrix_1.Matrix.isMatrix(value)) {
|
|
97
|
+
retval = value.copy().each(e => (0, math_1.numeric)(e, precision));
|
|
98
|
+
}
|
|
99
|
+
else if (Collection_1.Collection.isCollection(value)) {
|
|
100
|
+
retval = value.copy().each(e => applyNumeric(e, precision));
|
|
101
|
+
}
|
|
102
|
+
else if (Dictionary_1.Dictionary.isDictionary(value)) {
|
|
103
|
+
retval = value.copy().each(e => applyNumeric(e, precision));
|
|
104
|
+
}
|
|
105
|
+
else if (ValuesSet_1.ValuesSet.isValuesSet(value)) {
|
|
106
|
+
retval = value.copy().each(e => applyNumeric(e, precision));
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
retval = value;
|
|
110
|
+
}
|
|
111
|
+
return retval;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Evaluates a parser value numerically at a finite significant-digit precision.
|
|
115
|
+
*/
|
|
116
|
+
function numeric(value, precision) {
|
|
117
|
+
const input = value();
|
|
118
|
+
let digits;
|
|
119
|
+
if (precision) {
|
|
120
|
+
const resolved = precision();
|
|
121
|
+
if (!Expression_1.Expression.isExpression(resolved)) {
|
|
122
|
+
throw new errors_1.UnexpectedDataType((0, errors_1.message)('expressionExpected', { type: constants_1.dataTypes[resolved.dataType] }));
|
|
123
|
+
}
|
|
124
|
+
digits = resolved;
|
|
125
|
+
}
|
|
126
|
+
const retval = applyNumeric(input, digits);
|
|
127
|
+
return retval;
|
|
128
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ParserEntity } from '../../../types';
|
|
2
|
+
import type { DeferredFunctionArgument } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Evaluates a symbolic user-function body with call-scoped argument bindings.
|
|
5
|
+
*
|
|
6
|
+
* Arguments temporarily shadow parser known values so ordinary assignment can update a
|
|
7
|
+
* function parameter during the call. Previous bindings are restored afterward, including
|
|
8
|
+
* when RETURN or another error unwinds evaluation. A string body is parsed per invocation;
|
|
9
|
+
* a deferred parser body reuses its compiled RPN while still resolving current parameter and
|
|
10
|
+
* known-value state. RETURN is consumed at the function boundary so its parser entity becomes
|
|
11
|
+
* the function result and cannot escape into the caller. BREAK and CONTINUE are also rejected
|
|
12
|
+
* at that boundary so loop control cannot cross a function call.
|
|
13
|
+
*/
|
|
14
|
+
export declare function wrappedFunction(expression: string | DeferredFunctionArgument, argList: string[]): (...inputs: ParserEntity[]) => ParserEntity;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wrappedFunction = wrappedFunction;
|
|
4
|
+
const Parser_1 = require("../Parser");
|
|
5
|
+
const controlFlow_1 = require("./controlFlow");
|
|
6
|
+
/**
|
|
7
|
+
* Evaluates a symbolic user-function body with call-scoped argument bindings.
|
|
8
|
+
*
|
|
9
|
+
* Arguments temporarily shadow parser known values so ordinary assignment can update a
|
|
10
|
+
* function parameter during the call. Previous bindings are restored afterward, including
|
|
11
|
+
* when RETURN or another error unwinds evaluation. A string body is parsed per invocation;
|
|
12
|
+
* a deferred parser body reuses its compiled RPN while still resolving current parameter and
|
|
13
|
+
* known-value state. RETURN is consumed at the function boundary so its parser entity becomes
|
|
14
|
+
* the function result and cannot escape into the caller. BREAK and CONTINUE are also rejected
|
|
15
|
+
* at that boundary so loop control cannot cross a function call.
|
|
16
|
+
*/
|
|
17
|
+
function wrappedFunction(expression, argList) {
|
|
18
|
+
return (...inputs) => {
|
|
19
|
+
const previousValues = new Map();
|
|
20
|
+
const previouslyUndefined = new Set();
|
|
21
|
+
for (let i = 0; i < argList.length; i++) {
|
|
22
|
+
const name = argList[i];
|
|
23
|
+
if (!previousValues.has(name) && !previouslyUndefined.has(name)) {
|
|
24
|
+
if (Object.prototype.hasOwnProperty.call(Parser_1.Parser.KNOWN_VALUES, name)) {
|
|
25
|
+
previousValues.set(name, Parser_1.Parser.KNOWN_VALUES[name]);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
previouslyUndefined.add(name);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
Parser_1.Parser.KNOWN_VALUES[name] = inputs[i];
|
|
32
|
+
}
|
|
33
|
+
let retval;
|
|
34
|
+
try {
|
|
35
|
+
retval = (0, controlFlow_1.functionBoundary)(() => {
|
|
36
|
+
let result;
|
|
37
|
+
if (typeof expression === 'string') {
|
|
38
|
+
result = Parser_1.Parser.parse(expression);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// Function declarations should not capture temporary Parser.parse(..., values)
|
|
42
|
+
// substitutions from registration. Parameter and persistent known values are
|
|
43
|
+
// resolved from the current call instead.
|
|
44
|
+
result = expression({ inheritValues: false });
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
for (const [name, value] of previousValues) {
|
|
51
|
+
Parser_1.Parser.KNOWN_VALUES[name] = value;
|
|
52
|
+
}
|
|
53
|
+
for (const name of previouslyUndefined) {
|
|
54
|
+
delete Parser_1.Parser.KNOWN_VALUES[name];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return retval;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Scope } from '../../../common/classes/Scope';
|
|
2
|
+
import { Expression } from '../../expression/Expression';
|
|
3
|
+
import type { ExpressionInput, ParserEntity } from '../../../types';
|
|
4
|
+
import type { DeferredFunctionArgument } from '../types';
|
|
5
|
+
export declare function assign(a: ExpressionInput, b: ParserEntity | string | DeferredFunctionArgument): ParserEntity;
|
|
6
|
+
export declare function normalizeLetArguments(argumentScopes: Scope[]): Scope[];
|
|
7
|
+
export declare function LET(...args: DeferredFunctionArgument[]): ParserEntity;
|
|
8
|
+
export declare function unassign(x: Expression | string | DeferredFunctionArgument): Expression;
|
|
@@ -0,0 +1,132 @@
|
|
|
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 controlFlowSignals_1 = require("../controlFlowSignals");
|
|
14
|
+
const Parser_1 = require("../Parser");
|
|
15
|
+
const Token_1 = require("../Token");
|
|
16
|
+
const controlFlow_1 = require("./controlFlow");
|
|
17
|
+
function assign(a, b) {
|
|
18
|
+
a = Expression_1.Expression.create(a);
|
|
19
|
+
if (Expression_1.Expression.isExpression(a) && !a.isPlainVariable()) {
|
|
20
|
+
throw new errors_1.UnexpectedInputError((0, errors_1.message)('plainVariableExpected', { input: String(a) }));
|
|
21
|
+
}
|
|
22
|
+
if (Settings_1.RESTRICTED.includes(a.value))
|
|
23
|
+
throw new errors_1.AssignmentError((0, errors_1.message)('restrictedVariableName', { name: a.value }));
|
|
24
|
+
let value;
|
|
25
|
+
try {
|
|
26
|
+
if (typeof b === 'function')
|
|
27
|
+
value = b();
|
|
28
|
+
else if (typeof b === 'string')
|
|
29
|
+
value = Parser_1.Parser.parse(b);
|
|
30
|
+
else
|
|
31
|
+
value = b;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (controlFlowSignals_1.NullSignal.isNullSignal(error)) {
|
|
35
|
+
// A no-result RHS is assignment's one special case. It is equivalent to x:x:
|
|
36
|
+
// preserve an existing binding, or leave an unbound name unresolved.
|
|
37
|
+
return Parser_1.Parser.KNOWN_VALUES[a.value]?.copy() ?? a;
|
|
38
|
+
}
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
Parser_1.Parser.KNOWN_VALUES[a.value] = value;
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
function normalizeLetArguments(argumentScopes) {
|
|
45
|
+
const normalizedScopes = [];
|
|
46
|
+
for (let i = 0; i < argumentScopes.length; i++) {
|
|
47
|
+
const argumentScope = argumentScopes[i];
|
|
48
|
+
let assignmentIndex = -1;
|
|
49
|
+
if (i < argumentScopes.length - 1) {
|
|
50
|
+
for (let j = 0; j < argumentScope.length; j++) {
|
|
51
|
+
const argumentToken = argumentScope[j];
|
|
52
|
+
if (Token_1.Token.isToken(argumentToken) && argumentToken.type === Token_1.Token.OPERATOR && argumentToken.value === constants_1.ASSIGN) {
|
|
53
|
+
assignmentIndex = j;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (assignmentIndex > 0 && assignmentIndex < argumentScope.length - 1) {
|
|
59
|
+
const nameScope = new Scope_1.Scope(argumentScope.type, argumentScope.column);
|
|
60
|
+
const valueScope = new Scope_1.Scope(argumentScope.type, argumentScope.column);
|
|
61
|
+
for (let j = 0; j < assignmentIndex; j++)
|
|
62
|
+
nameScope.push(argumentScope[j]);
|
|
63
|
+
for (let j = assignmentIndex + 1; j < argumentScope.length; j++)
|
|
64
|
+
valueScope.push(argumentScope[j]);
|
|
65
|
+
normalizedScopes.push(nameScope, valueScope);
|
|
66
|
+
}
|
|
67
|
+
else
|
|
68
|
+
normalizedScopes.push(argumentScope);
|
|
69
|
+
}
|
|
70
|
+
return normalizedScopes;
|
|
71
|
+
}
|
|
72
|
+
function LET(...args) {
|
|
73
|
+
if (args.length < 3 || args.length % 2 === 0)
|
|
74
|
+
throw new errors_1.ParserError((0, errors_1.message)('letRequiresBindingsAndBody'));
|
|
75
|
+
const previousValues = new Map();
|
|
76
|
+
const previouslyUndefined = new Set();
|
|
77
|
+
const localNames = [];
|
|
78
|
+
let retval;
|
|
79
|
+
try {
|
|
80
|
+
for (let i = 0; i < args.length - 1; i += 2) {
|
|
81
|
+
const nameExpression = args[i]({ inheritValues: false, substitute: false });
|
|
82
|
+
if (!Expression_1.Expression.isExpression(nameExpression)) {
|
|
83
|
+
throw new errors_1.UnexpectedInputError((0, errors_1.message)('plainVariableExpected', { input: nameExpression.text() }));
|
|
84
|
+
}
|
|
85
|
+
const name = (0, utils_1.assertPlainVariableAndGetString)(nameExpression);
|
|
86
|
+
const value = args[i + 1]({ excludeValues: localNames });
|
|
87
|
+
if (!previousValues.has(name) && !previouslyUndefined.has(name)) {
|
|
88
|
+
if (Object.prototype.hasOwnProperty.call(Parser_1.Parser.KNOWN_VALUES, name))
|
|
89
|
+
previousValues.set(name, Parser_1.Parser.KNOWN_VALUES[name]);
|
|
90
|
+
else
|
|
91
|
+
previouslyUndefined.add(name);
|
|
92
|
+
}
|
|
93
|
+
assign(nameExpression, value);
|
|
94
|
+
if (!localNames.includes(name))
|
|
95
|
+
localNames.push(name);
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
retval = args[args.length - 1]({ excludeValues: localNames });
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
if ((0, controlFlow_1.shouldConsumeLocalReturn)() && controlFlow_1.ReturnSignal.isReturnSignal(error))
|
|
102
|
+
retval = error.value;
|
|
103
|
+
else
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
for (const [name, value] of previousValues)
|
|
109
|
+
Parser_1.Parser.KNOWN_VALUES[name] = value;
|
|
110
|
+
for (const name of previouslyUndefined)
|
|
111
|
+
delete Parser_1.Parser.KNOWN_VALUES[name];
|
|
112
|
+
}
|
|
113
|
+
return retval;
|
|
114
|
+
}
|
|
115
|
+
function unassign(x) {
|
|
116
|
+
let variable;
|
|
117
|
+
let name;
|
|
118
|
+
if (typeof x === 'function') {
|
|
119
|
+
const parsed = x({ inheritValues: false, substitute: false });
|
|
120
|
+
if (!Expression_1.Expression.isExpression(parsed))
|
|
121
|
+
throw new errors_1.UnexpectedInputError((0, errors_1.message)('plainVariableExpected', { input: parsed.text() }));
|
|
122
|
+
variable = parsed;
|
|
123
|
+
}
|
|
124
|
+
else
|
|
125
|
+
variable = x;
|
|
126
|
+
if (Expression_1.Expression.isExpression(variable))
|
|
127
|
+
name = (0, utils_1.assertPlainVariableAndGetString)(variable);
|
|
128
|
+
else
|
|
129
|
+
name = variable;
|
|
130
|
+
delete Parser_1.Parser.KNOWN_VALUES[name];
|
|
131
|
+
return Expression_1.Expression.create(variable);
|
|
132
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
/**
|
|
92
|
+
* Render numeric values in scientific notation with exactly this many significant digits (1–1e9).
|
|
93
|
+
* Numeric powers use scientific notation only when the formatted exponent remains exact.
|
|
94
|
+
*/
|
|
95
|
+
scientific?: number;
|
|
96
|
+
/** Sort sum and product elements with {@link Expression.sortFunction} before rendering. */
|
|
97
|
+
sort?: boolean;
|
|
98
|
+
/** Parenthesize powers for output that will be embedded in JavaScript-style expressions. */
|
|
99
|
+
wrapPow?: boolean;
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* The type used when passing settings
|
|
103
|
+
*/
|
|
104
|
+
export type SimpleOptionsObject = Record<string, string | number | Expression>;
|
|
105
|
+
/**
|
|
106
|
+
* The type supported by Decimal implementations of algorithms
|
|
107
|
+
*/
|
|
108
|
+
export type DecimalType = Decimal | number | string;
|
|
109
|
+
/**
|
|
110
|
+
* Native JavaScript function produced or consumed by numerical compilation APIs.
|
|
111
|
+
*
|
|
112
|
+
* Arguments and numeric results use JavaScript `number` arithmetic rather than
|
|
113
|
+
* Nerdamer's exact rational or arbitrary-precision symbolic representation. Boolean
|
|
114
|
+
* results support compiled comparison expressions.
|
|
115
|
+
*/
|
|
116
|
+
export type JsFunction = (...args: number[]) => number | boolean;
|
|
117
|
+
/**
|
|
118
|
+
* A simple expression function call
|
|
119
|
+
*/
|
|
120
|
+
export type ExpressionFunction = (...args: Expression[]) => Expression;
|
|
121
|
+
/**
|
|
122
|
+
* Internal values that may temporarily exist on the parser output stack.
|
|
123
|
+
* IndexedReference and KeyValuePair are resolved or consumed before parseRPN returns.
|
|
124
|
+
* Deferred callbacks are consumed only by operators that explicitly request them.
|
|
125
|
+
*/
|
|
126
|
+
export type ParserStackValue = ParserEntity | IndexedReference | KeyValuePair | DeferredFunctionArgument;
|
|
127
|
+
/**
|
|
128
|
+
* An array containing numerator and denominator
|
|
129
|
+
*/
|
|
130
|
+
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;
|