solve-engine 1.0.0-beta.6 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/README.md +10 -3
  2. package/dist/{BytecodeBuilder-3egMyuDi.d.cts → BytecodeBuilder-B0xskcv5.d.cts} +2 -1
  3. package/dist/{BytecodeBuilder-3egMyuDi.d.ts → BytecodeBuilder-B0xskcv5.d.ts} +2 -1
  4. package/dist/{Configuration-fVpd-HC-.d.cts → Configuration-B-G5gTRn.d.cts} +107 -29
  5. package/dist/{Configuration-fVpd-HC-.d.ts → Configuration-B-G5gTRn.d.ts} +107 -29
  6. package/dist/{EngineError-DvPSnhZi.d.cts → EngineError-LU7W7AgI.d.cts} +96 -16
  7. package/dist/{EngineError-DvPSnhZi.d.ts → EngineError-LU7W7AgI.d.ts} +96 -16
  8. package/dist/{Lexer-W9MBOP0V.d.ts → Lexer-BN5mt30n.d.ts} +16 -0
  9. package/dist/{Lexer-Cfm79Dak.d.cts → Lexer-D78E2yDW.d.cts} +16 -0
  10. package/dist/{PackageRegistry-CjDt-Jy_.d.ts → PackageRegistry-DFeINv2O.d.ts} +54 -13
  11. package/dist/{PackageRegistry-pHtKythi.d.cts → PackageRegistry-u2zdfFaj.d.cts} +54 -13
  12. package/dist/{Parselet-DEdF9I7n.d.ts → Parselet-BaySkMV3.d.ts} +37 -5
  13. package/dist/{Parselet-Cu0bLSis.d.cts → Parselet-DuI1Pjiq.d.cts} +37 -5
  14. package/dist/{ScopeManager-CKfQtl7l.d.cts → ScopeManager-B6GzdhVG.d.cts} +75 -6
  15. package/dist/{ScopeManager-B5k0nk05.d.ts → ScopeManager-udv4Twwq.d.ts} +75 -6
  16. package/dist/{VMCheckpoints-BmDwIXgK.d.ts → VMCheckpoints-BiaIlOOY.d.ts} +4 -4
  17. package/dist/{VMCheckpoints-CqFuLwrT.d.cts → VMCheckpoints-DwLjivM7.d.cts} +4 -4
  18. package/dist/{Value-KtAQNHur.d.cts → Value-CXJqDH9J.d.cts} +5 -2
  19. package/dist/{Value-KtAQNHur.d.ts → Value-CXJqDH9J.d.ts} +5 -2
  20. package/dist/{chunk-CSG5XVNJ.cjs → chunk-3AFRJYP4.cjs} +556 -414
  21. package/dist/chunk-3AFRJYP4.cjs.map +1 -0
  22. package/dist/chunk-3BOK2LDK.js +17 -0
  23. package/dist/chunk-3BOK2LDK.js.map +1 -0
  24. package/dist/{chunk-6RDSQURE.js → chunk-3D7V24DG.js} +57 -6
  25. package/dist/chunk-3D7V24DG.js.map +1 -0
  26. package/dist/{chunk-MEOHSQEH.js → chunk-3LAEG75D.js} +47 -15
  27. package/dist/chunk-3LAEG75D.js.map +1 -0
  28. package/dist/{chunk-NUR3K7EW.js → chunk-3VNGREMU.js} +118 -41
  29. package/dist/chunk-3VNGREMU.js.map +1 -0
  30. package/dist/{chunk-4AVD7NZW.cjs → chunk-4B2CNWQU.cjs} +13 -7
  31. package/dist/chunk-4B2CNWQU.cjs.map +1 -0
  32. package/dist/{chunk-6GCKCWLB.js → chunk-526PMQOA.js} +126 -69
  33. package/dist/chunk-526PMQOA.js.map +1 -0
  34. package/dist/{chunk-2CS6OMZK.js → chunk-5F4C26RU.js} +8 -5
  35. package/dist/chunk-5F4C26RU.js.map +1 -0
  36. package/dist/{chunk-M4N5GA5Z.cjs → chunk-5KMIY374.cjs} +57 -6
  37. package/dist/chunk-5KMIY374.cjs.map +1 -0
  38. package/dist/{chunk-R24DI24X.cjs → chunk-5LI5EPGJ.cjs} +6 -5
  39. package/dist/chunk-5LI5EPGJ.cjs.map +1 -0
  40. package/dist/{chunk-BAMZT3GL.js → chunk-5WVP4YHP.js} +939 -134
  41. package/dist/chunk-5WVP4YHP.js.map +1 -0
  42. package/dist/{chunk-MZOVP3WI.cjs → chunk-6KFYJ6TD.cjs} +3 -2
  43. package/dist/chunk-6KFYJ6TD.cjs.map +1 -0
  44. package/dist/{chunk-BXKJLM5R.cjs → chunk-6WFMPTGB.cjs} +972 -636
  45. package/dist/chunk-6WFMPTGB.cjs.map +1 -0
  46. package/dist/{chunk-2MV4HBKC.cjs → chunk-A2N2GFCG.cjs} +10 -10
  47. package/dist/{chunk-2MV4HBKC.cjs.map → chunk-A2N2GFCG.cjs.map} +1 -1
  48. package/dist/chunk-ADBA3XBE.cjs +20 -0
  49. package/dist/chunk-ADBA3XBE.cjs.map +1 -0
  50. package/dist/{chunk-MBNQVDVC.cjs → chunk-AMOJYLG2.cjs} +16 -10
  51. package/dist/chunk-AMOJYLG2.cjs.map +1 -0
  52. package/dist/{chunk-CLVQBF5C.cjs → chunk-AQNHHJMJ.cjs} +5 -5
  53. package/dist/{chunk-CLVQBF5C.cjs.map → chunk-AQNHHJMJ.cjs.map} +1 -1
  54. package/dist/{chunk-AHCLWAM5.cjs → chunk-BHTNFEGZ.cjs} +13 -13
  55. package/dist/chunk-BHTNFEGZ.cjs.map +1 -0
  56. package/dist/{chunk-62W2DYYA.cjs → chunk-E4NUZXVK.cjs} +58 -27
  57. package/dist/chunk-E4NUZXVK.cjs.map +1 -0
  58. package/dist/{chunk-LVLUHTRD.js → chunk-GLG5ZMX7.js} +54 -23
  59. package/dist/chunk-GLG5ZMX7.js.map +1 -0
  60. package/dist/{chunk-BVAR5J2F.js → chunk-GQCOSXMG.js} +117 -6
  61. package/dist/chunk-GQCOSXMG.js.map +1 -0
  62. package/dist/{chunk-QDMPOAI7.cjs → chunk-HDP7VK3C.cjs} +1118 -313
  63. package/dist/chunk-HDP7VK3C.cjs.map +1 -0
  64. package/dist/{chunk-GVWHCL2N.js → chunk-HMOISHXR.js} +217 -75
  65. package/dist/chunk-HMOISHXR.js.map +1 -0
  66. package/dist/{chunk-MTX2KVU7.cjs → chunk-HVQFNJKE.cjs} +122 -90
  67. package/dist/chunk-HVQFNJKE.cjs.map +1 -0
  68. package/dist/{chunk-OC6LTXYS.cjs → chunk-JMXUNXQS.cjs} +126 -7
  69. package/dist/chunk-JMXUNXQS.cjs.map +1 -0
  70. package/dist/{chunk-WWOLFXTX.cjs → chunk-KBSXGXPM.cjs} +10 -7
  71. package/dist/chunk-KBSXGXPM.cjs.map +1 -0
  72. package/dist/{chunk-YU2CUNFO.js → chunk-KV7UW6T6.js} +11 -5
  73. package/dist/chunk-KV7UW6T6.js.map +1 -0
  74. package/dist/{chunk-CCJPSHGI.cjs → chunk-N7FNVFXW.cjs} +4 -12
  75. package/dist/chunk-N7FNVFXW.cjs.map +1 -0
  76. package/dist/{chunk-CYFK5SY2.js → chunk-O3ANBHSA.js} +169 -39
  77. package/dist/chunk-O3ANBHSA.js.map +1 -0
  78. package/dist/{chunk-NZFKROS7.cjs → chunk-PA4VC73I.cjs} +130 -72
  79. package/dist/chunk-PA4VC73I.cjs.map +1 -0
  80. package/dist/{chunk-NJTXJ5AG.cjs → chunk-PFUESQTW.cjs} +18 -18
  81. package/dist/{chunk-NJTXJ5AG.cjs.map → chunk-PFUESQTW.cjs.map} +1 -1
  82. package/dist/{chunk-SFQWJMKT.js → chunk-QY25VWBF.js} +51 -12
  83. package/dist/chunk-QY25VWBF.js.map +1 -0
  84. package/dist/{chunk-WC5FFSHB.js → chunk-R3PY4G7J.js} +3 -3
  85. package/dist/{chunk-WC5FFSHB.js.map → chunk-R3PY4G7J.js.map} +1 -1
  86. package/dist/{chunk-M5E34VG5.js → chunk-SBUFNJVE.js} +3 -3
  87. package/dist/{chunk-M5E34VG5.js.map → chunk-SBUFNJVE.js.map} +1 -1
  88. package/dist/{chunk-UKPGSAZW.js → chunk-TMA4RCEN.js} +3 -3
  89. package/dist/{chunk-UKPGSAZW.js.map → chunk-TMA4RCEN.js.map} +1 -1
  90. package/dist/{chunk-FN2WMF2W.cjs → chunk-U5VAY32K.cjs} +215 -138
  91. package/dist/chunk-U5VAY32K.cjs.map +1 -0
  92. package/dist/{chunk-DUEZFTK2.js → chunk-UKQHXPGW.js} +4 -12
  93. package/dist/chunk-UKQHXPGW.js.map +1 -0
  94. package/dist/{chunk-4CVLFLOB.cjs → chunk-UM6BVY2S.cjs} +201 -69
  95. package/dist/chunk-UM6BVY2S.cjs.map +1 -0
  96. package/dist/{chunk-75JP4BZX.js → chunk-UQ3UIZJC.js} +3 -2
  97. package/dist/chunk-UQ3UIZJC.js.map +1 -0
  98. package/dist/{chunk-PCPX42KL.js → chunk-V4XG5QF6.js} +16 -10
  99. package/dist/chunk-V4XG5QF6.js.map +1 -0
  100. package/dist/{chunk-GPPLSM2Z.js → chunk-VB37OC6I.js} +6 -5
  101. package/dist/chunk-VB37OC6I.js.map +1 -0
  102. package/dist/{chunk-MVBEL57Q.js → chunk-Y7FT4IQT.js} +500 -170
  103. package/dist/chunk-Y7FT4IQT.js.map +1 -0
  104. package/dist/{chunk-OFXOTECC.js → chunk-YPPPYLSR.js} +7 -7
  105. package/dist/chunk-YPPPYLSR.js.map +1 -0
  106. package/dist/{chunk-M4F66R4O.cjs → chunk-YWQ6V4ZN.cjs} +121 -82
  107. package/dist/chunk-YWQ6V4ZN.cjs.map +1 -0
  108. package/dist/constants.cjs +5 -5
  109. package/dist/constants.d.cts +1 -1
  110. package/dist/constants.d.ts +1 -1
  111. package/dist/constants.js +2 -2
  112. package/dist/engine.cjs +31 -31
  113. package/dist/engine.d.cts +11 -11
  114. package/dist/engine.d.ts +11 -11
  115. package/dist/engine.js +21 -21
  116. package/dist/errors.cjs +19 -19
  117. package/dist/errors.d.cts +2 -2
  118. package/dist/errors.d.ts +2 -2
  119. package/dist/errors.js +1 -1
  120. package/dist/format.cjs +29 -22
  121. package/dist/format.cjs.map +1 -1
  122. package/dist/format.d.cts +1 -2
  123. package/dist/format.d.ts +1 -2
  124. package/dist/format.js +23 -16
  125. package/dist/format.js.map +1 -1
  126. package/dist/index.cjs +31 -31
  127. package/dist/index.d.cts +10 -10
  128. package/dist/index.d.ts +10 -10
  129. package/dist/index.js +22 -22
  130. package/dist/language.cjs +8 -8
  131. package/dist/language.cjs.map +1 -1
  132. package/dist/language.d.cts +10 -10
  133. package/dist/language.d.ts +10 -10
  134. package/dist/language.js +6 -6
  135. package/dist/language.js.map +1 -1
  136. package/dist/lexer.cjs +18 -18
  137. package/dist/lexer.d.cts +2 -2
  138. package/dist/lexer.d.ts +2 -2
  139. package/dist/lexer.js +6 -6
  140. package/dist/normalizer.cjs +12 -12
  141. package/dist/normalizer.js +6 -6
  142. package/dist/packages.cjs +39 -39
  143. package/dist/packages.d.cts +9 -9
  144. package/dist/packages.d.ts +9 -9
  145. package/dist/packages.js +16 -16
  146. package/dist/parser.cjs +15 -15
  147. package/dist/parser.d.cts +23 -9
  148. package/dist/parser.d.ts +23 -9
  149. package/dist/parser.js +5 -5
  150. package/dist/{pipeline-CrsRPmsv.d.ts → pipeline-B6k5lCB7.d.ts} +1 -1
  151. package/dist/{pipeline-DPUQt7yL.d.cts → pipeline-BEb3hujr.d.cts} +1 -1
  152. package/dist/resolvers.d.cts +2 -2
  153. package/dist/resolvers.d.ts +2 -2
  154. package/dist/uom.cjs +17 -17
  155. package/dist/uom.d.cts +2 -2
  156. package/dist/uom.d.ts +2 -2
  157. package/dist/uom.js +7 -7
  158. package/dist/utilities.cjs +8 -4
  159. package/dist/utilities.d.cts +19 -3
  160. package/dist/utilities.d.ts +19 -3
  161. package/dist/utilities.js +2 -2
  162. package/dist/vm.cjs +43 -31
  163. package/dist/vm.d.cts +105 -9
  164. package/dist/vm.d.ts +105 -9
  165. package/dist/vm.js +9 -9
  166. package/package.json +3 -3
  167. package/dist/chunk-2CS6OMZK.js.map +0 -1
  168. package/dist/chunk-4AVD7NZW.cjs.map +0 -1
  169. package/dist/chunk-4CVLFLOB.cjs.map +0 -1
  170. package/dist/chunk-62W2DYYA.cjs.map +0 -1
  171. package/dist/chunk-6GCKCWLB.js.map +0 -1
  172. package/dist/chunk-6RDSQURE.js.map +0 -1
  173. package/dist/chunk-75JP4BZX.js.map +0 -1
  174. package/dist/chunk-AHCLWAM5.cjs.map +0 -1
  175. package/dist/chunk-BAMZT3GL.js.map +0 -1
  176. package/dist/chunk-BVAR5J2F.js.map +0 -1
  177. package/dist/chunk-BXKJLM5R.cjs.map +0 -1
  178. package/dist/chunk-CCJPSHGI.cjs.map +0 -1
  179. package/dist/chunk-CSG5XVNJ.cjs.map +0 -1
  180. package/dist/chunk-CYFK5SY2.js.map +0 -1
  181. package/dist/chunk-DUEZFTK2.js.map +0 -1
  182. package/dist/chunk-FN2WMF2W.cjs.map +0 -1
  183. package/dist/chunk-GPPLSM2Z.js.map +0 -1
  184. package/dist/chunk-GVWHCL2N.js.map +0 -1
  185. package/dist/chunk-LVLUHTRD.js.map +0 -1
  186. package/dist/chunk-M4F66R4O.cjs.map +0 -1
  187. package/dist/chunk-M4N5GA5Z.cjs.map +0 -1
  188. package/dist/chunk-MBNQVDVC.cjs.map +0 -1
  189. package/dist/chunk-MEOHSQEH.js.map +0 -1
  190. package/dist/chunk-MTX2KVU7.cjs.map +0 -1
  191. package/dist/chunk-MVBEL57Q.js.map +0 -1
  192. package/dist/chunk-MZOVP3WI.cjs.map +0 -1
  193. package/dist/chunk-N5YFR4UP.cjs +0 -10
  194. package/dist/chunk-N5YFR4UP.cjs.map +0 -1
  195. package/dist/chunk-NUR3K7EW.js.map +0 -1
  196. package/dist/chunk-NZFKROS7.cjs.map +0 -1
  197. package/dist/chunk-OC6LTXYS.cjs.map +0 -1
  198. package/dist/chunk-OFXOTECC.js.map +0 -1
  199. package/dist/chunk-PCPX42KL.js.map +0 -1
  200. package/dist/chunk-PFSDGGYL.js +0 -8
  201. package/dist/chunk-PFSDGGYL.js.map +0 -1
  202. package/dist/chunk-QDMPOAI7.cjs.map +0 -1
  203. package/dist/chunk-R24DI24X.cjs.map +0 -1
  204. package/dist/chunk-SFQWJMKT.js.map +0 -1
  205. package/dist/chunk-WWOLFXTX.cjs.map +0 -1
  206. package/dist/chunk-YU2CUNFO.js.map +0 -1
