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.
Files changed (387) hide show
  1. package/BREAKING_CHANGES.md +244 -5
  2. package/LICENSE.md +184 -0
  3. package/README.md +232 -318
  4. package/dist/bundle.js +2 -0
  5. package/dist/bundle.js.LICENSE.txt +7 -0
  6. package/dist/parser.js +2 -0
  7. package/dist/parser.js.LICENSE.txt +7 -0
  8. package/docs-data/parser-functions.json +2248 -0
  9. package/index.d.ts +10 -426
  10. package/output/algebra/adapters.d.ts +3 -0
  11. package/output/algebra/adapters.js +11 -0
  12. package/output/algebra/algorithms/arith.d.ts +84 -0
  13. package/output/algebra/algorithms/arith.js +324 -0
  14. package/output/algebra/algorithms/groebnerBase.d.ts +161 -0
  15. package/output/algebra/algorithms/groebnerBase.js +929 -0
  16. package/output/algebra/dispatch.d.ts +1 -0
  17. package/output/algebra/dispatch.js +25 -0
  18. package/output/algebra/factor/factor.d.ts +77 -0
  19. package/output/algebra/factor/factor.js +245 -0
  20. package/output/algebra/gcd/gcd.d.ts +30 -0
  21. package/output/algebra/gcd/gcd.js +95 -0
  22. package/output/algebra/groebner.d.ts +21 -0
  23. package/output/algebra/groebner.js +36 -0
  24. package/output/algebra/partfrac.d.ts +19 -0
  25. package/output/algebra/partfrac.js +365 -0
  26. package/output/algebra/polynomial/ModularSparsePolynomial.d.ts +131 -0
  27. package/output/algebra/polynomial/ModularSparsePolynomial.js +378 -0
  28. package/output/algebra/polynomial/ModularSparsePolynomialFactor.d.ts +40 -0
  29. package/output/algebra/polynomial/ModularSparsePolynomialFactor.js +661 -0
  30. package/output/algebra/polynomial/SparsePolynomialFactor.d.ts +64 -0
  31. package/output/algebra/polynomial/SparsePolynomialFactor.js +492 -0
  32. package/output/algebra/polynomial/SparsePolynomialGcd.d.ts +29 -0
  33. package/output/algebra/polynomial/SparsePolynomialGcd.js +259 -0
  34. package/output/algebra/polynomial/SparsePolynomialMultivariateFactor.d.ts +82 -0
  35. package/output/algebra/polynomial/SparsePolynomialMultivariateFactor.js +604 -0
  36. package/output/algebra/polynomial/modularGcd.d.ts +40 -0
  37. package/output/algebra/polynomial/modularGcd.js +365 -0
  38. package/output/algebra/polynomialize.d.ts +20 -0
  39. package/output/algebra/polynomialize.js +26 -0
  40. package/output/algebra/simplify/complexsimp.d.ts +7 -0
  41. package/output/algebra/simplify/complexsimp.js +24 -0
  42. package/output/algebra/simplify/factorCommon.d.ts +13 -0
  43. package/output/algebra/simplify/factorCommon.js +136 -0
  44. package/output/algebra/simplify/funcsimp.d.ts +26 -0
  45. package/output/algebra/simplify/funcsimp.js +633 -0
  46. package/output/algebra/simplify/invtrigrewrite.d.ts +10 -0
  47. package/output/algebra/simplify/invtrigrewrite.js +96 -0
  48. package/output/algebra/simplify/ratsimp.d.ts +21 -0
  49. package/output/algebra/simplify/ratsimp.js +140 -0
  50. package/output/algebra/simplify/simplify.d.ts +25 -0
  51. package/output/algebra/simplify/simplify.js +237 -0
  52. package/output/algebra/simplify/trigreduce.d.ts +38 -0
  53. package/output/algebra/simplify/trigreduce.js +424 -0
  54. package/output/algebra/simplify/trigrewrite.d.ts +17 -0
  55. package/output/algebra/simplify/trigrewrite.js +156 -0
  56. package/output/algebra/simplify/trigsimp.d.ts +11 -0
  57. package/output/algebra/simplify/trigsimp.js +369 -0
  58. package/output/algebra/simplify/utils.d.ts +32 -0
  59. package/output/algebra/simplify/utils.js +56 -0
  60. package/output/algebra/utils.d.ts +32 -0
  61. package/output/algebra/utils.js +48 -0
  62. package/output/api/advanced.d.ts +8 -0
  63. package/output/api/advanced.js +18 -0
  64. package/output/api/algebra.d.ts +17 -0
  65. package/output/api/algebra.js +35 -0
  66. package/output/api/assumptions.d.ts +4 -0
  67. package/output/api/assumptions.js +11 -0
  68. package/output/api/calculus.d.ts +10 -0
  69. package/output/api/calculus.js +22 -0
  70. package/output/api/core.d.ts +17 -0
  71. package/output/api/core.js +41 -0
  72. package/output/api/debug.d.ts +16 -0
  73. package/output/api/debug.js +23 -0
  74. package/output/api/languages/deu.d.ts +3 -0
  75. package/output/api/languages/deu.js +266 -0
  76. package/output/api/languages/fra.d.ts +3 -0
  77. package/output/api/languages/fra.js +266 -0
  78. package/output/api/languages/ita.d.ts +3 -0
  79. package/output/api/languages/ita.js +266 -0
  80. package/output/api/languages/nld.d.ts +3 -0
  81. package/output/api/languages/nld.js +266 -0
  82. package/output/api/languages/por.d.ts +3 -0
  83. package/output/api/languages/por.js +266 -0
  84. package/output/api/languages/spa.d.ts +3 -0
  85. package/output/api/languages/spa.js +266 -0
  86. package/output/api/parser.d.ts +93 -0
  87. package/output/api/parser.js +18 -0
  88. package/output/api/solve.d.ts +10 -0
  89. package/output/api/solve.js +17 -0
  90. package/output/api/structures.d.ts +10 -0
  91. package/output/api/structures.js +23 -0
  92. package/output/calculus/adapters.d.ts +8 -0
  93. package/output/calculus/adapters.js +41 -0
  94. package/output/calculus/derivative/diff.d.ts +30 -0
  95. package/output/calculus/derivative/diff.js +241 -0
  96. package/output/calculus/dispatch.d.ts +1 -0
  97. package/output/calculus/dispatch.js +25 -0
  98. package/output/calculus/fresnel.d.ts +16 -0
  99. package/output/calculus/fresnel.js +39 -0
  100. package/output/calculus/integrate/byParts.d.ts +18 -0
  101. package/output/calculus/integrate/byParts.js +339 -0
  102. package/output/calculus/integrate/bySubstitution.d.ts +135 -0
  103. package/output/calculus/integrate/bySubstitution.js +411 -0
  104. package/output/calculus/integrate/integrate.d.ts +38 -0
  105. package/output/calculus/integrate/integrate.js +652 -0
  106. package/output/calculus/integrate/integrationTable.d.ts +2 -0
  107. package/output/calculus/integrate/integrationTable.js +914 -0
  108. package/output/calculus/integrate/utils.d.ts +28 -0
  109. package/output/calculus/integrate/utils.js +96 -0
  110. package/output/calculus/laplace/ilaplace.d.ts +31 -0
  111. package/output/calculus/laplace/ilaplace.js +192 -0
  112. package/output/calculus/laplace/ilaplaceTable.d.ts +2 -0
  113. package/output/calculus/laplace/ilaplaceTable.js +200 -0
  114. package/output/calculus/laplace/laplace.d.ts +22 -0
  115. package/output/calculus/laplace/laplace.js +109 -0
  116. package/output/calculus/laplace/laplaceTable.d.ts +2 -0
  117. package/output/calculus/laplace/laplaceTable.js +187 -0
  118. package/output/calculus/limit/limit.d.ts +35 -0
  119. package/output/calculus/limit/limit.js +1183 -0
  120. package/output/calculus/limit/limitsTable.d.ts +2 -0
  121. package/output/calculus/limit/limitsTable.js +7 -0
  122. package/output/core/Settings.d.ts +32 -0
  123. package/output/core/Settings.js +68 -0
  124. package/output/core/classes/assumption/Assumption.d.ts +218 -0
  125. package/output/core/classes/assumption/Assumption.js +609 -0
  126. package/output/core/classes/assumption/assertiveFunctions.d.ts +6 -0
  127. package/output/core/classes/assumption/assertiveFunctions.js +64 -0
  128. package/output/core/classes/assumption/assume.d.ts +90 -0
  129. package/output/core/classes/assumption/assume.js +145 -0
  130. package/output/core/classes/assumption/dispatch.d.ts +1 -0
  131. package/output/core/classes/assumption/dispatch.js +11 -0
  132. package/output/core/classes/collection/Collection.d.ts +107 -0
  133. package/output/core/classes/collection/Collection.js +240 -0
  134. package/output/core/classes/complex/Complex.d.ts +109 -0
  135. package/output/core/classes/complex/Complex.js +153 -0
  136. package/output/core/classes/decimalSet/DecimalSet.d.ts +226 -0
  137. package/output/core/classes/decimalSet/DecimalSet.js +454 -0
  138. package/output/core/classes/dictionary/Dictionary.d.ts +102 -0
  139. package/output/core/classes/dictionary/Dictionary.js +216 -0
  140. package/output/core/classes/equation/Equation.d.ts +256 -0
  141. package/output/core/classes/equation/Equation.js +350 -0
  142. package/output/core/classes/expression/CoeffObject.d.ts +100 -0
  143. package/output/core/classes/expression/CoeffObject.js +197 -0
  144. package/output/core/classes/expression/Expression.d.ts +1691 -0
  145. package/output/core/classes/expression/Expression.js +2381 -0
  146. package/output/core/classes/expression/analysis.d.ts +25 -0
  147. package/output/core/classes/expression/analysis.js +218 -0
  148. package/output/core/classes/expression/collect.d.ts +9 -0
  149. package/output/core/classes/expression/collect.js +49 -0
  150. package/output/core/classes/expression/format.d.ts +54 -0
  151. package/output/core/classes/expression/format.js +340 -0
  152. package/output/core/classes/expression/products.d.ts +23 -0
  153. package/output/core/classes/expression/products.js +115 -0
  154. package/output/core/classes/expression/shortcuts.d.ts +35 -0
  155. package/output/core/classes/expression/shortcuts.js +129 -0
  156. package/output/core/classes/expression/traversal.d.ts +31 -0
  157. package/output/core/classes/expression/traversal.js +216 -0
  158. package/output/core/classes/expression/trig.d.ts +25 -0
  159. package/output/core/classes/expression/trig.js +40 -0
  160. package/output/core/classes/expression/utils.d.ts +61 -0
  161. package/output/core/classes/expression/utils.js +235 -0
  162. package/output/core/classes/lookupTable/LookupTable.d.ts +12 -0
  163. package/output/core/classes/lookupTable/LookupTable.js +55 -0
  164. package/output/core/classes/matrix/Matrix.d.ts +227 -0
  165. package/output/core/classes/matrix/Matrix.js +901 -0
  166. package/output/core/classes/matrix/Sylvester.d.ts +11 -0
  167. package/output/core/classes/matrix/Sylvester.js +54 -0
  168. package/output/core/classes/matrix/dispatch.d.ts +1 -0
  169. package/output/core/classes/matrix/dispatch.js +19 -0
  170. package/output/core/classes/matrix/functions.d.ts +28 -0
  171. package/output/core/classes/matrix/functions.js +57 -0
  172. package/output/core/classes/matrix/utils.d.ts +9 -0
  173. package/output/core/classes/matrix/utils.js +22 -0
  174. package/output/core/classes/parser/Parser.d.ts +493 -0
  175. package/output/core/classes/parser/Parser.js +1863 -0
  176. package/output/core/classes/parser/Token.d.ts +58 -0
  177. package/output/core/classes/parser/Token.js +137 -0
  178. package/output/core/classes/parser/constants.d.ts +162 -0
  179. package/output/core/classes/parser/constants.js +229 -0
  180. package/output/core/classes/parser/controlFlowSignals.d.ts +38 -0
  181. package/output/core/classes/parser/controlFlowSignals.js +60 -0
  182. package/output/core/classes/parser/helpers.d.ts +21 -0
  183. package/output/core/classes/parser/helpers.js +42 -0
  184. package/output/core/classes/parser/operations/add.d.ts +15 -0
  185. package/output/core/classes/parser/operations/add.js +236 -0
  186. package/output/core/classes/parser/operations/comma.d.ts +7 -0
  187. package/output/core/classes/parser/operations/comma.js +11 -0
  188. package/output/core/classes/parser/operations/compare.d.ts +21 -0
  189. package/output/core/classes/parser/operations/compare.js +474 -0
  190. package/output/core/classes/parser/operations/divide.d.ts +2 -0
  191. package/output/core/classes/parser/operations/divide.js +72 -0
  192. package/output/core/classes/parser/operations/functions.d.ts +46 -0
  193. package/output/core/classes/parser/operations/functions.js +438 -0
  194. package/output/core/classes/parser/operations/multiply.d.ts +11 -0
  195. package/output/core/classes/parser/operations/multiply.js +328 -0
  196. package/output/core/classes/parser/operations/power.d.ts +48 -0
  197. package/output/core/classes/parser/operations/power.js +673 -0
  198. package/output/core/classes/parser/operations/subtract.d.ts +3 -0
  199. package/output/core/classes/parser/operations/subtract.js +36 -0
  200. package/output/core/classes/parser/preprocess.d.ts +7 -0
  201. package/output/core/classes/parser/preprocess.js +246 -0
  202. package/output/core/classes/parser/scripting/controlFlow.d.ts +23 -0
  203. package/output/core/classes/parser/scripting/controlFlow.js +279 -0
  204. package/output/core/classes/parser/scripting/deferred.d.ts +4 -0
  205. package/output/core/classes/parser/scripting/deferred.js +65 -0
  206. package/output/core/classes/parser/scripting/dispatch.d.ts +1 -0
  207. package/output/core/classes/parser/scripting/dispatch.js +62 -0
  208. package/output/core/classes/parser/scripting/evaluate.d.ts +23 -0
  209. package/output/core/classes/parser/scripting/evaluate.js +128 -0
  210. package/output/core/classes/parser/scripting/functions.d.ts +14 -0
  211. package/output/core/classes/parser/scripting/functions.js +59 -0
  212. package/output/core/classes/parser/scripting/scope.d.ts +8 -0
  213. package/output/core/classes/parser/scripting/scope.js +132 -0
  214. package/output/core/classes/parser/types.d.ts +130 -0
  215. package/output/core/classes/parser/types.js +2 -0
  216. package/output/core/classes/parser/wrappers/IndexedReference.d.ts +31 -0
  217. package/output/core/classes/parser/wrappers/IndexedReference.js +68 -0
  218. package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +24 -0
  219. package/output/core/classes/parser/wrappers/KeyValuePair.js +51 -0
  220. package/output/core/classes/polynomial/Polynomial.d.ts +504 -0
  221. package/output/core/classes/polynomial/Polynomial.js +1195 -0
  222. package/output/core/classes/polynomial/SparsePolynomial.d.ts +221 -0
  223. package/output/core/classes/polynomial/SparsePolynomial.js +824 -0
  224. package/output/core/classes/polynomial/SparsePolynomialAdapter.d.ts +56 -0
  225. package/output/core/classes/polynomial/SparsePolynomialAdapter.js +241 -0
  226. package/output/core/classes/polynomial/Term.d.ts +222 -0
  227. package/output/core/classes/polynomial/Term.js +430 -0
  228. package/output/core/classes/polynomial/adapters.d.ts +18 -0
  229. package/output/core/classes/polynomial/adapters.js +33 -0
  230. package/output/core/classes/polynomial/dispatch.d.ts +1 -0
  231. package/output/core/classes/polynomial/dispatch.js +14 -0
  232. package/output/core/classes/polynomial/functions.d.ts +77 -0
  233. package/output/core/classes/polynomial/functions.js +189 -0
  234. package/output/core/classes/polynomial/utils.d.ts +62 -0
  235. package/output/core/classes/polynomial/utils.js +207 -0
  236. package/output/core/classes/rational/Rational.d.ts +501 -0
  237. package/output/core/classes/rational/Rational.js +829 -0
  238. package/output/core/classes/seq/SEQ.d.ts +13 -0
  239. package/output/core/classes/seq/SEQ.js +137 -0
  240. package/output/core/classes/valuesSet/ValuesSet.d.ts +187 -0
  241. package/output/core/classes/valuesSet/ValuesSet.js +399 -0
  242. package/output/core/classes/vector/Vector.d.ts +222 -0
  243. package/output/core/classes/vector/Vector.js +501 -0
  244. package/output/core/classes/vector/dispatch.d.ts +1 -0
  245. package/output/core/classes/vector/dispatch.js +11 -0
  246. package/output/core/classes/vector/functions.d.ts +28 -0
  247. package/output/core/classes/vector/functions.js +47 -0
  248. package/output/core/common/classes/MathematicalAggregate.d.ts +53 -0
  249. package/output/core/common/classes/MathematicalAggregate.js +149 -0
  250. package/output/core/common/classes/Scope.d.ts +62 -0
  251. package/output/core/common/classes/Scope.js +122 -0
  252. package/output/core/common/classes/StructuredEntity.d.ts +55 -0
  253. package/output/core/common/classes/StructuredEntity.js +151 -0
  254. package/output/core/common/common.d.ts +62 -0
  255. package/output/core/common/common.js +74 -0
  256. package/output/core/common/functions/functions.d.ts +14 -0
  257. package/output/core/common/functions/functions.js +33 -0
  258. package/output/core/common/functions/structuredEntityUtils.d.ts +27 -0
  259. package/output/core/common/functions/structuredEntityUtils.js +40 -0
  260. package/output/core/converters/BaseConverter.d.ts +97 -0
  261. package/output/core/converters/BaseConverter.js +405 -0
  262. package/output/core/converters/Converter.d.ts +111 -0
  263. package/output/core/converters/Converter.js +806 -0
  264. package/output/core/converters/Pattern.d.ts +71 -0
  265. package/output/core/converters/Pattern.js +302 -0
  266. package/output/core/dispatch.d.ts +52 -0
  267. package/output/core/dispatch.js +26 -0
  268. package/output/core/errors.d.ts +316 -0
  269. package/output/core/errors.js +349 -0
  270. package/output/core/fullFunctions.d.ts +7 -0
  271. package/output/core/fullFunctions.js +31 -0
  272. package/output/core/functions/bigint/bigint.d.ts +133 -0
  273. package/output/core/functions/bigint/bigint.js +444 -0
  274. package/output/core/functions/bigint/primeFactor.d.ts +51 -0
  275. package/output/core/functions/bigint/primeFactor.js +267 -0
  276. package/output/core/functions/bigint/primes.d.ts +1 -0
  277. package/output/core/functions/bigint/primes.js +11 -0
  278. package/output/core/functions/build/definitions.d.ts +12 -0
  279. package/output/core/functions/build/definitions.js +139 -0
  280. package/output/core/functions/build/index.d.ts +32 -0
  281. package/output/core/functions/build/index.js +136 -0
  282. package/output/core/functions/complex.d.ts +90 -0
  283. package/output/core/functions/complex.dispatch.d.ts +1 -0
  284. package/output/core/functions/complex.dispatch.js +16 -0
  285. package/output/core/functions/complex.js +482 -0
  286. package/output/core/functions/decimal.d.ts +24 -0
  287. package/output/core/functions/decimal.js +665 -0
  288. package/output/core/functions/expand/expand.d.ts +42 -0
  289. package/output/core/functions/expand/expand.js +376 -0
  290. package/output/core/functions/fresnelNumeric.d.ts +12 -0
  291. package/output/core/functions/fresnelNumeric.js +123 -0
  292. package/output/core/functions/numeric.d.ts +140 -0
  293. package/output/core/functions/numeric.js +790 -0
  294. package/output/core/functions/rationalNormalization.d.ts +11 -0
  295. package/output/core/functions/rationalNormalization.js +117 -0
  296. package/output/core/functions/setFunction.d.ts +19 -0
  297. package/output/core/functions/setFunction.js +75 -0
  298. package/output/core/functions/string.d.ts +26 -0
  299. package/output/core/functions/string.js +102 -0
  300. package/output/core/functions/subst.d.ts +90 -0
  301. package/output/core/functions/subst.js +506 -0
  302. package/output/core/functions/utils.d.ts +24 -0
  303. package/output/core/functions/utils.js +51 -0
  304. package/output/core/parserFunctions.d.ts +7 -0
  305. package/output/core/parserFunctions.js +25 -0
  306. package/output/core/types.d.ts +48 -0
  307. package/output/core/types.js +2 -0
  308. package/output/index.d.ts +359 -0
  309. package/output/index.js +739 -0
  310. package/output/math/defint/defint.d.ts +18 -0
  311. package/output/math/defint/defint.js +60 -0
  312. package/output/math/defint/defintDecimal.d.ts +37 -0
  313. package/output/math/defint/defintDecimal.js +321 -0
  314. package/output/math/defint/defintNative.d.ts +57 -0
  315. package/output/math/defint/defintNative.js +281 -0
  316. package/output/math/dispatch.d.ts +1 -0
  317. package/output/math/dispatch.js +101 -0
  318. package/output/math/geometry.d.ts +12 -0
  319. package/output/math/geometry.js +55 -0
  320. package/output/math/math.d.ts +695 -0
  321. package/output/math/math.js +1955 -0
  322. package/output/math/trig.d.ts +518 -0
  323. package/output/math/trig.js +1444 -0
  324. package/output/math/trunc.d.ts +19 -0
  325. package/output/math/trunc.js +36 -0
  326. package/output/math/utils.d.ts +66 -0
  327. package/output/math/utils.js +219 -0
  328. package/output/solve/classes/DecimalMatrix.d.ts +17 -0
  329. package/output/solve/classes/DecimalMatrix.js +86 -0
  330. package/output/solve/classes/FunctionSolver.d.ts +135 -0
  331. package/output/solve/classes/FunctionSolver.js +433 -0
  332. package/output/solve/classes/MultivariateSolver.d.ts +84 -0
  333. package/output/solve/classes/MultivariateSolver.js +240 -0
  334. package/output/solve/classes/PolynomialSolver.d.ts +104 -0
  335. package/output/solve/classes/PolynomialSolver.js +492 -0
  336. package/output/solve/classes/SolutionSet.d.ts +172 -0
  337. package/output/solve/classes/SolutionSet.js +434 -0
  338. package/output/solve/classes/Solver.d.ts +17 -0
  339. package/output/solve/classes/Solver.js +132 -0
  340. package/output/solve/classes/SymbolicSolver.d.ts +74 -0
  341. package/output/solve/classes/SymbolicSolver.js +601 -0
  342. package/output/solve/dispatch.d.ts +1 -0
  343. package/output/solve/dispatch.js +13 -0
  344. package/output/solve/linsolve.d.ts +53 -0
  345. package/output/solve/linsolve.js +233 -0
  346. package/output/solve/solve.d.ts +44 -0
  347. package/output/solve/solve.js +368 -0
  348. package/output/solve/solveSystem.d.ts +31 -0
  349. package/output/solve/solveSystem.js +266 -0
  350. package/output/solve/utils.d.ts +10 -0
  351. package/output/solve/utils.js +58 -0
  352. package/output/utils/array.d.ts +42 -0
  353. package/output/utils/array.js +98 -0
  354. package/output/utils/debug.d.ts +131 -0
  355. package/output/utils/debug.js +296 -0
  356. package/output/utils/decimal.d.ts +3 -0
  357. package/output/utils/decimal.js +16 -0
  358. package/output/utils/numeric.d.ts +14 -0
  359. package/output/utils/numeric.js +51 -0
  360. package/output/utils/object.d.ts +26 -0
  361. package/output/utils/object.js +56 -0
  362. package/package.json +178 -57
  363. package/.travis.yml +0 -3
  364. package/Algebra.js +0 -4568
  365. package/CODE_OF_CONDUCT.md +0 -46
  366. package/CONTRIBUTING.md +0 -14
  367. package/Calculus.js +0 -2675
  368. package/Extra.js +0 -622
  369. package/Solve.js +0 -1783
  370. package/all.js +0 -16
  371. package/all.min.js +0 -1
  372. package/gulpfile.js +0 -16
  373. package/index.html +0 -158
  374. package/license.txt +0 -19
  375. package/nerdamer.core.js +0 -12510
  376. package/spec/LaTeX.spec.js +0 -302
  377. package/spec/TeXConvert.spec.js +0 -8
  378. package/spec/algebra.spec.js +0 -287
  379. package/spec/basic_parser.spec.js +0 -134
  380. package/spec/build.spec.js +0 -131
  381. package/spec/calculus.spec.js +0 -183
  382. package/spec/core.spec.js +0 -2970
  383. package/spec/extra.spec.js +0 -54
  384. package/spec/solve.spec.js +0 -126
  385. package/spec/support/jasmine.json +0 -11
  386. package/spec/support/utils.js +0 -42
  387. package/spec/text.spec.js +0 -132
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.subtract = subtract;
4
+ exports.subtractPrefix = subtractPrefix;
5
+ const errors_1 = require("../../../errors");
6
+ const Settings_1 = require("../../../Settings");
7
+ const Expression_1 = require("../../expression/Expression");
8
+ const add_1 = require("./add");
9
+ function subtract(a, b) {
10
+ let retval;
11
+ if (Settings_1.Settings.DEFER_SIMPLIFICATION) {
12
+ retval = (0, add_1.add)(a, b.neg());
13
+ retval.deferred = true;
14
+ }
15
+ else {
16
+ if (a.isNUM() && b.isNUM()) {
17
+ retval = Expression_1.Expression.fromRational(a.getMultiplier().minus(b.getMultiplier()));
18
+ }
19
+ // Any value minus inf is -inf
20
+ else if (!a.isInf() && b.isInf()) {
21
+ retval = Expression_1.Expression.Inf().neg();
22
+ }
23
+ else {
24
+ retval = (0, add_1.add)(a, b.neg());
25
+ }
26
+ if (!retval) {
27
+ throw new Error((0, errors_1.message)('subtractionNotDefined', { leftType: String(a.type), rightType: String(b.type), left: String(a), right: String(b) }));
28
+ }
29
+ }
30
+ return retval;
31
+ }
32
+ function subtractPrefix(a) {
33
+ // Just negates the multiplier
34
+ const x = a.neg();
35
+ return x;
36
+ }
@@ -0,0 +1,7 @@
1
+ type FunctionMetadata = {
2
+ bracketlessStatement?: boolean;
3
+ maxArgs: number;
4
+ };
5
+ type FunctionRegistry = Record<string, FunctionMetadata>;
6
+ export declare function preprocess(input: string, functions: FunctionRegistry): string;
7
+ export {};
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.preprocess = preprocess;
4
+ const errors_1 = require("../../errors");
5
+ const BLOCK_FUNCTION = 'block';
6
+ const LET_FUNCTION = 'let';
7
+ function isIdentifierStart(character) {
8
+ return /[a-z_]/i.test(character);
9
+ }
10
+ function isIdentifierPart(character) {
11
+ return /[a-z0-9_]/i.test(character);
12
+ }
13
+ function getPreviousIdentifier(input, at) {
14
+ let end = at;
15
+ while (end > 0 && /\s/.test(input[end - 1])) {
16
+ end--;
17
+ }
18
+ let start = end;
19
+ while (start > 0 && isIdentifierPart(input[start - 1])) {
20
+ start--;
21
+ }
22
+ const identifier = input.slice(start, end);
23
+ return identifier && isIdentifierStart(identifier[0]) ? identifier : undefined;
24
+ }
25
+ function getNextSignificantCharacter(input, at) {
26
+ let index = at;
27
+ while (index < input.length && /\s/.test(input[index])) {
28
+ index++;
29
+ }
30
+ return input[index];
31
+ }
32
+ function normalizeComments(input) {
33
+ let retval = '';
34
+ let index = 0;
35
+ while (index < input.length) {
36
+ const opening = input.indexOf('#', index);
37
+ if (opening === -1) {
38
+ retval += input.slice(index);
39
+ break;
40
+ }
41
+ retval += input.slice(index, opening);
42
+ const delimiter = input.startsWith('##', opening) ? '##' : '#';
43
+ const closing = input.indexOf(delimiter, opening + delimiter.length);
44
+ if (closing === -1) {
45
+ throw new errors_1.ParserError((0, errors_1.message)('missingCommentDelimiter', { delimiter }));
46
+ }
47
+ retval += ' ';
48
+ index = closing + delimiter.length;
49
+ }
50
+ return retval;
51
+ }
52
+ /**
53
+ * Normalizes semicolon statement syntax onto the parser's existing block sequencing.
54
+ *
55
+ * Root-level statement sequences become an implicit block. Inside an explicit block,
56
+ * semicolons separate block arguments just like commas. A statement sequence in LET's body is
57
+ * wrapped in an implicit block so the sequence remains one LET body argument rather than being
58
+ * mistaken for additional bindings. A trailing semicolon is discarded.
59
+ */
60
+ function normalizeStatementSeparators(input) {
61
+ const scopes = [];
62
+ let retval = '';
63
+ let hasRootSequence = false;
64
+ for (let index = 0; index < input.length; index++) {
65
+ const character = input[index];
66
+ if (character === '(' || character === '[' || character === '{') {
67
+ const closingBracket = character === '(' ? ')' : character === '[' ? ']' : '}';
68
+ retval += character;
69
+ scopes.push({
70
+ argumentStart: retval.length,
71
+ closingBracket,
72
+ functionName: character === '(' ? getPreviousIdentifier(input, index) : undefined,
73
+ });
74
+ continue;
75
+ }
76
+ if (character === ')' || character === ']' || character === '}') {
77
+ const currentScope = scopes[scopes.length - 1];
78
+ if (currentScope?.closingBracket === character) {
79
+ if (currentScope.statementBlockOpened) {
80
+ retval += ')';
81
+ }
82
+ scopes.pop();
83
+ }
84
+ retval += character;
85
+ continue;
86
+ }
87
+ if (character === ',') {
88
+ retval += character;
89
+ const currentScope = scopes[scopes.length - 1];
90
+ if (currentScope && !currentScope.statementBlockOpened) {
91
+ currentScope.argumentStart = retval.length;
92
+ }
93
+ continue;
94
+ }
95
+ if (character === ';') {
96
+ const nextCharacter = getNextSignificantCharacter(input, index + 1);
97
+ const currentScope = scopes[scopes.length - 1];
98
+ const isTrailingTerminator = nextCharacter === undefined ||
99
+ nextCharacter === ',' ||
100
+ nextCharacter === currentScope?.closingBracket;
101
+ if (scopes.length === 0) {
102
+ if (!isTrailingTerminator) {
103
+ retval += ',';
104
+ hasRootSequence = true;
105
+ }
106
+ }
107
+ else if (isTrailingTerminator) {
108
+ continue;
109
+ }
110
+ else if (currentScope?.functionName === BLOCK_FUNCTION) {
111
+ retval += ',';
112
+ }
113
+ else if (currentScope?.functionName === LET_FUNCTION) {
114
+ if (!currentScope.statementBlockOpened) {
115
+ retval =
116
+ retval.slice(0, currentScope.argumentStart) +
117
+ `${BLOCK_FUNCTION}(` +
118
+ retval.slice(currentScope.argumentStart);
119
+ currentScope.statementBlockOpened = true;
120
+ }
121
+ retval += ',';
122
+ }
123
+ else {
124
+ retval += character;
125
+ }
126
+ continue;
127
+ }
128
+ retval += character;
129
+ }
130
+ if (hasRootSequence) {
131
+ retval = `${BLOCK_FUNCTION}(${retval})`;
132
+ }
133
+ return retval;
134
+ }
135
+ function findBracketlessFunction(input, functions) {
136
+ let retval;
137
+ let index = 0;
138
+ while (index < input.length) {
139
+ if (!isIdentifierStart(input[index])) {
140
+ index++;
141
+ continue;
142
+ }
143
+ const nameStart = index;
144
+ index++;
145
+ while (index < input.length && isIdentifierPart(input[index])) {
146
+ index++;
147
+ }
148
+ const nameEnd = index;
149
+ const name = input.slice(nameStart, nameEnd);
150
+ if (!(name in functions) || !/\s/.test(input[index] ?? '')) {
151
+ continue;
152
+ }
153
+ while (index < input.length && /\s/.test(input[index])) {
154
+ index++;
155
+ }
156
+ if (index < input.length) {
157
+ const firstArgumentCharacter = input[index];
158
+ const nextCharacter = input[index + 1] ?? '';
159
+ const startsWithOperatorBoundary = /[*/=<>:&|]/.test(firstArgumentCharacter) ||
160
+ ((firstArgumentCharacter === '+' || firstArgumentCharacter === '-') && /\s/.test(nextCharacter));
161
+ if (!startsWithOperatorBoundary) {
162
+ retval = {
163
+ argumentStart: index,
164
+ consumeStatement: functions[name].bracketlessStatement === true,
165
+ maxArgs: functions[name].maxArgs,
166
+ nameEnd,
167
+ nameStart,
168
+ };
169
+ }
170
+ }
171
+ }
172
+ return retval;
173
+ }
174
+ function isOpeningBracket(character) {
175
+ return character === '(' || character === '[' || character === '{';
176
+ }
177
+ function isClosingBracket(character) {
178
+ return character === ')' || character === ']' || character === '}';
179
+ }
180
+ function findArgumentEnd(input, start, maxArgs, consumeStatement = false) {
181
+ let depth = 0;
182
+ let index = start;
183
+ let previousSignificant = '';
184
+ const multipleArguments = maxArgs !== 1;
185
+ for (; index < input.length; index++) {
186
+ const character = input[index];
187
+ if (isOpeningBracket(character)) {
188
+ depth++;
189
+ previousSignificant = character;
190
+ continue;
191
+ }
192
+ if (isClosingBracket(character)) {
193
+ if (depth === 0)
194
+ break;
195
+ depth--;
196
+ previousSignificant = character;
197
+ continue;
198
+ }
199
+ if (depth > 0) {
200
+ if (!/\s/.test(character))
201
+ previousSignificant = character;
202
+ continue;
203
+ }
204
+ if (consumeStatement) {
205
+ if (character === ',')
206
+ break;
207
+ if (!/\s/.test(character))
208
+ previousSignificant = character;
209
+ continue;
210
+ }
211
+ if (/\s/.test(character)) {
212
+ if (multipleArguments && previousSignificant === ',')
213
+ continue;
214
+ break;
215
+ }
216
+ if (character === ',') {
217
+ if (!multipleArguments)
218
+ break;
219
+ previousSignificant = character;
220
+ continue;
221
+ }
222
+ const isPrefixSign = (character === '+' || character === '-') &&
223
+ (index === start || previousSignificant === ',' || previousSignificant === '^');
224
+ const isBinaryBoundary = /[+\-*/=<>:&|]/.test(character) && !isPrefixSign;
225
+ if (isBinaryBoundary)
226
+ break;
227
+ previousSignificant = character;
228
+ }
229
+ return index;
230
+ }
231
+ function preprocess(input, functions) {
232
+ let retval = normalizeComments(input);
233
+ retval = normalizeStatementSeparators(retval);
234
+ let bracketless = findBracketlessFunction(retval, functions);
235
+ while (bracketless) {
236
+ const argumentEnd = findArgumentEnd(retval, bracketless.argumentStart, bracketless.maxArgs, bracketless.consumeStatement);
237
+ const name = retval.slice(bracketless.nameStart, bracketless.nameEnd);
238
+ const argument = retval.slice(bracketless.argumentStart, argumentEnd);
239
+ retval =
240
+ retval.slice(0, bracketless.nameStart) +
241
+ `${name}(${argument})` +
242
+ retval.slice(argumentEnd);
243
+ bracketless = findBracketlessFunction(retval, functions);
244
+ }
245
+ return retval;
246
+ }
@@ -0,0 +1,23 @@
1
+ import { Expression } from '../../expression/Expression';
2
+ import type { ParserEntity } from '../../../types';
3
+ import type { DeferredFunctionArgument } from '../types';
4
+ export { BREAK_SIGNAL, CONTINUE_SIGNAL, NULL_SIGNAL, RETURN_SIGNAL, BreakSignal, ContinueSignal, ControlFlowSignal, NullSignal, ReturnSignal, } from '../controlFlowSignals';
5
+ export declare function isInsideSymbolicFunction(): boolean;
6
+ export declare function shouldConsumeLocalReturn(): boolean;
7
+ export declare function withReturnPropagation(evaluate: () => ParserEntity): ParserEntity;
8
+ export declare function functionBoundary(evaluate: () => ParserEntity): ParserEntity;
9
+ export declare function RETURN(x: ParserEntity): never;
10
+ export declare function BREAK(): never;
11
+ export declare function CONTINUE(): never;
12
+ export declare function AND(...args: DeferredFunctionArgument[]): Expression;
13
+ export declare function OR(...args: DeferredFunctionArgument[]): Expression;
14
+ export declare function NOT(value: ParserEntity): Expression;
15
+ export declare function XOR(...args: ParserEntity[]): Expression;
16
+ export declare function IFERROR(expression: DeferredFunctionArgument, fallback: DeferredFunctionArgument): ParserEntity;
17
+ export declare function ISERROR(expression: DeferredFunctionArgument): Expression;
18
+ export declare function IF(condition: DeferredFunctionArgument, branch1: DeferredFunctionArgument, branch2?: DeferredFunctionArgument): ParserEntity;
19
+ export declare function WHILE(condition: DeferredFunctionArgument, body: DeferredFunctionArgument): ParserEntity;
20
+ export declare function FOR(initializer: DeferredFunctionArgument, condition: DeferredFunctionArgument, update: DeferredFunctionArgument, body: DeferredFunctionArgument): ParserEntity;
21
+ export declare function BLOCK(...args: DeferredFunctionArgument[]): ParserEntity;
22
+ export declare function parserReturnBoundary(evaluate: () => ParserEntity): ParserEntity;
23
+ export declare function parserBlock(...args: DeferredFunctionArgument[]): ParserEntity;
@@ -0,0 +1,279 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ReturnSignal = exports.NullSignal = exports.ControlFlowSignal = exports.ContinueSignal = exports.BreakSignal = exports.RETURN_SIGNAL = exports.NULL_SIGNAL = exports.CONTINUE_SIGNAL = exports.BREAK_SIGNAL = void 0;
4
+ exports.isInsideSymbolicFunction = isInsideSymbolicFunction;
5
+ exports.shouldConsumeLocalReturn = shouldConsumeLocalReturn;
6
+ exports.withReturnPropagation = withReturnPropagation;
7
+ exports.functionBoundary = functionBoundary;
8
+ exports.RETURN = RETURN;
9
+ exports.BREAK = BREAK;
10
+ exports.CONTINUE = CONTINUE;
11
+ exports.AND = AND;
12
+ exports.OR = OR;
13
+ exports.NOT = NOT;
14
+ exports.XOR = XOR;
15
+ exports.IFERROR = IFERROR;
16
+ exports.ISERROR = ISERROR;
17
+ exports.IF = IF;
18
+ exports.WHILE = WHILE;
19
+ exports.FOR = FOR;
20
+ exports.BLOCK = BLOCK;
21
+ exports.parserReturnBoundary = parserReturnBoundary;
22
+ exports.parserBlock = parserBlock;
23
+ const errors_1 = require("../../../errors");
24
+ const Settings_1 = require("../../../Settings");
25
+ const Expression_1 = require("../../expression/Expression");
26
+ const shortcuts_1 = require("../../expression/shortcuts");
27
+ const constants_1 = require("../constants");
28
+ const controlFlowSignals_1 = require("../controlFlowSignals");
29
+ var controlFlowSignals_2 = require("../controlFlowSignals");
30
+ Object.defineProperty(exports, "BREAK_SIGNAL", { enumerable: true, get: function () { return controlFlowSignals_2.BREAK_SIGNAL; } });
31
+ Object.defineProperty(exports, "CONTINUE_SIGNAL", { enumerable: true, get: function () { return controlFlowSignals_2.CONTINUE_SIGNAL; } });
32
+ Object.defineProperty(exports, "NULL_SIGNAL", { enumerable: true, get: function () { return controlFlowSignals_2.NULL_SIGNAL; } });
33
+ Object.defineProperty(exports, "RETURN_SIGNAL", { enumerable: true, get: function () { return controlFlowSignals_2.RETURN_SIGNAL; } });
34
+ Object.defineProperty(exports, "BreakSignal", { enumerable: true, get: function () { return controlFlowSignals_2.BreakSignal; } });
35
+ Object.defineProperty(exports, "ContinueSignal", { enumerable: true, get: function () { return controlFlowSignals_2.ContinueSignal; } });
36
+ Object.defineProperty(exports, "ControlFlowSignal", { enumerable: true, get: function () { return controlFlowSignals_2.ControlFlowSignal; } });
37
+ Object.defineProperty(exports, "NullSignal", { enumerable: true, get: function () { return controlFlowSignals_2.NullSignal; } });
38
+ Object.defineProperty(exports, "ReturnSignal", { enumerable: true, get: function () { return controlFlowSignals_2.ReturnSignal; } });
39
+ const BREAK_SIGNAL_INSTANCE = new controlFlowSignals_1.BreakSignal();
40
+ const CONTINUE_SIGNAL_INSTANCE = new controlFlowSignals_1.ContinueSignal();
41
+ let loopBodyDepth = 0;
42
+ let parserReturnBoundaryDepth = 0;
43
+ let returnPropagationDepth = 0;
44
+ let symbolicFunctionDepth = 0;
45
+ function throwNullSignal() {
46
+ throw new controlFlowSignals_1.NullSignal();
47
+ }
48
+ function isInsideSymbolicFunction() {
49
+ return symbolicFunctionDepth > 0;
50
+ }
51
+ function shouldConsumeLocalReturn() {
52
+ return symbolicFunctionDepth === 0 && returnPropagationDepth === 0;
53
+ }
54
+ function withReturnPropagation(evaluate) {
55
+ returnPropagationDepth++;
56
+ try {
57
+ return evaluate();
58
+ }
59
+ finally {
60
+ returnPropagationDepth--;
61
+ }
62
+ }
63
+ function isTruthy(value) {
64
+ if (!Expression_1.Expression.isExpression(value)) {
65
+ throw new errors_1.UnexpectedDataType((0, errors_1.message)('expressionExpected', { type: constants_1.dataTypes[value.dataType] }));
66
+ }
67
+ return !value.isZero();
68
+ }
69
+ function functionBoundary(evaluate) {
70
+ let retval;
71
+ symbolicFunctionDepth++;
72
+ try {
73
+ retval = evaluate();
74
+ }
75
+ catch (error) {
76
+ if (controlFlowSignals_1.ReturnSignal.isReturnSignal(error))
77
+ retval = error.value;
78
+ else if (controlFlowSignals_1.BreakSignal.isBreakSignal(error))
79
+ throw new errors_1.ParserError((0, errors_1.message)('breakOutsideLoop'));
80
+ else if (controlFlowSignals_1.ContinueSignal.isContinueSignal(error))
81
+ throw new errors_1.ParserError((0, errors_1.message)('continueOutsideLoop'));
82
+ else
83
+ throw error;
84
+ }
85
+ finally {
86
+ symbolicFunctionDepth--;
87
+ }
88
+ return retval;
89
+ }
90
+ function RETURN(x) {
91
+ throw new controlFlowSignals_1.ReturnSignal(x);
92
+ }
93
+ function BREAK() {
94
+ if (loopBodyDepth === 0)
95
+ throw new errors_1.ParserError((0, errors_1.message)('breakOutsideLoop'));
96
+ throw BREAK_SIGNAL_INSTANCE;
97
+ }
98
+ function CONTINUE() {
99
+ if (loopBodyDepth === 0)
100
+ throw new errors_1.ParserError((0, errors_1.message)('continueOutsideLoop'));
101
+ throw CONTINUE_SIGNAL_INSTANCE;
102
+ }
103
+ function AND(...args) {
104
+ let retval = (0, shortcuts_1.one)();
105
+ for (const arg of args) {
106
+ if (!isTruthy(arg())) {
107
+ retval = (0, shortcuts_1.zero)();
108
+ break;
109
+ }
110
+ }
111
+ return retval;
112
+ }
113
+ function OR(...args) {
114
+ let retval = (0, shortcuts_1.zero)();
115
+ for (const arg of args) {
116
+ if (isTruthy(arg())) {
117
+ retval = (0, shortcuts_1.one)();
118
+ break;
119
+ }
120
+ }
121
+ return retval;
122
+ }
123
+ function NOT(value) {
124
+ return isTruthy(value) ? (0, shortcuts_1.zero)() : (0, shortcuts_1.one)();
125
+ }
126
+ function XOR(...args) {
127
+ let odd = false;
128
+ for (const arg of args)
129
+ if (isTruthy(arg))
130
+ odd = !odd;
131
+ return odd ? (0, shortcuts_1.one)() : (0, shortcuts_1.zero)();
132
+ }
133
+ function IFERROR(expression, fallback) {
134
+ let retval;
135
+ try {
136
+ retval = expression();
137
+ }
138
+ catch (error) {
139
+ if (error instanceof controlFlowSignals_1.ControlFlowSignal)
140
+ throw error;
141
+ retval = fallback();
142
+ }
143
+ return retval;
144
+ }
145
+ function ISERROR(expression) {
146
+ let retval = (0, shortcuts_1.zero)();
147
+ try {
148
+ expression();
149
+ }
150
+ catch (error) {
151
+ if (error instanceof controlFlowSignals_1.ControlFlowSignal)
152
+ throw error;
153
+ retval = (0, shortcuts_1.one)();
154
+ }
155
+ return retval;
156
+ }
157
+ function controlFlowReturnBoundary(evaluate) {
158
+ let retval;
159
+ try {
160
+ retval = evaluate();
161
+ }
162
+ catch (error) {
163
+ if (parserReturnBoundaryDepth > 0 &&
164
+ symbolicFunctionDepth === 0 &&
165
+ controlFlowSignals_1.ReturnSignal.isReturnSignal(error))
166
+ retval = error.value;
167
+ else
168
+ throw error;
169
+ }
170
+ return retval;
171
+ }
172
+ function IF(condition, branch1, branch2) {
173
+ return controlFlowReturnBoundary(() => {
174
+ const evaluatedCondition = condition();
175
+ let retval;
176
+ if (isTruthy(evaluatedCondition))
177
+ retval = branch1();
178
+ else if (branch2)
179
+ retval = branch2();
180
+ else
181
+ return throwNullSignal();
182
+ return retval;
183
+ });
184
+ }
185
+ function WHILE(condition, body) {
186
+ return controlFlowReturnBoundary(() => {
187
+ let retval;
188
+ let continueLoop = true;
189
+ let iterations = 0;
190
+ while (continueLoop) {
191
+ const evaluatedCondition = condition();
192
+ if (!isTruthy(evaluatedCondition))
193
+ continueLoop = false;
194
+ else {
195
+ if (iterations >= Settings_1.Settings.MAX_LOOP_ITERATIONS) {
196
+ throw new errors_1.ParserError((0, errors_1.message)('loopIterationLimitExceeded', { max: String(Settings_1.Settings.MAX_LOOP_ITERATIONS) }));
197
+ }
198
+ loopBodyDepth++;
199
+ try {
200
+ retval = body();
201
+ }
202
+ catch (error) {
203
+ if (controlFlowSignals_1.NullSignal.isNullSignal(error)) {
204
+ // A loop body may legitimately complete without producing a value.
205
+ }
206
+ else if (controlFlowSignals_1.BreakSignal.isBreakSignal(error))
207
+ continueLoop = false;
208
+ else if (!controlFlowSignals_1.ContinueSignal.isContinueSignal(error))
209
+ throw error;
210
+ }
211
+ finally {
212
+ loopBodyDepth--;
213
+ }
214
+ iterations++;
215
+ }
216
+ }
217
+ if (retval === undefined) {
218
+ return throwNullSignal();
219
+ }
220
+ return retval;
221
+ });
222
+ }
223
+ function FOR(initializer, condition, update, body) {
224
+ return controlFlowReturnBoundary(() => {
225
+ initializer();
226
+ return WHILE(condition, () => {
227
+ let bodyResult;
228
+ try {
229
+ bodyResult = body();
230
+ }
231
+ catch (error) {
232
+ if (controlFlowSignals_1.ContinueSignal.isContinueSignal(error) ||
233
+ controlFlowSignals_1.NullSignal.isNullSignal(error))
234
+ update();
235
+ throw error;
236
+ }
237
+ update();
238
+ return bodyResult;
239
+ });
240
+ });
241
+ }
242
+ function BLOCK(...args) {
243
+ if (args.length === 0)
244
+ return throwNullSignal();
245
+ let retval;
246
+ for (const arg of args) {
247
+ try {
248
+ retval = arg();
249
+ }
250
+ catch (error) {
251
+ if (!controlFlowSignals_1.NullSignal.isNullSignal(error))
252
+ throw error;
253
+ }
254
+ }
255
+ if (retval === undefined)
256
+ return throwNullSignal();
257
+ return retval;
258
+ }
259
+ function parserReturnBoundary(evaluate) {
260
+ const consumesReturn = symbolicFunctionDepth === 0 && parserReturnBoundaryDepth === 0;
261
+ let retval;
262
+ parserReturnBoundaryDepth++;
263
+ try {
264
+ retval = evaluate();
265
+ }
266
+ catch (error) {
267
+ if (consumesReturn && controlFlowSignals_1.ReturnSignal.isReturnSignal(error))
268
+ retval = error.value;
269
+ else
270
+ throw error;
271
+ }
272
+ finally {
273
+ parserReturnBoundaryDepth--;
274
+ }
275
+ return retval;
276
+ }
277
+ function parserBlock(...args) {
278
+ return parserReturnBoundary(() => BLOCK(...args));
279
+ }
@@ -0,0 +1,4 @@
1
+ import type { DeferredFunctionArgument } from '../types';
2
+ import type { ParserEntity } from '../../../types';
3
+ /** Iterates parser containers while keeping iteration variables local to each body call. */
4
+ export declare function each(collection: DeferredFunctionArgument, variable: DeferredFunctionArgument, bodyOrValueVariable: DeferredFunctionArgument, dictionaryBody?: DeferredFunctionArgument): ParserEntity;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.each = each;
4
+ const Collection_1 = require("../../collection/Collection");
5
+ const Dictionary_1 = require("../../dictionary/Dictionary");
6
+ const Expression_1 = require("../../expression/Expression");
7
+ const shortcuts_1 = require("../../expression/shortcuts");
8
+ const Matrix_1 = require("../../matrix/Matrix");
9
+ const ValuesSet_1 = require("../../valuesSet/ValuesSet");
10
+ const Vector_1 = require("../../vector/Vector");
11
+ const errors_1 = require("../../../errors");
12
+ const constants_1 = require("../constants");
13
+ const controlFlow_1 = require("./controlFlow");
14
+ const scope_1 = require("./scope");
15
+ /** Iterates parser containers while keeping iteration variables local to each body call. */
16
+ function each(collection, variable, bodyOrValueVariable, dictionaryBody) {
17
+ const target = collection();
18
+ const values = [];
19
+ const keys = [];
20
+ if (dictionaryBody) {
21
+ if (!Dictionary_1.Dictionary.isDictionary(target)) {
22
+ throw new errors_1.UnexpectedDataType((0, errors_1.message)('unsupportedType', { type: constants_1.dataTypes[target.dataType] }));
23
+ }
24
+ for (const [key, value] of target.entries()) {
25
+ keys.push(Expression_1.Expression.create(key));
26
+ values.push(value.copy());
27
+ }
28
+ }
29
+ else if (Vector_1.Vector.isVector(target) ||
30
+ Collection_1.Collection.isCollection(target) ||
31
+ ValuesSet_1.ValuesSet.isValuesSet(target)) {
32
+ target.forEach(value => values.push(value.copy()));
33
+ }
34
+ else if (Matrix_1.Matrix.isMatrix(target)) {
35
+ target.forEach(value => values.push(value.copy()));
36
+ }
37
+ else if (Dictionary_1.Dictionary.isDictionary(target)) {
38
+ target.forEach(value => values.push(value.copy()));
39
+ }
40
+ else {
41
+ throw new errors_1.UnexpectedDataType((0, errors_1.message)('unsupportedType', { type: constants_1.dataTypes[target.dataType] }));
42
+ }
43
+ let index = 0;
44
+ let retval;
45
+ try {
46
+ retval = (0, controlFlow_1.withReturnPropagation)(() => (0, controlFlow_1.FOR)(() => (0, shortcuts_1.zero)(), () => (index < values.length ? (0, shortcuts_1.one)() : (0, shortcuts_1.zero)()), () => {
47
+ index++;
48
+ return (0, shortcuts_1.zero)();
49
+ }, () => {
50
+ if (dictionaryBody) {
51
+ return (0, scope_1.LET)(variable, () => keys[index], () => (0, scope_1.LET)(bodyOrValueVariable, () => values[index], dictionaryBody));
52
+ }
53
+ return (0, scope_1.LET)(variable, () => values[index], bodyOrValueVariable);
54
+ }));
55
+ }
56
+ catch (error) {
57
+ if (!(0, controlFlow_1.isInsideSymbolicFunction)() && controlFlow_1.ReturnSignal.isReturnSignal(error)) {
58
+ retval = error.value;
59
+ }
60
+ else {
61
+ throw error;
62
+ }
63
+ }
64
+ return retval;
65
+ }
@@ -0,0 +1 @@
1
+ export declare function loadScriptingFunctions(): void;