@@ -1,19 +1,20 @@
1
- import { ParseletRegistry, PrecedenceParser } from './chunk-MEOHSQEH.js';
1
+ import { ParseletRegistry, PrecedenceParser } from './chunk-3LAEG75D.js';
2
2
  import { ResolverRegistry } from './chunk-3VGDNEE3.js';
3
3
  import { abortLogger, djb2Hash } from './chunk-IF532O7C.js';
4
- import { executeBytecode, createVM, DependencyGraph, ScopeManager } from './chunk-BAMZT3GL.js';
4
+ import { executeBytecode, createVM, DependencyGraph, ScopeManager } from './chunk-5WVP4YHP.js';
5
5
  import { DiagnosticPipeline, TimelineDiagnosticCollector, DiagnosticEventType } from './chunk-G535KJEG.js';
6
- import { BUILTIN_PACKAGES, containsSymbolicCall } from './chunk-GVWHCL2N.js';
7
- import { BytecodeBuilder } from './chunk-6GCKCWLB.js';
8
- import { TokenNormalizer, BUILTIN_PHRASES, implicitMultiplyRule } from './chunk-OFXOTECC.js';
6
+ import { BUILTIN_PACKAGES, containsSymbolicCall } from './chunk-HMOISHXR.js';
7
+ import { BytecodeBuilder } from './chunk-526PMQOA.js';
8
+ import { TokenNormalizer, BUILTIN_PHRASES, implicitMultiplyRule } from './chunk-YPPPYLSR.js';
9
+ import { countLines } from './chunk-3BOK2LDK.js';
9
10
  import { createQueryClient, setActiveQueryClient, getActiveQueryClient } from './chunk-NLNDMWZC.js';
10
- import { sharedOpRegistry, createEngineContext, registerAsConverter, unregisterAsConverter, solveEquationValues, globalDagKey, sharedGlobalVariableStore } from './chunk-MVBEL57Q.js';
11
- import { matrixMultiply, inverse } from './chunk-CYFK5SY2.js';
12
- import { pendingValue, errorValue, stringValue, numberValue, freezeIfDev, boolValue, uomValue, percentageValue, datetimeValue, bigIntValue, hexValue, enableValueArena, disableValueArena } from './chunk-BVAR5J2F.js';
13
- import { mergeEngineConfig, DEFAULT_CONFIG, ENGINE_VERSION } from './chunk-LVLUHTRD.js';
14
- import { Lexer, buildTokenLookup, sharedLexer } from './chunk-2CS6OMZK.js';
11
+ import { sharedOpRegistry, createEngineContext, registerAsConverter, unregisterAsConverter, solveEquationValues, globalDagKey, sharedGlobalVariableStore } from './chunk-Y7FT4IQT.js';
12
+ import { matrixMultiply, inverse } from './chunk-O3ANBHSA.js';
13
+ import { pendingValue, errorValue, stringValue, numberValue, freezeIfDev, boolValue, uomValue, percentageValue, datetimeValue, bigIntValue, hexValue, enableValueArena, disableValueArena } from './chunk-GQCOSXMG.js';
14
+ import { mergeEngineConfig, DEFAULT_CONFIG, ENGINE_VERSION } from './chunk-GLG5ZMX7.js';
15
+ import { Lexer, buildTokenLookup, sharedLexer } from './chunk-5F4C26RU.js';
15
16
  import { registerTokenCategory, unregisterTokenCategory } from './chunk-AJA6LUI7.js';
16
- import { normalizeUnknownError, ErrorFactory, EngineError } from './chunk-6RDSQURE.js';
17
+ import { normalizeUnknownError, ErrorFactory, EngineError } from './chunk-3D7V24DG.js';
17
18
  import { __commonJS, __toESM } from './chunk-YLJ4XMA6.js';
18
19
 
19
20
  // node_modules/semver/internal/constants.js
@@ -3457,6 +3458,11 @@ var ExpressionEngine = class {
3457
3458
  this.config.vm.maxStackDepth,
3458
3459
  this.config.vm.maxInstructions,
3459
3460
  void 0,
3461
+ this.config.vm.maxCollectionSize,
3462
+ this.config.vm.maxAllocatedElements,
3463
+ this.config.vm.maxFunctionCalls,
3464
+ this.config.date.maxOffsetYears,
3465
+ this.config.date.minOffsetYears,
3460
3466
  this.context
3461
3467
  );
3462
3468
  this.queryClient = createQueryClient();
@@ -3577,7 +3583,8 @@ var ExpressionEngine = class {
3577
3583
  resolverNamespaces: [],
3578
3584
  tokenCategories: [],
3579
3585
  lexerVocabulary: pkg.lexerVocabulary,
3580
- asConverterNames: []
3586
+ asConverterNames: [],
3587
+ normalizerRuleNames: []
3581
3588
  };
3582
3589
  if (pkg.lexerVocabulary) {
3583
3590
  this.lexer.registerVocabulary(pkg.lexerVocabulary);
@@ -3619,6 +3626,7 @@ var ExpressionEngine = class {
3619
3626
  if (pkg.normalizerRules) {
3620
3627
  for (const rule of pkg.normalizerRules) {
3621
3628
  this.normalizer.register(rule);
3629
+ contribution.normalizerRuleNames.push(rule.name);
3622
3630
  }
3623
3631
  }
3624
3632
  if (pkg.tokenCategories) {
@@ -3652,9 +3660,17 @@ var ExpressionEngine = class {
3652
3660
  * own contract). This engine-instance-local registration is reversed
3653
3661
  * here too, even though it isn't a "shared" registry, so a package's
3654
3662
  * lexer and highlighting contributions clean up together rather than
3655
- * only half-reversing on unregister. Per-engine parselets/phrases are
3656
- * still left in place: they live in this engine's isolated registries
3657
- * and are discarded with the engine instance.
3663
+ * only half-reversing on unregister. Normalizer rules are reversed here
3664
+ * for the same reason: they are per-engine, but they live in an ARRAY the
3665
+ * normalizer walks at every token position, so re-registering a package
3666
+ * appended a second copy of every rule and lexing got slower with every
3667
+ * register/unregister cycle.
3668
+ *
3669
+ * Per-engine parselets and phrases are still left in place: a parselet
3670
+ * lives in this engine's isolated registry and a phrase goes into a
3671
+ * text-keyed trie where registering the same phrase twice is the same as
3672
+ * registering it once, so neither accumulates and both are discarded with
3673
+ * the engine instance.
3658
3674
  *
3659
3675
  * Clears the bytecode cache, removing handlers changes what compiled
3660
3676
  * bytecode is valid.
@@ -3684,6 +3700,9 @@ var ExpressionEngine = class {
3684
3700
  for (const name of contribution.asConverterNames) {
3685
3701
  unregisterAsConverter(name);
3686
3702
  }
3703
+ for (const ruleName of contribution.normalizerRuleNames) {
3704
+ this.normalizer.unregister(ruleName);
3705
+ }
3687
3706
  this.packageCompletionItems.delete(packageName);
3688
3707
  this.packageContributions.delete(packageName);
3689
3708
  this.registeredPackages.delete(packageName);
@@ -3861,6 +3880,14 @@ var ExpressionEngine = class {
3861
3880
  * with precise coordinate mapping for inline solves.
3862
3881
  */
3863
3882
  parseDocument(input, options = { inputType: "markdown" }) {
3883
+ const maxLines = this.config.performance.maxDocumentLines;
3884
+ if (countLines(input, maxLines) > maxLines) {
3885
+ throw ErrorFactory.execution(
3886
+ "DOCUMENT_TOO_LARGE",
3887
+ `This document has more than ${maxLines.toLocaleString("en-US")} lines, which is the most the engine will process in one pass`,
3888
+ { maxLines }
3889
+ );
3890
+ }
3864
3891
  const scanResults = this.lexer.scanDocument(input);
3865
3892
  const processedLines = this.processScanResults(scanResults);
3866
3893
  const result = {
@@ -4009,8 +4036,14 @@ var ExpressionEngine = class {
4009
4036
  * parseExpression(). Abstracts the API difference between the two parsers:
4010
4037
  * - PrecedenceParser: parser.setBuilder(builder); parser.parseExpression(0)
4011
4038
  * - RD: parser.builder = builder; parser.parseExpression(0)
4039
+ *
4040
+ * @param allowLabelFallback - Whether a line that does not parse whole may
4041
+ * be retried as "<label>: <expression>". True for a real line, false for
4042
+ * the retries that fallback makes itself, which is what stops it costing
4043
+ * exponential time; see the loop below, and the comment on its recursive
4044
+ * call for the measurement.
4012
4045
  */
4013
- parseExpression(builder, tokens, hasParens) {
4046
+ parseExpression(builder, tokens, hasParens, allowLabelFallback = true) {
4014
4047
  this.parser.setBuilder(builder);
4015
4048
  this.parser.load(tokens, this.config.validation.autoBalanceParens ? hasParens : false);
4016
4049
  this.parser.parseExpression(0);
@@ -4019,12 +4052,28 @@ var ExpressionEngine = class {
4019
4052
  if (leftover.type === "EQUALS" && !this.parser.peekAt(1)) {
4020
4053
  return;
4021
4054
  }
4022
- for (let i = tokens.length - 1; i >= 1; i--) {
4055
+ for (let i = allowLabelFallback ? tokens.length - 1 : 0; i >= 1; i--) {
4023
4056
  if (tokens[i].type !== "COLON") continue;
4024
4057
  if (i + 1 >= tokens.length) continue;
4058
+ let labelIsAllNumeric = true;
4059
+ for (let j = 0; j < i; j++) {
4060
+ const type = tokens[j].type;
4061
+ if (type !== "NUMBER" && type !== "COLON") {
4062
+ labelIsAllNumeric = false;
4063
+ break;
4064
+ }
4065
+ }
4066
+ if (labelIsAllNumeric) {
4067
+ const literal = tokens.slice(0, i + 2).map((t) => t.value).join("");
4068
+ throw ErrorFactory.parsing(
4069
+ "INVALID_TIME_LITERAL",
4070
+ `"${literal}" is not a valid time`,
4071
+ { tokenType: tokens[i].type, tokenValue: literal }
4072
+ );
4073
+ }
4025
4074
  builder.reset();
4026
4075
  try {
4027
- this.parseExpression(builder, tokens.slice(i + 1), hasParens);
4076
+ this.parseExpression(builder, tokens.slice(i + 1), hasParens, false);
4028
4077
  return;
4029
4078
  } catch {
4030
4079
  }
@@ -4060,9 +4109,17 @@ var ExpressionEngine = class {
4060
4109
  * (a bare assignment's RHS, and an equation's own RHS at solve time)
4061
4110
  *, every one of these needs forward-tolerant reads of not-yet-defined
4062
4111
  * names, which ordinary evaluation deliberately never allows.
4112
+ *
4113
+ * `lineNumber` is the 1-based document line this program belongs to, so
4114
+ * the RHS still receives a {@link makeLineContext}, a bare assignment's
4115
+ * right-hand side (`total = prev`, `x = line2`) can therefore read
4116
+ * cross-line results exactly as a bare expression line does. Defaults to
4117
+ * `-1` (the "no real document" sentinel) for the expression-level and
4118
+ * `=>`-without-a-document callers, which naturally yields the same
4119
+ * `LINE_REF_NO_DOCUMENT` a single-expression eval already returns.
4063
4120
  */
4064
- executeSymbolicTolerant(program) {
4065
- const result = executeBytecode(program, this.vm, void 0, void 0, void 0, true);
4121
+ executeSymbolicTolerant(program, lineNumber = -1) {
4122
+ const result = executeBytecode(program, this.vm, void 0, void 0, this.makeLineContext(lineNumber), true);
4066
4123
  if (result.type === "error") throw result.error;
4067
4124
  if (result.type === "pending") {
4068
4125
  throw ErrorFactory.execution(
@@ -4072,9 +4129,9 @@ var ExpressionEngine = class {
4072
4129
  }
4073
4130
  return result.value;
4074
4131
  }
4075
- /** Compiles and executes `tokens` in symbolic-tolerant mode, the "just simplify this" `=>` fallback when there's no stored equation to solve. */
4076
- simplifySymbolically(tokens) {
4077
- return this.executeSymbolicTolerant(this.compileAdHoc(tokens));
4132
+ /** Compiles and executes `tokens` in symbolic-tolerant mode, the "just simplify this" `=>` fallback when there's no stored equation to solve. `lineNumber` (1-based, `-1` outside a document) is forwarded so a bare assignment's RHS can resolve cross-line references. */
4133
+ simplifySymbolically(tokens, lineNumber = -1) {
4134
+ return this.executeSymbolicTolerant(this.compileAdHoc(tokens), lineNumber);
4078
4135
  }
4079
4136
  /**
4080
4137
  * Parses a bare (colon-less) equation's left-hand side, `factor1 *
@@ -4119,7 +4176,7 @@ var ExpressionEngine = class {
4119
4176
  * errors propagate as values" convention (DIMENSION_MISMATCH,
4120
4177
  * SINGULAR_MATRIX, ...).
4121
4178
  */
4122
- solveEquation(equation) {
4179
+ solveEquation(equation, lineNumber = -1) {
4123
4180
  const factorValues = [];
4124
4181
  for (const name of equation.factorNames) {
4125
4182
  const v = this.vm.getVar(name);
@@ -4145,7 +4202,7 @@ var ExpressionEngine = class {
4145
4202
  }
4146
4203
  const inv = inverse(combined);
4147
4204
  if (inv.type === 13 /* Error */) return inv;
4148
- const rhsValue = this.executeSymbolicTolerant(equation.rhsProgram);
4205
+ const rhsValue = this.executeSymbolicTolerant(equation.rhsProgram, lineNumber);
4149
4206
  if (rhsValue.type !== 7 /* Matrix */) {
4150
4207
  return errorValue(
4151
4208
  "EQUATION_RHS_NOT_MATRIX",
@@ -4185,7 +4242,7 @@ var ExpressionEngine = class {
4185
4242
  * session's own Phase H.2 scope decision (full symbolic MATRICES, not
4186
4243
  * a general CAS).
4187
4244
  */
4188
- trySymbolicGrammar(normalizedTokens) {
4245
+ trySymbolicGrammar(normalizedTokens, lineNumber = -1) {
4189
4246
  if (normalizedTokens.length === 0) return null;
4190
4247
  const last = normalizedTokens[normalizedTokens.length - 1];
4191
4248
  if (last.type === "THEREFORE") {
@@ -4198,18 +4255,18 @@ var ExpressionEngine = class {
4198
4255
  const equation = this.vm.getEquation(name);
4199
4256
  const scalar = this.vm.getScalarEquation(name);
4200
4257
  if (equation) {
4201
- const solved = this.solveEquation(equation);
4258
+ const solved = this.solveEquation(equation, lineNumber);
4202
4259
  const isNotMatrix = solved.type === 13 /* Error */ && solved.value === "EQUATION_FACTOR_NOT_MATRIX";
4203
4260
  if (!isNotMatrix || !scalar) return solved;
4204
4261
  }
4205
4262
  if (scalar) {
4206
- return this.solveScalarEquation(scalar);
4263
+ return this.solveScalarEquation(scalar, lineNumber);
4207
4264
  }
4208
4265
  }
4209
- return this.simplifySymbolically(beforeTokens);
4266
+ return this.simplifySymbolically(beforeTokens, lineNumber);
4210
4267
  }
4211
4268
  if (containsSymbolicCall(normalizedTokens)) {
4212
- return this.simplifySymbolically(normalizedTokens);
4269
+ return this.simplifySymbolically(normalizedTokens, lineNumber);
4213
4270
  }
4214
4271
  if (normalizedTokens[0].type === "COLON" || normalizedTokens[0].type === "GLOBAL") return null;
4215
4272
  const eqIdx = normalizedTokens.findIndex((t) => t.type === "EQUALS");
@@ -4220,7 +4277,7 @@ var ExpressionEngine = class {
4220
4277
  }
4221
4278
  const rhsTokens = normalizedTokens.slice(eqIdx + 1);
4222
4279
  if (names.length === 1) {
4223
- const result = this.simplifySymbolically(rhsTokens);
4280
+ const result = this.simplifySymbolically(rhsTokens, lineNumber);
4224
4281
  this.vm.setVar(names[0], result);
4225
4282
  return result;
4226
4283
  }
@@ -4306,9 +4363,9 @@ var ExpressionEngine = class {
4306
4363
  * @returns The solution, rendered by the same helper `solve()` uses, so the
4307
4364
  * two surfaces cannot disagree about how an outcome reads.
4308
4365
  */
4309
- solveScalarEquation(equation) {
4310
- const lhs = this.executeSymbolicTolerant(equation.lhsProgram);
4311
- const rhs = this.executeSymbolicTolerant(equation.rhsProgram);
4366
+ solveScalarEquation(equation, lineNumber = -1) {
4367
+ const lhs = this.executeSymbolicTolerant(equation.lhsProgram, lineNumber);
4368
+ const rhs = this.executeSymbolicTolerant(equation.rhsProgram, lineNumber);
4312
4369
  return solveEquationValues(lhs, rhs, equation.variable);
4313
4370
  }
4314
4371
  //#endregion
@@ -4386,7 +4443,7 @@ var ExpressionEngine = class {
4386
4443
  * produced negative-allocation readings (a GC sweep landing inside the
4387
4444
  * wider window) in `AllocationTracker.spec.ts` well over half the time.
4388
4445
  */
4389
- prepareExpression(expression, tokens, hasParens, onFusion) {
4446
+ prepareExpression(expression, tokens, hasParens, onFusion, lineNumber = -1) {
4390
4447
  const lengthCheck = checkExpressionLength(expression, this.config.validation);
4391
4448
  if (!lengthCheck.passed) {
4392
4449
  return { kind: "error", stage: "length", error: lengthCheck.error.engineError };
@@ -4400,7 +4457,7 @@ var ExpressionEngine = class {
4400
4457
  if (!complexityCheck.passed) {
4401
4458
  return { kind: "error", stage: "complexity", error: complexityCheck.engineError, normalizedTokens };
4402
4459
  }
4403
- const symbolicResult = this.trySymbolicGrammar(normalizedTokens);
4460
+ const symbolicResult = this.trySymbolicGrammar(normalizedTokens, lineNumber);
4404
4461
  if (symbolicResult !== null) {
4405
4462
  return { kind: "symbolic-solve", normalizedTokens, value: symbolicResult };
4406
4463
  }
@@ -4507,7 +4564,7 @@ var ExpressionEngine = class {
4507
4564
  * {@link preflightAsync}) + VM execution (via {@link executeAndStore}).
4508
4565
  */
4509
4566
  evaluateWithTokens(lineNumber, expression, tokens, hasParens) {
4510
- const prep = this.prepareExpression(expression, tokens, hasParens);
4567
+ const prep = this.prepareExpression(expression, tokens, hasParens, void 0, lineNumber);
4511
4568
  if (prep.kind === "empty") {
4512
4569
  const v = numberValue(0);
4513
4570
  this.lineCache.set(lineNumber, new LineCacheEntry(v, { opcodes: new Uint8Array(0), numbers: new Float64Array(0), strings: [], hasAsync: false }, [], null), expression);
@@ -4836,7 +4893,7 @@ var ExpressionEngine = class {
4836
4893
  if (hasCollectors && !cachedBefore) {
4837
4894
  this.parser.setDiagnosticPipeline(pipeline, expression);
4838
4895
  }
4839
- const prep = this.prepareExpression(expression, tokens, hasParens, onFusion);
4896
+ const prep = this.prepareExpression(expression, tokens, hasParens, onFusion, lineNumber);
4840
4897
  if (trackEnabled && prep.kind === "ready" && prep.parserAlloc) {
4841
4898
  stageAllocs.push(prep.parserAlloc);
4842
4899
  }
@@ -5945,7 +6002,14 @@ function pseudoRandom(seed) {
5945
6002
 
5946
6003
  // src/engine/DocumentModel.ts
5947
6004
  var DocumentModel = class {
5948
- constructor() {
6005
+ /**
6006
+ * @param maxLines - Ceiling on the line count, defaulting to the engine's
6007
+ * configured one. Every line costs a LineState with six arrays in it
6008
+ * whatever the line says, so the cost of a document is its line count and
6009
+ * nothing else bounds it: two hundred thousand lines of `1 + 1` exhausted
6010
+ * the heap here, before a single expression had been looked at.
6011
+ */
6012
+ constructor(maxLines = DEFAULT_CONFIG.performance.maxDocumentLines) {
5949
6013
  /** Persistent line ID → LineState. */
5950
6014
  this.lines = /* @__PURE__ */ new Map();
5951
6015
  /** Order-statistic treap representing the current document line order. */
@@ -5970,13 +6034,26 @@ var DocumentModel = class {
5970
6034
  * bottom of a 20k-line document before this fix.
5971
6035
  */
5972
6036
  this.dirtyLineIds = /* @__PURE__ */ new Set();
6037
+ this.maxLines = maxLines;
5973
6038
  }
5974
6039
  // ── Initialization ──────────────────────────────────────────────────
5975
6040
  /**
5976
6041
  * Initialize or replace the entire document from a text blob.
5977
6042
  * Clears all existing state and assigns new persistent line IDs.
6043
+ *
6044
+ * @throws `DOCUMENT_TOO_LARGE` for a document past {@link maxLines}, before
6045
+ * any of it is stored. Recoverable: nothing has been replaced yet, so the
6046
+ * model still holds whatever it held.
5978
6047
  */
5979
6048
  setDocument(text) {
6049
+ const lineCount = countLines(text, this.maxLines);
6050
+ if (lineCount > this.maxLines) {
6051
+ throw ErrorFactory.execution(
6052
+ "DOCUMENT_TOO_LARGE",
6053
+ `This document has more than ${this.maxLines.toLocaleString("en-US")} lines, which is the most the engine will hold at once`,
6054
+ { maxLines: this.maxLines }
6055
+ );
6056
+ }
5980
6057
  this.lines.clear();
5981
6058
  this.orderTree.clear();
5982
6059
  this._positionCache = null;
@@ -7469,5 +7546,5 @@ var ThreeTierEvaluator = class {
7469
7546
  };
7470
7547
 
7471
7548
  export { AsyncResolutionBatcher, DocumentModel, EvalTier, ExpressionEngine, ThreeTierEvaluator, assertEngineVersionCompatible, checkEngineVersionCompatibility, checkExpressionComplexity, checkExpressionLength, checkPackageCompatibility, extractReadsAndWrites, findInlineSolvesInLine, isEmptyLine };
7472
- //# sourceMappingURL=chunk-NUR3K7EW.js.map
7473
- //# sourceMappingURL=chunk-NUR3K7EW.js.map
7549
+ //# sourceMappingURL=chunk-3VNGREMU.js.map
7550
+ //# sourceMappingURL=chunk-3VNGREMU.js.map