solve-engine 1.0.0-beta.0 → 1.0.0-beta.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 (253) hide show
  1. package/dist/BytecodeBuilder-3egMyuDi.d.cts +274 -0
  2. package/dist/BytecodeBuilder-3egMyuDi.d.ts +274 -0
  3. package/dist/Configuration-fVpd-HC-.d.cts +228 -0
  4. package/dist/Configuration-fVpd-HC-.d.ts +228 -0
  5. package/dist/EngineError-DvPSnhZi.d.cts +304 -0
  6. package/dist/EngineError-DvPSnhZi.d.ts +304 -0
  7. package/dist/Lexer-BJdhlnej.d.cts +531 -0
  8. package/dist/Lexer-D9l4Yrk2.d.ts +531 -0
  9. package/dist/NormalizerRule-BrVoVjmP.d.cts +163 -0
  10. package/dist/NormalizerRule-CEjf1FyD.d.ts +163 -0
  11. package/dist/PackageRegistry-D-Tv_7ca.d.cts +2572 -0
  12. package/dist/PackageRegistry-DaH4aIKP.d.ts +2572 -0
  13. package/dist/Parselet-CK8cQu2a.d.cts +299 -0
  14. package/dist/Parselet-ConOIdRO.d.ts +299 -0
  15. package/dist/ScopeManager-B5k0nk05.d.ts +559 -0
  16. package/dist/ScopeManager-CKfQtl7l.d.cts +559 -0
  17. package/dist/Token-0jpvUdPY.d.cts +245 -0
  18. package/dist/Token-0jpvUdPY.d.ts +245 -0
  19. package/dist/VMCheckpoints-BmDwIXgK.d.ts +171 -0
  20. package/dist/VMCheckpoints-CqFuLwrT.d.cts +171 -0
  21. package/dist/Value-KtAQNHur.d.cts +295 -0
  22. package/dist/Value-KtAQNHur.d.ts +295 -0
  23. package/dist/chunk-2RWAXT6O.js +3 -0
  24. package/dist/chunk-2RWAXT6O.js.map +1 -0
  25. package/dist/chunk-34RRD7PC.js +1492 -0
  26. package/dist/chunk-34RRD7PC.js.map +1 -0
  27. package/dist/chunk-3PPFLFH4.js +5097 -0
  28. package/dist/chunk-3PPFLFH4.js.map +1 -0
  29. package/dist/chunk-3VGDNEE3.js +84 -0
  30. package/dist/chunk-3VGDNEE3.js.map +1 -0
  31. package/dist/chunk-3YNVWKR2.cjs +370 -0
  32. package/dist/chunk-3YNVWKR2.cjs.map +1 -0
  33. package/dist/chunk-47LRVGOT.cjs +316 -0
  34. package/dist/chunk-47LRVGOT.cjs.map +1 -0
  35. package/dist/chunk-4MG4XKO2.js +1644 -0
  36. package/dist/chunk-4MG4XKO2.js.map +1 -0
  37. package/dist/chunk-4QADQTWS.js +2392 -0
  38. package/dist/chunk-4QADQTWS.js.map +1 -0
  39. package/dist/chunk-53B6KDDJ.cjs +1651 -0
  40. package/dist/chunk-53B6KDDJ.cjs.map +1 -0
  41. package/dist/chunk-5X2PTP6F.cjs +104 -0
  42. package/dist/chunk-5X2PTP6F.cjs.map +1 -0
  43. package/dist/chunk-5YEMOYSE.js +264 -0
  44. package/dist/chunk-5YEMOYSE.js.map +1 -0
  45. package/dist/chunk-64W6GLLZ.js +481 -0
  46. package/dist/chunk-64W6GLLZ.js.map +1 -0
  47. package/dist/chunk-6BKTCEUP.cjs +233 -0
  48. package/dist/chunk-6BKTCEUP.cjs.map +1 -0
  49. package/dist/chunk-6NTVRDQV.cjs +1642 -0
  50. package/dist/chunk-6NTVRDQV.cjs.map +1 -0
  51. package/dist/chunk-6RDSQURE.js +290 -0
  52. package/dist/chunk-6RDSQURE.js.map +1 -0
  53. package/dist/chunk-75JP4BZX.js +93 -0
  54. package/dist/chunk-75JP4BZX.js.map +1 -0
  55. package/dist/chunk-B7LXJ6LC.cjs +36 -0
  56. package/dist/chunk-B7LXJ6LC.cjs.map +1 -0
  57. package/dist/chunk-BVAR5J2F.js +257 -0
  58. package/dist/chunk-BVAR5J2F.js.map +1 -0
  59. package/dist/chunk-C4XZV6E7.cjs +269 -0
  60. package/dist/chunk-C4XZV6E7.cjs.map +1 -0
  61. package/dist/chunk-CCJPSHGI.cjs +40 -0
  62. package/dist/chunk-CCJPSHGI.cjs.map +1 -0
  63. package/dist/chunk-CLL7RUQV.cjs +316 -0
  64. package/dist/chunk-CLL7RUQV.cjs.map +1 -0
  65. package/dist/chunk-DM3LMRBC.js +329 -0
  66. package/dist/chunk-DM3LMRBC.js.map +1 -0
  67. package/dist/chunk-DUEZFTK2.js +38 -0
  68. package/dist/chunk-DUEZFTK2.js.map +1 -0
  69. package/dist/chunk-EBSPLUW4.cjs +489 -0
  70. package/dist/chunk-EBSPLUW4.cjs.map +1 -0
  71. package/dist/chunk-EHAHVROS.cjs +261 -0
  72. package/dist/chunk-EHAHVROS.cjs.map +1 -0
  73. package/dist/chunk-EIGTWK5N.js +167 -0
  74. package/dist/chunk-EIGTWK5N.js.map +1 -0
  75. package/dist/chunk-EPOXXJBK.js +96 -0
  76. package/dist/chunk-EPOXXJBK.js.map +1 -0
  77. package/dist/chunk-FEAIOR7N.cjs +91 -0
  78. package/dist/chunk-FEAIOR7N.cjs.map +1 -0
  79. package/dist/chunk-G535KJEG.js +312 -0
  80. package/dist/chunk-G535KJEG.js.map +1 -0
  81. package/dist/chunk-GCM5JHMX.js +88 -0
  82. package/dist/chunk-GCM5JHMX.js.map +1 -0
  83. package/dist/chunk-GOLDJNMZ.js +368 -0
  84. package/dist/chunk-GOLDJNMZ.js.map +1 -0
  85. package/dist/chunk-GW32KPCU.cjs +360 -0
  86. package/dist/chunk-GW32KPCU.cjs.map +1 -0
  87. package/dist/chunk-HTXVVJRA.cjs +1549 -0
  88. package/dist/chunk-HTXVVJRA.cjs.map +1 -0
  89. package/dist/chunk-HWSZJQCI.js +311 -0
  90. package/dist/chunk-HWSZJQCI.js.map +1 -0
  91. package/dist/chunk-IF532O7C.js +101 -0
  92. package/dist/chunk-IF532O7C.js.map +1 -0
  93. package/dist/chunk-J73SJHR3.cjs +2415 -0
  94. package/dist/chunk-J73SJHR3.cjs.map +1 -0
  95. package/dist/chunk-JBSYC7BB.cjs +7473 -0
  96. package/dist/chunk-JBSYC7BB.cjs.map +1 -0
  97. package/dist/chunk-KVILKGMS.js +228 -0
  98. package/dist/chunk-KVILKGMS.js.map +1 -0
  99. package/dist/chunk-LIPPNDBE.js +258 -0
  100. package/dist/chunk-LIPPNDBE.js.map +1 -0
  101. package/dist/chunk-LR7YASZF.cjs +172 -0
  102. package/dist/chunk-LR7YASZF.cjs.map +1 -0
  103. package/dist/chunk-M4N5GA5Z.cjs +309 -0
  104. package/dist/chunk-M4N5GA5Z.cjs.map +1 -0
  105. package/dist/chunk-M5LX5AOO.js +7459 -0
  106. package/dist/chunk-M5LX5AOO.js.map +1 -0
  107. package/dist/chunk-MZOVP3WI.cjs +96 -0
  108. package/dist/chunk-MZOVP3WI.cjs.map +1 -0
  109. package/dist/chunk-N5YFR4UP.cjs +10 -0
  110. package/dist/chunk-N5YFR4UP.cjs.map +1 -0
  111. package/dist/chunk-NGBBNL4K.cjs +4 -0
  112. package/dist/chunk-NGBBNL4K.cjs.map +1 -0
  113. package/dist/chunk-NH2O2AUR.js +146 -0
  114. package/dist/chunk-NH2O2AUR.js.map +1 -0
  115. package/dist/chunk-NLNDMWZC.js +31 -0
  116. package/dist/chunk-NLNDMWZC.js.map +1 -0
  117. package/dist/chunk-NMCRQP3Z.cjs +778 -0
  118. package/dist/chunk-NMCRQP3Z.cjs.map +1 -0
  119. package/dist/chunk-NMD5VRN4.cjs +1327 -0
  120. package/dist/chunk-NMD5VRN4.cjs.map +1 -0
  121. package/dist/chunk-OC6LTXYS.cjs +286 -0
  122. package/dist/chunk-OC6LTXYS.cjs.map +1 -0
  123. package/dist/chunk-OT6OJY7C.cjs +114 -0
  124. package/dist/chunk-OT6OJY7C.cjs.map +1 -0
  125. package/dist/chunk-PFSDGGYL.js +8 -0
  126. package/dist/chunk-PFSDGGYL.js.map +1 -0
  127. package/dist/chunk-QNJ4ACRT.cjs +155 -0
  128. package/dist/chunk-QNJ4ACRT.cjs.map +1 -0
  129. package/dist/chunk-QWY3VEZN.js +1637 -0
  130. package/dist/chunk-QWY3VEZN.js.map +1 -0
  131. package/dist/chunk-RFYD5TJE.js +111 -0
  132. package/dist/chunk-RFYD5TJE.js.map +1 -0
  133. package/dist/chunk-RIN643A3.js +354 -0
  134. package/dist/chunk-RIN643A3.js.map +1 -0
  135. package/dist/chunk-RZCWSXTA.cjs +5122 -0
  136. package/dist/chunk-RZCWSXTA.cjs.map +1 -0
  137. package/dist/chunk-SDGRK7EP.js +774 -0
  138. package/dist/chunk-SDGRK7EP.js.map +1 -0
  139. package/dist/chunk-VEKIWQ3F.cjs +39 -0
  140. package/dist/chunk-VEKIWQ3F.cjs.map +1 -0
  141. package/dist/chunk-WQTTOGXC.cjs +99 -0
  142. package/dist/chunk-WQTTOGXC.cjs.map +1 -0
  143. package/dist/chunk-X6K3HUOY.cjs +86 -0
  144. package/dist/chunk-X6K3HUOY.cjs.map +1 -0
  145. package/dist/chunk-XJCMXB2E.cjs +333 -0
  146. package/dist/chunk-XJCMXB2E.cjs.map +1 -0
  147. package/dist/chunk-XVWCOTR6.js +1324 -0
  148. package/dist/chunk-XVWCOTR6.js.map +1 -0
  149. package/dist/chunk-YLJ4XMA6.js +33 -0
  150. package/dist/chunk-YLJ4XMA6.js.map +1 -0
  151. package/dist/chunk-Z2XP767T.cjs +35 -0
  152. package/dist/chunk-Z2XP767T.cjs.map +1 -0
  153. package/dist/chunk-Z4X2RWOF.js +37 -0
  154. package/dist/chunk-Z4X2RWOF.js.map +1 -0
  155. package/dist/constants.cjs +22 -0
  156. package/dist/constants.cjs.map +1 -0
  157. package/dist/constants.d.cts +12 -0
  158. package/dist/constants.d.ts +12 -0
  159. package/dist/constants.js +5 -0
  160. package/dist/constants.js.map +1 -0
  161. package/dist/engine.cjs +79 -0
  162. package/dist/engine.cjs.map +1 -0
  163. package/dist/engine.d.cts +587 -0
  164. package/dist/engine.d.ts +587 -0
  165. package/dist/engine.js +34 -0
  166. package/dist/engine.js.map +1 -0
  167. package/dist/errors.cjs +81 -0
  168. package/dist/errors.cjs.map +1 -0
  169. package/dist/errors.d.cts +95 -0
  170. package/dist/errors.d.ts +95 -0
  171. package/dist/errors.js +4 -0
  172. package/dist/errors.js.map +1 -0
  173. package/dist/format.cjs +171 -0
  174. package/dist/format.cjs.map +1 -0
  175. package/dist/format.d.cts +51 -0
  176. package/dist/format.d.ts +51 -0
  177. package/dist/format.js +168 -0
  178. package/dist/format.js.map +1 -0
  179. package/dist/index.cjs +97 -0
  180. package/dist/index.cjs.map +1 -0
  181. package/dist/index.d.cts +152 -0
  182. package/dist/index.d.ts +152 -0
  183. package/dist/index.js +75 -0
  184. package/dist/index.js.map +1 -0
  185. package/dist/language.cjs +308 -0
  186. package/dist/language.cjs.map +1 -0
  187. package/dist/language.d.cts +110 -0
  188. package/dist/language.d.ts +110 -0
  189. package/dist/language.js +287 -0
  190. package/dist/language.js.map +1 -0
  191. package/dist/lexer.cjs +64 -0
  192. package/dist/lexer.cjs.map +1 -0
  193. package/dist/lexer.d.cts +56 -0
  194. package/dist/lexer.d.ts +56 -0
  195. package/dist/lexer.js +11 -0
  196. package/dist/lexer.js.map +1 -0
  197. package/dist/normalizer.cjs +40 -0
  198. package/dist/normalizer.cjs.map +1 -0
  199. package/dist/normalizer.d.cts +364 -0
  200. package/dist/normalizer.d.ts +364 -0
  201. package/dist/normalizer.js +11 -0
  202. package/dist/normalizer.js.map +1 -0
  203. package/dist/packages.cjs +121 -0
  204. package/dist/packages.cjs.map +1 -0
  205. package/dist/packages.d.cts +691 -0
  206. package/dist/packages.d.ts +691 -0
  207. package/dist/packages.js +24 -0
  208. package/dist/packages.js.map +1 -0
  209. package/dist/parser.cjs +55 -0
  210. package/dist/parser.cjs.map +1 -0
  211. package/dist/parser.d.cts +46 -0
  212. package/dist/parser.d.ts +46 -0
  213. package/dist/parser.js +10 -0
  214. package/dist/parser.js.map +1 -0
  215. package/dist/pipeline-CrsRPmsv.d.ts +285 -0
  216. package/dist/pipeline-DPUQt7yL.d.cts +285 -0
  217. package/dist/resolvers.cjs +13 -0
  218. package/dist/resolvers.cjs.map +1 -0
  219. package/dist/resolvers.d.cts +111 -0
  220. package/dist/resolvers.d.ts +111 -0
  221. package/dist/resolvers.js +4 -0
  222. package/dist/resolvers.js.map +1 -0
  223. package/dist/services.cjs +21 -0
  224. package/dist/services.cjs.map +1 -0
  225. package/dist/services.d.cts +30 -0
  226. package/dist/services.d.ts +30 -0
  227. package/dist/services.js +4 -0
  228. package/dist/services.js.map +1 -0
  229. package/dist/uom.cjs +56 -0
  230. package/dist/uom.cjs.map +1 -0
  231. package/dist/uom.d.cts +224 -0
  232. package/dist/uom.d.ts +224 -0
  233. package/dist/uom.js +11 -0
  234. package/dist/uom.js.map +1 -0
  235. package/dist/utilities.cjs +32 -0
  236. package/dist/utilities.cjs.map +1 -0
  237. package/dist/utilities.d.cts +113 -0
  238. package/dist/utilities.d.ts +113 -0
  239. package/dist/utilities.js +7 -0
  240. package/dist/utilities.js.map +1 -0
  241. package/dist/variables.cjs +17 -0
  242. package/dist/variables.cjs.map +1 -0
  243. package/dist/variables.d.cts +87 -0
  244. package/dist/variables.d.ts +87 -0
  245. package/dist/variables.js +4 -0
  246. package/dist/variables.js.map +1 -0
  247. package/dist/vm.cjs +284 -0
  248. package/dist/vm.cjs.map +1 -0
  249. package/dist/vm.d.cts +68 -0
  250. package/dist/vm.d.ts +68 -0
  251. package/dist/vm.js +194 -0
  252. package/dist/vm.js.map +1 -0
  253. package/package.json +4 -4
@@ -0,0 +1,778 @@
1
+ 'use strict';
2
+
3
+ var chunk47LRVGOT_cjs = require('./chunk-47LRVGOT.cjs');
4
+ var chunkC4XZV6E7_cjs = require('./chunk-C4XZV6E7.cjs');
5
+ var chunkGW32KPCU_cjs = require('./chunk-GW32KPCU.cjs');
6
+ var chunk3YNVWKR2_cjs = require('./chunk-3YNVWKR2.cjs');
7
+ var chunkM4N5GA5Z_cjs = require('./chunk-M4N5GA5Z.cjs');
8
+
9
+ // src/parser/registry/ParseletRegistry.ts
10
+ function bindingPowersOf(parselet) {
11
+ return parselet;
12
+ }
13
+ var ParseletRegistry = class {
14
+ constructor() {
15
+ // String-keyed maps (kept for diagnostics + backwards compat)
16
+ this.prefixParselets = /* @__PURE__ */ new Map();
17
+ this.infixParselets = /* @__PURE__ */ new Map();
18
+ // Integer-keyed maps for parser hot path
19
+ this.prefixById = /* @__PURE__ */ new Map();
20
+ this.infixById = /* @__PURE__ */ new Map();
21
+ }
22
+ /**
23
+ * Register a prefix parselet for `tokenType`.
24
+ *
25
+ * If another parselet is already registered for this token type, it is
26
+ * silently overwritten by default (`Map.set()` semantics), the old
27
+ * parselet is simply unreachable from then on, with no error. This is
28
+ * a real footgun for third-party packages: two packages independently
29
+ * choosing the same custom token type will collide with zero signal
30
+ * about which one "won". Mirrors ResolverRegistry.register()'s and
31
+ * ExpressionEngine.registerPackage()'s existing "warn and replace"
32
+ * pattern for the same class of problem at the resolver-namespace and
33
+ * package-name levels.
34
+ *
35
+ * Note: this warns about registry-level collisions only. It does NOT
36
+ * detect the separate case where `tokenType` is one of PrecedenceParser's
37
+ * Tier-1 fast-path token types (NUMBER, STRING, IDENT, LPAREN, MINUS,
38
+ * PLUS, and the Tier-1 infix operators), those are deliberately kept
39
+ * registered here for introspection/diagnostics even though Tier-1
40
+ * always intercepts them before this registry is consulted (see
41
+ * PrecedenceParser.parsePrefix()'s docs), so warning there would
42
+ * misfire on that intentional, already-documented pattern.
43
+ */
44
+ registerPrefix(tokenType, parselet) {
45
+ const existing = this.prefixParselets.get(tokenType);
46
+ if (existing && existing !== parselet) {
47
+ console.warn(
48
+ `[ParseletRegistry] Prefix parselet for token "${tokenType}" is already registered (category: "${existing.category ?? "unknown"}"). Overwriting with a new parselet (category: "${parselet.category ?? "unknown"}") \u2014 the previous parselet is now unreachable. Two packages may be claiming the same token type.`
49
+ );
50
+ }
51
+ this.prefixParselets.set(tokenType, parselet);
52
+ this.prefixById.set(chunkGW32KPCU_cjs.tokenTypeId(tokenType), parselet);
53
+ }
54
+ /** Register an infix parselet for `tokenType`. See {@link registerPrefix} for the collision-warning behavior this mirrors. */
55
+ registerInfix(tokenType, parselet) {
56
+ const existing = this.infixParselets.get(tokenType);
57
+ if (existing && existing !== parselet) {
58
+ console.warn(
59
+ `[ParseletRegistry] Infix parselet for token "${tokenType}" is already registered (category: "${existing.category ?? "unknown"}"). Overwriting with a new parselet (category: "${parselet.category ?? "unknown"}") \u2014 the previous parselet is now unreachable. Two packages may be claiming the same token type.`
60
+ );
61
+ }
62
+ this.infixParselets.set(tokenType, parselet);
63
+ this.infixById.set(chunkGW32KPCU_cjs.tokenTypeId(tokenType), parselet);
64
+ }
65
+ /** Iterate all registered prefix parselets for diagnostic display. */
66
+ getAllPrefix() {
67
+ const result = [];
68
+ for (const [tokenType, parselet] of this.prefixParselets) {
69
+ result.push({
70
+ tokenType,
71
+ bindingPower: bindingPowersOf(parselet).bindingPower ?? 0,
72
+ category: parselet.category
73
+ });
74
+ }
75
+ return result;
76
+ }
77
+ /** Iterate all registered infix parselets for diagnostic display. */
78
+ getAllInfix() {
79
+ const result = [];
80
+ for (const [tokenType, parselet] of this.infixParselets) {
81
+ result.push({
82
+ tokenType,
83
+ leftBindingPower: bindingPowersOf(parselet).leftBindingPower ?? 0,
84
+ rightBindingPower: bindingPowersOf(parselet).rightBindingPower ?? 0,
85
+ category: parselet.category
86
+ });
87
+ }
88
+ return result;
89
+ }
90
+ /** Number of registered prefix parselets. */
91
+ get prefixCount() {
92
+ return this.prefixParselets.size;
93
+ }
94
+ /** Number of registered infix parselets. */
95
+ get infixCount() {
96
+ return this.infixParselets.size;
97
+ }
98
+ /**
99
+ * Get prefix parselet by string token type OR integer typeId.
100
+ * Fast path for integer IDs (Parser hot path), fallback for strings
101
+ * (diagnostics, error messages, backwards compatibility).
102
+ */
103
+ getPrefix(tokenType) {
104
+ if (typeof tokenType === "number") return this.prefixById.get(tokenType);
105
+ return this.prefixParselets.get(tokenType);
106
+ }
107
+ /**
108
+ * Get infix parselet by string token type OR integer typeId.
109
+ * Fast path for integer IDs (Parser hot path), fallback for strings.
110
+ */
111
+ getInfix(tokenType) {
112
+ if (typeof tokenType === "number") return this.infixById.get(tokenType);
113
+ return this.infixParselets.get(tokenType);
114
+ }
115
+ hasPrefix(tokenType) {
116
+ return this.prefixParselets.has(tokenType);
117
+ }
118
+ hasInfix(tokenType) {
119
+ return this.infixParselets.has(tokenType);
120
+ }
121
+ clear() {
122
+ this.prefixParselets.clear();
123
+ this.infixParselets.clear();
124
+ this.prefixById.clear();
125
+ this.infixById.clear();
126
+ }
127
+ };
128
+ var sharedParseletRegistry = new ParseletRegistry();
129
+
130
+ // src/parser/PrecedenceParser.ts
131
+ var CHAINED_DOT_THOUSANDS_GROUPS = /^\d{1,3}(\.\d{3}){2,}$/;
132
+ var _PrecedenceParser = class _PrecedenceParser {
133
+ constructor(parseletRegistry, maxDepth = 50, localeCode = "en") {
134
+ this.tokens = [];
135
+ this.current = 0;
136
+ this.depth = 0;
137
+ this.currentExpression = "";
138
+ this.registry = parseletRegistry;
139
+ this.maxDepth = maxDepth;
140
+ this.localeCode = localeCode;
141
+ }
142
+ /** Get locale code for NumberParselet to normalize separators */
143
+ getLocaleCode() {
144
+ return this.localeCode;
145
+ }
146
+ /**
147
+ * Set the diagnostic pipeline for parselet matching events.
148
+ * Cleared after each non-cached parse to avoid holding refs.
149
+ */
150
+ setDiagnosticPipeline(pipeline, expression) {
151
+ this.diagnosticPipeline = pipeline;
152
+ this.currentExpression = expression ?? "";
153
+ }
154
+ /**
155
+ * Load tokens for parsing. Identical to Parser.load().
156
+ *
157
+ * @param hasParens - if false, skips the O(n) paren balance scan (~90% of expressions)
158
+ */
159
+ load(tokens, hasParens) {
160
+ if (hasParens === false) {
161
+ this.tokens = tokens;
162
+ this.current = 0;
163
+ this.depth = 0;
164
+ return;
165
+ }
166
+ const LPAREN_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.LPAREN);
167
+ const RPAREN_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.RPAREN);
168
+ let openCount = 0;
169
+ for (let i = 0; i < tokens.length; i++) {
170
+ if (tokens[i].typeId === LPAREN_ID) openCount++;
171
+ else if (tokens[i].typeId === RPAREN_ID) openCount--;
172
+ }
173
+ this.tokens = openCount === 0 ? tokens : this.balanceParens(tokens, openCount);
174
+ this.current = 0;
175
+ this.depth = 0;
176
+ }
177
+ /**
178
+ * Auto-balance unmatched parentheses.
179
+ */
180
+ balanceParens(tokens, openCount) {
181
+ const result = tokens.slice();
182
+ if (openCount > 0) {
183
+ const RPAREN_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.RPAREN);
184
+ for (let i = 0; i < openCount; i++) {
185
+ const lastToken = tokens[tokens.length - 1];
186
+ result.push({
187
+ type: chunkGW32KPCU_cjs.TokenTypes.RPAREN,
188
+ typeId: RPAREN_ID,
189
+ value: ")",
190
+ text: ")",
191
+ offset: lastToken ? lastToken.offset + lastToken.text.length : 0,
192
+ lineBreaks: 0,
193
+ line: lastToken ? lastToken.line : 1,
194
+ col: lastToken ? lastToken.col + lastToken.text.length : 1
195
+ });
196
+ }
197
+ } else if (openCount < 0) {
198
+ const LPAREN_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.LPAREN);
199
+ for (let i = 0; i < -openCount; i++) {
200
+ result.unshift({
201
+ type: chunkGW32KPCU_cjs.TokenTypes.LPAREN,
202
+ typeId: LPAREN_ID,
203
+ value: "(",
204
+ text: "(",
205
+ offset: 0,
206
+ lineBreaks: 0,
207
+ line: 1,
208
+ col: 1
209
+ });
210
+ }
211
+ }
212
+ return result;
213
+ }
214
+ // ═══════════════════════════════════════════════════════════════════════════════
215
+ // Main entry point: precedence climbing parse expression
216
+ // ═══════════════════════════════════════════════════════════════════════════════
217
+ /**
218
+ * Parse a full expression starting at the current token position.
219
+ *
220
+ * @param minBp - minimum binding power (precedence climbing threshold).
221
+ * For left-associative operators, the recursive call uses `bp + 1`.
222
+ * For right-associative operators (^), it uses `bp`.
223
+ * @param _builder - accepted for parselet API compatibility; always uses `this.builder`.
224
+ */
225
+ parseExpression(minBp = 0, _builder) {
226
+ if (_builder) {
227
+ this.builder = _builder;
228
+ }
229
+ this.depth++;
230
+ if (this.depth > this.maxDepth) {
231
+ this.depth--;
232
+ throw chunkM4N5GA5Z_cjs.ErrorFactory.parsing(
233
+ "NESTING_DEPTH_EXCEEDED",
234
+ `Parse nesting depth ${this.depth} exceeds maximum of ${this.maxDepth}`,
235
+ { maxDepth: this.maxDepth, currentDepth: this.depth }
236
+ );
237
+ }
238
+ const token = this.consume();
239
+ if (!token) {
240
+ this.depth--;
241
+ throw chunkM4N5GA5Z_cjs.ErrorFactory.parsing("UNEXPECTED_END", "Unexpected end of expression");
242
+ }
243
+ this.parsePrefix(token);
244
+ const tokens = this.tokens;
245
+ const len = tokens.length;
246
+ const bpTable = _PrecedenceParser.BP_TABLE;
247
+ const registry = this.registry;
248
+ const builder = this.builder;
249
+ let idx = this.current;
250
+ while (idx < len) {
251
+ const lookahead = tokens[idx];
252
+ if (!lookahead) break;
253
+ const bp = bpTable[lookahead.typeId];
254
+ if (bp > 0) {
255
+ if (bp <= minBp) break;
256
+ if (this.diagnosticPipeline) {
257
+ const infixParselet = registry.getInfix(lookahead.typeId);
258
+ if (infixParselet) {
259
+ this.fireParseletMatched(infixParselet, lookahead, false, bp);
260
+ }
261
+ }
262
+ this.current = ++idx;
263
+ const typeId = lookahead.typeId;
264
+ if (typeId === _PrecedenceParser.PERCENT_ID) {
265
+ builder.emitOpcode(10 /* PUSH_NUMBER */);
266
+ builder.emitNumber(100);
267
+ builder.emitOpcode(23 /* DIV */);
268
+ } else if (typeId === _PrecedenceParser.CARET_ID && this.tryEmitMatrixCaretOp(builder)) ; else {
269
+ const rightBp = typeId === _PrecedenceParser.CARET_ID ? bp : bp + 1;
270
+ this.parseExpression(rightBp, builder);
271
+ builder.emitOpcode(_PrecedenceParser.INFIX_OPCODE[typeId]);
272
+ }
273
+ } else {
274
+ const infixParselet = registry.getInfix(lookahead.typeId);
275
+ if (!infixParselet) break;
276
+ if (infixParselet.bindingPower <= minBp) break;
277
+ this.current = ++idx;
278
+ if (this.diagnosticPipeline) {
279
+ this.fireParseletMatched(infixParselet, lookahead, false, infixParselet.bindingPower);
280
+ }
281
+ infixParselet.parse(this, token, lookahead, builder);
282
+ }
283
+ idx = this.current;
284
+ }
285
+ this.current = idx;
286
+ this.depth--;
287
+ }
288
+ // ═══════════════════════════════════════════════════════════════════════════════
289
+ // Prefix dispatch: inline switch for built-ins, parselet registry for plugins
290
+ // ═══════════════════════════════════════════════════════════════════════════════
291
+ /**
292
+ * Parse a prefix token. Built-in tokens (NUMBER, IDENT, LPAREN, etc.) are
293
+ * handled inline with zero registry lookup. Everything else falls through
294
+ * to the parselet registry (Tier 2).
295
+ */
296
+ parsePrefix(token) {
297
+ const builder = this.builder;
298
+ const typeId = token.typeId;
299
+ if (this.diagnosticPipeline) {
300
+ const parselet = this.registry.getPrefix(typeId);
301
+ if (parselet) {
302
+ this.fireParseletMatched(parselet, token, true);
303
+ }
304
+ }
305
+ switch (typeId) {
306
+ // ── Numeric literals ──────────────────────────────────────────────────
307
+ case _PrecedenceParser.NUMBER_ID: {
308
+ let v;
309
+ const raw = token.value;
310
+ if (raw.startsWith("0x") || raw.startsWith("0X")) {
311
+ v = parseInt(raw, 16);
312
+ if (Number.isNaN(v)) {
313
+ throw chunkM4N5GA5Z_cjs.ErrorFactory.parsing("INVALID_NUMBER_LITERAL", `Invalid hex literal: "${raw}"`, { raw });
314
+ }
315
+ } else if (raw.startsWith("0b") || raw.startsWith("0B")) {
316
+ v = parseInt(raw.slice(2), 2);
317
+ if (Number.isNaN(v)) {
318
+ throw chunkM4N5GA5Z_cjs.ErrorFactory.parsing("INVALID_NUMBER_LITERAL", `Invalid binary literal: "${raw}"`, { raw });
319
+ }
320
+ } else if (raw.startsWith("0o") || raw.startsWith("0O")) {
321
+ v = parseInt(raw.slice(2), 8);
322
+ if (Number.isNaN(v)) {
323
+ throw chunkM4N5GA5Z_cjs.ErrorFactory.parsing("INVALID_NUMBER_LITERAL", `Invalid octal literal: "${raw}"`, { raw });
324
+ }
325
+ } else if (CHAINED_DOT_THOUSANDS_GROUPS.test(raw)) {
326
+ v = parseFloat(raw.split(".").join(""));
327
+ } else {
328
+ const locale = chunk3YNVWKR2_cjs.getLocale(this.localeCode);
329
+ const decimalSep = locale.display.decimalSeparator;
330
+ const thousandsSep = locale.display.thousandsSeparator;
331
+ let normalized = raw;
332
+ if (thousandsSep) {
333
+ normalized = normalized.split(thousandsSep).join("");
334
+ }
335
+ if (decimalSep && decimalSep !== ".") {
336
+ normalized = normalized.replace(decimalSep, ".");
337
+ }
338
+ v = parseFloat(normalized);
339
+ }
340
+ builder.emitOpcode(10 /* PUSH_NUMBER */);
341
+ builder.emitNumber(v);
342
+ return;
343
+ }
344
+ case _PrecedenceParser.BIGINT_ID: {
345
+ let raw = token.value;
346
+ if (raw.endsWith("n")) raw = raw.slice(0, -1);
347
+ builder.emitOpcode(11 /* PUSH_BIGINT */);
348
+ builder.emitString(raw);
349
+ return;
350
+ }
351
+ case _PrecedenceParser.STRING_ID: {
352
+ builder.emitOpcode(13 /* PUSH_STRING */);
353
+ builder.emitString(token.value);
354
+ return;
355
+ }
356
+ // ── Identifiers (variables) ────────────────────────────────────────────
357
+ case _PrecedenceParser.IDENT_ID: {
358
+ if (this.peek()?.typeId === _PrecedenceParser.LPAREN_ID) {
359
+ this.parseUserFunctionDefOrCall(token, builder);
360
+ return;
361
+ }
362
+ builder.emitOpcode(60 /* LOAD_VAR */);
363
+ builder.emitString(token.value);
364
+ return;
365
+ }
366
+ // ── Grouping / bare-tuple vector literal ─────────────────────────────────
367
+ // `(expr)` groups for precedence; `(x, y[, z[, w]])` is the bare-tuple
368
+ // vector literal documented as an alternative to vec2/vec3/vec4(...)
369
+ // (wiki: Arithmetic/Vector). This Tier-1 case is what actually runs for
370
+ // every LPAREN in production parsing, GroupParselet.ts mirrors this
371
+ // logic for registry-introspection/diagnostic-listing purposes, but a
372
+ // package can never override LPAREN's dispatch here (Tier 1 always
373
+ // wins over the ParseletRegistry fallback below), so both must be kept
374
+ // in sync by hand.
375
+ case _PrecedenceParser.LPAREN_ID: {
376
+ this.parseExpression(0, builder);
377
+ let count = 1;
378
+ while (this.match(chunkGW32KPCU_cjs.TokenTypes.COMMA)) {
379
+ this.parseExpression(0, builder);
380
+ count++;
381
+ }
382
+ this.consume(chunkGW32KPCU_cjs.TokenTypes.RPAREN);
383
+ if (count > 1) {
384
+ builder.emitOpcode(152 /* MAT_NEW */);
385
+ builder.emitIndex(1);
386
+ builder.emitIndex(count);
387
+ }
388
+ return;
389
+ }
390
+ // ── Unary operators ───────────────────────────────────────────────────
391
+ case _PrecedenceParser.MINUS_ID: {
392
+ this.parseExpression(chunkC4XZV6E7_cjs.BindingPower.Prefix, builder);
393
+ builder.emitOpcode(26 /* NEG */);
394
+ return;
395
+ }
396
+ case _PrecedenceParser.PLUS_ID: {
397
+ this.parseExpression(chunkC4XZV6E7_cjs.BindingPower.Prefix, builder);
398
+ builder.emitOpcode(27 /* POS */);
399
+ return;
400
+ }
401
+ // ── Keyword constants ─────────────────────────────────────────────────
402
+ case _PrecedenceParser.KEYWORD_ID: }
403
+ const prefixParselet = this.registry.getPrefix(typeId);
404
+ if (!prefixParselet) {
405
+ throw chunkM4N5GA5Z_cjs.ErrorFactory.parsing(
406
+ "NO_PREFIX_PARSELET",
407
+ `No prefix parselet found for token: ${token.type} ("${token.value}")`,
408
+ { tokenType: token.type, tokenValue: token.value }
409
+ );
410
+ }
411
+ prefixParselet.parse(this, token, builder);
412
+ }
413
+ /**
414
+ * After a `^` token (already consumed by the Tier-1 infix loop above),
415
+ * checks {@link CARET_SUFFIX_RULES} in order for a shape that means
416
+ * something other than ordinary exponentiation: `^T` (transpose) and `^-1`
417
+ * (matrix inverse, LITERALLY the integer exponent `-1`; `^-2`, `^-1.5`
418
+ * etc. still mean ordinary exponentiation). On a match, the rule's `emit`
419
+ * consumes that shape's own tokens and this returns `true`. On no match,
420
+ * consumes NOTHING, returning `false` so the caller falls through to
421
+ * ordinary `EXP` parsing.
422
+ *
423
+ * Every rule dispatches purely on SHAPE, never on operand type (unknowable
424
+ * at parse time): `inv()`'s own handler (`VMBuiltins.ts` index 65) returns
425
+ * `1/x` for a plain Number, byte-identical to what `Math.pow(x, -1)`
426
+ * already computed for `x^-1` before this feature existed, and a real
427
+ * matrix inverse for a Matrix, so `5^-1` still means exactly what it always
428
+ * has; only a Matrix operand actually inverts.
429
+ *
430
+ * Adding a future `^`-suffix shape is a new table entry here, not a new
431
+ * if-block. See the "Tier-1 shape-exception" pattern write-up above for
432
+ * why this table can't instead be a package-registered parselet.
433
+ */
434
+ tryEmitMatrixCaretOp(builder) {
435
+ for (const rule of _PrecedenceParser.CARET_SUFFIX_RULES) {
436
+ if (rule.matches(this)) {
437
+ rule.emit(this, builder);
438
+ return true;
439
+ }
440
+ }
441
+ return false;
442
+ }
443
+ // ═══════════════════════════════════════════════════════════════════════════════
444
+ // User-defined, parameterized, reusable functions (f(x) = 2*x + 1, then f(5))
445
+ // ═══════════════════════════════════════════════════════════════════════════════
446
+ /**
447
+ * From an LPAREN token index, scan forward tracking paren depth and
448
+ * return the index of the matching RPAREN, or `null` if the parens never
449
+ * balance before the token stream ends. No emission, no position
450
+ * advance. Same class of technique as {@link balanceParens}'s own
451
+ * pre-scan, just exposed mid-parse instead of only at `load()` time.
452
+ * `openIdx` must point AT the LPAREN itself.
453
+ */
454
+ findMatchingRParen(openIdx) {
455
+ let depth = 0;
456
+ for (let i = openIdx; i < this.tokens.length; i++) {
457
+ const t = this.tokens[i];
458
+ if (t.typeId === _PrecedenceParser.LPAREN_ID) depth++;
459
+ else if (t.typeId === _PrecedenceParser.RPAREN_ID) {
460
+ depth--;
461
+ if (depth === 0) return i;
462
+ }
463
+ }
464
+ return null;
465
+ }
466
+ /**
467
+ * Disambiguates a bare `IDENT` immediately followed by `(` between three
468
+ * things, using ONLY a bracket-depth scan (no backtracking, nothing is
469
+ * consumed until the shape is known):
470
+ * - `f(x) = expr`, a DEFINITION: the matching `)` is followed by `=`.
471
+ * - `f(5)`, a CALL to a (possibly not-yet-defined) function: anything
472
+ * else. This was never valid syntax before this feature (a bare
473
+ * `IDENT` immediately before `(` has no pre-existing "plain variable
474
+ * read + separately grouped `(...)`" meaning to preserve, confirmed
475
+ * via `BuiltinNormalizerRules.ts`'s `implicitMultiplyRule()`, which
476
+ * only inserts an implicit `*` for `NUMBER/RPAREN` immediately before
477
+ * `IDENT/LPAREN`, never for a bare `IDENT` immediately before
478
+ * `LPAREN`). Always commits to a CALL; an unregistered name produces a
479
+ * clear `UNDEFINED_FUNCTION` error at VM-execution time, the same
480
+ * forward-reference philosophy `LOAD_VAR`/`UNDEFINED_VARIABLE` already
481
+ * uses, rather than any parse-time registry lookup.
482
+ * If the parens never balance, this falls through to the ordinary
483
+ * `LOAD_VAR` path (a malformed expression surfaces its own parse error
484
+ * shortly after, from the normal expression grammar).
485
+ */
486
+ parseUserFunctionDefOrCall(nameToken, builder) {
487
+ const closeIdx = this.findMatchingRParen(this.current);
488
+ if (closeIdx === null) {
489
+ builder.emitOpcode(60 /* LOAD_VAR */);
490
+ builder.emitString(nameToken.value);
491
+ return;
492
+ }
493
+ const afterClose = this.tokens[closeIdx + 1];
494
+ if (afterClose?.type === chunkGW32KPCU_cjs.TokenTypes.EQUALS) {
495
+ this.parseUserFunctionDefinition(nameToken, builder);
496
+ } else {
497
+ this.parseUserFunctionCall(nameToken, builder);
498
+ }
499
+ }
500
+ /**
501
+ * A parameter name, accepted as either `IDENT` or `UNIT`, matches this
502
+ * codebase's established `:name = value` variable-name policy
503
+ * (`VariableParselet.ts` explicitly accepts `UNIT`-typed tokens too, e.g.
504
+ * `:b = 5` for the "b" bits unit) since common short parameter names
505
+ * like `h`/`l`/`b`/`t`/`s`/`m` collide with real unit abbreviations
506
+ * (hour, liter, bits, ton, second, meter, ...) and lex as `UNIT`, not
507
+ * `IDENT`.
508
+ */
509
+ consumeParamName() {
510
+ const token = this.peek();
511
+ if (token?.type === chunkGW32KPCU_cjs.TokenTypes.IDENT || token?.type === chunkGW32KPCU_cjs.TokenTypes.UNIT) {
512
+ this.consume();
513
+ return token.value;
514
+ }
515
+ throw chunkM4N5GA5Z_cjs.ErrorFactory.parsing(
516
+ "USER_FUNCTION_INVALID_PARAM_NAME",
517
+ `Expected a parameter name but got "${token?.type ?? "end of input"}"${token ? ` ("${token.value}")` : ""}`,
518
+ { actualType: token?.type }
519
+ );
520
+ }
521
+ parseUserFunctionDefinition(nameToken, builder) {
522
+ this.consume(chunkGW32KPCU_cjs.TokenTypes.LPAREN);
523
+ const params = [];
524
+ if (this.peek()?.type !== chunkGW32KPCU_cjs.TokenTypes.RPAREN) {
525
+ params.push(this.consumeParamName());
526
+ while (this.match(chunkGW32KPCU_cjs.TokenTypes.COMMA)) {
527
+ params.push(this.consumeParamName());
528
+ }
529
+ }
530
+ this.consume(chunkGW32KPCU_cjs.TokenTypes.RPAREN);
531
+ this.consume(chunkGW32KPCU_cjs.TokenTypes.EQUALS);
532
+ if (params.length === 0) {
533
+ throw chunkM4N5GA5Z_cjs.ErrorFactory.parsing(
534
+ "USER_FUNCTION_NO_PARAMS",
535
+ `"${nameToken.value}()" has no parameters -- user-defined functions need at least one (a zero-argument definition is indistinguishable from a plain function CALL with no args, which this grammar doesn't otherwise support)`,
536
+ { name: nameToken.value }
537
+ );
538
+ }
539
+ const bodyBuilder = new chunkC4XZV6E7_cjs.BytecodeBuilder();
540
+ this.parseExpression(chunkC4XZV6E7_cjs.BindingPower.Lowest, bodyBuilder);
541
+ this.setBuilder(builder);
542
+ const bodyProgram = bodyBuilder.build();
543
+ if (bodyProgram.hasAsync) {
544
+ throw chunkM4N5GA5Z_cjs.ErrorFactory.parsing(
545
+ "FUNCTION_BODY_MUST_BE_SYNCHRONOUS",
546
+ `"${nameToken.value}(...)"'s body calls an async operation (weather, stocks, currency, ...) \u2014 user-defined function bodies must be synchronous`,
547
+ { name: nameToken.value }
548
+ );
549
+ }
550
+ const bodyIdx = builder.emitUserFunctionBody(nameToken.value, params, bodyProgram);
551
+ builder.emitOpcode(150 /* DEFINE_USER_FUNCTION */);
552
+ builder.emitIndex(bodyIdx);
553
+ builder.emitOpcode(13 /* PUSH_STRING */);
554
+ builder.emitString(`${nameToken.value}(${params.join(", ")}) defined`);
555
+ }
556
+ parseUserFunctionCall(nameToken, builder) {
557
+ this.consume(chunkGW32KPCU_cjs.TokenTypes.LPAREN);
558
+ let argCount = 0;
559
+ if (this.peek()?.type !== chunkGW32KPCU_cjs.TokenTypes.RPAREN) {
560
+ this.parseExpression(chunkC4XZV6E7_cjs.BindingPower.Lowest, builder);
561
+ argCount++;
562
+ while (this.match(chunkGW32KPCU_cjs.TokenTypes.COMMA)) {
563
+ this.parseExpression(chunkC4XZV6E7_cjs.BindingPower.Lowest, builder);
564
+ argCount++;
565
+ }
566
+ }
567
+ this.consume(chunkGW32KPCU_cjs.TokenTypes.RPAREN);
568
+ builder.emitOpcode(151 /* CALL_USER_FUNCTION */);
569
+ builder.emitString(nameToken.value);
570
+ builder.emitByte(argCount);
571
+ }
572
+ // ═══════════════════════════════════════════════════════════════════════════════
573
+ // Token stream navigation (identical API to Parser)
574
+ // ═══════════════════════════════════════════════════════════════════════════════
575
+ consume(expectedType) {
576
+ const token = this.tokens[this.current];
577
+ if (!token) {
578
+ throw chunkM4N5GA5Z_cjs.ErrorFactory.parsing(
579
+ "UNEXPECTED_END_OF_INPUT",
580
+ "Unexpected end of input"
581
+ );
582
+ }
583
+ if (expectedType !== void 0) {
584
+ const expectedId = chunkGW32KPCU_cjs.tokenTypeId(expectedType);
585
+ if (token.typeId !== expectedId) {
586
+ throw chunkM4N5GA5Z_cjs.ErrorFactory.parsing(
587
+ "UNEXPECTED_TOKEN_TYPE",
588
+ `Expected token type "${expectedType}" but got "${token.type}" ("${token.value}")`,
589
+ { expectedType, actualType: token.type, actualValue: token.value }
590
+ );
591
+ }
592
+ }
593
+ this.current++;
594
+ return token;
595
+ }
596
+ match(expectedType) {
597
+ const token = this.peek();
598
+ if (token && token.typeId === chunkGW32KPCU_cjs.tokenTypeId(expectedType)) {
599
+ this.advance();
600
+ return true;
601
+ }
602
+ return false;
603
+ }
604
+ peek() {
605
+ return this.tokens[this.current];
606
+ }
607
+ /**
608
+ * Read-only lookahead `offset` tokens past the current position, without
609
+ * consuming anything, `peekAt(0)` is equivalent to {@link peek}.
610
+ * `this.tokens` is a plain in-memory array (not a stream), so this is a
611
+ * simple, safe index read; no rewind/checkpoint mechanism is needed since
612
+ * nothing is consumed.
613
+ */
614
+ peekAt(offset) {
615
+ return this.tokens[this.current + offset];
616
+ }
617
+ previous() {
618
+ return this.current > 0 ? this.tokens[this.current - 1] : void 0;
619
+ }
620
+ advance() {
621
+ this.current++;
622
+ }
623
+ // ═══════════════════════════════════════════════════════════════════════════════
624
+ // Builder access, set before parse, read by inline prefix handlers
625
+ // ═══════════════════════════════════════════════════════════════════════════════
626
+ /** Set the builder to use for the current parse. Called by ExpressionEngine. */
627
+ setBuilder(builder) {
628
+ this.builder = builder;
629
+ }
630
+ // ═══════════════════════════════════════════════════════════════════════════════
631
+ // Diagnostics
632
+ // ═══════════════════════════════════════════════════════════════════════════════
633
+ fireParseletMatched(parselet, token, isPrefix, bindingPower) {
634
+ const pipeline = this.diagnosticPipeline;
635
+ const event = {
636
+ type: chunk47LRVGOT_cjs.DiagnosticEventType.ParseletMatched,
637
+ elapsedNs: 0,
638
+ expression: this.currentExpression,
639
+ tokenType: token.type,
640
+ tokenValue: token.value,
641
+ parseletCategory: parselet.category,
642
+ parseletType: parselet.constructor?.name ?? "unknown",
643
+ isPrefix,
644
+ bindingPower,
645
+ tokenOffset: token.offset || 0
646
+ };
647
+ pipeline.fireParseletMatched(event);
648
+ }
649
+ };
650
+ /**
651
+ * Static binding power table, built once at module load, shared across all instances.
652
+ * Index = tokenTypeId, value = binding power (0 = not a built-in infix).
653
+ */
654
+ _PrecedenceParser.BP_TABLE = chunkC4XZV6E7_cjs.buildBindingPowerTable();
655
+ // ── Pre-computed token type IDs for inline dispatch ────────────────────────
656
+ // Prefix built-ins
657
+ _PrecedenceParser.NUMBER_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.NUMBER);
658
+ _PrecedenceParser.BIGINT_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.BIGINT);
659
+ _PrecedenceParser.STRING_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.STRING);
660
+ _PrecedenceParser.IDENT_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.IDENT);
661
+ _PrecedenceParser.LPAREN_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.LPAREN);
662
+ _PrecedenceParser.RPAREN_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.RPAREN);
663
+ _PrecedenceParser.MINUS_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.MINUS);
664
+ _PrecedenceParser.PLUS_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.PLUS);
665
+ _PrecedenceParser.KEYWORD_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.KEYWORD);
666
+ // Infix built-ins (Tier 1, full inline emission)
667
+ _PrecedenceParser.STAR_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.STAR);
668
+ _PrecedenceParser.SLASH_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.SLASH);
669
+ _PrecedenceParser.MOD_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.MOD);
670
+ _PrecedenceParser.CARET_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.CARET);
671
+ _PrecedenceParser.LSHIFT_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.LSHIFT);
672
+ _PrecedenceParser.RSHIFT_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.RSHIFT);
673
+ _PrecedenceParser.BIT_AND_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.BIT_AND);
674
+ _PrecedenceParser.BIT_OR_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.BIT_OR);
675
+ _PrecedenceParser.BIT_XOR_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.BIT_XOR);
676
+ _PrecedenceParser.PERCENT_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.PERCENT);
677
+ _PrecedenceParser.OF_ID = chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.OF);
678
+ /**
679
+ * Inline opcode map for Tier 1 infix operators.
680
+ * tokenTypeId → OpCode. PERCENT and CARET are handled specially (not in this map).
681
+ */
682
+ _PrecedenceParser.INFIX_OPCODE = {
683
+ [chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.PLUS)]: 20 /* ADD */,
684
+ [chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.MINUS)]: 21 /* SUB */,
685
+ [chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.STAR)]: 22 /* MUL */,
686
+ [chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.SLASH)]: 23 /* DIV */,
687
+ [chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.MOD)]: 24 /* MOD */,
688
+ [chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.CARET)]: 25 /* EXP */,
689
+ [chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.LSHIFT)]: 30 /* LSHIFT */,
690
+ [chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.RSHIFT)]: 31 /* RSHIFT */,
691
+ [chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.BIT_AND)]: 33 /* BIT_AND */,
692
+ [chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.BIT_OR)]: 34 /* BIT_OR */,
693
+ [chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.BIT_XOR)]: 35 /* BIT_XOR */,
694
+ [chunkGW32KPCU_cjs.tokenTypeId(chunkGW32KPCU_cjs.TokenTypes.OF)]: 22 /* MUL */
695
+ };
696
+ // ═══════════════════════════════════════════════════════════════════════════════
697
+ // The "Tier-1 shape-exception" pattern
698
+ // ═══════════════════════════════════════════════════════════════════════════════
699
+ //
700
+ // Tier 1 exists purely for performance, avoid a Map lookup + parselet call
701
+ // on ~95% of tokens (see this file's own module doc comment above). A
702
+ // recurring consequence: any grammar shape tied to a Tier-1 token type can
703
+ // ONLY be implemented by hand-editing this switch, since a package-
704
+ // registered ParseletRegistry parselet for that same token type would
705
+ // simply never run in production (Tier 1 always wins over the registry
706
+ // fallback). Five confirmed instances of this tension exist in this file
707
+ // (plus one that had to move OUTSIDE it entirely):
708
+ // 1. NUMBER_ID, the full locale-aware number-literal parsing (hex/
709
+ // binary/octal, chained-dot thousands grouping, decimal-separator
710
+ // normalization) is inlined in parsePrefix() above; NumberParselet.ts's
711
+ // own copy is dead code for real evaluation, kept registered only for
712
+ // the "matched parselets" diagnostic view.
713
+ // 2. IDENT_ID, parseUserFunctionDefOrCall's lookahead (below) disambig-
714
+ // uates a function DEFINITION from a CALL from a plain variable load.
715
+ // 3. LPAREN_ID, the bare-tuple vector-literal sugar ("(x,y[,z[,w]])" ->
716
+ // MAT_NEW) is inlined in parsePrefix() above; GroupParselet.ts mirrors
717
+ // it for introspection only and must be kept in sync by hand.
718
+ // 4. CARET_ID, the transpose/inverse suffix table just below.
719
+ // 5. PLUS_ID, the locale word "and" lexes as PLUS (Tier-1, fixed Sum
720
+ // binding power), so a registry parselet can never intercept it the
721
+ // way LogicalParselet.ts intercepts "or"/&&/||; unlike the other four,
722
+ // there's no SHAPE to special-case on here (the token itself IS the
723
+ // operator), so the workaround lives entirely outside this file, as a
724
+ // runtime Boolean/Boolean type-check inside vm/VM.ts's OpCode.ADD
725
+ // handler instead.
726
+ //
727
+ // Deliberate non-goal: none of this is exposed as an IEnginePackage
728
+ // extension point (unlike prefixParselets/infixParselets). Letting
729
+ // third-party packages register their own Tier-1 shape-matchers would put
730
+ // per-package matcher iteration on a genuinely hot path (every CARET/
731
+ // NUMBER/IDENT/LPAREN/PLUS token, matched or not), a materially bigger
732
+ // separate product decision than "make this one table more concise," and
733
+ // not one this pattern write-up makes.
734
+ /**
735
+ * A single `^`-suffix shape: `matches` peeks ahead (consuming nothing) to
736
+ * check whether this shape starts at the current position; `emit` is only
737
+ * called immediately after `matches` returned true for that SAME position,
738
+ * and is responsible for consuming that shape's own trailing tokens and
739
+ * emitting its bytecode.
740
+ */
741
+ _PrecedenceParser.CARET_SUFFIX_RULES = [
742
+ {
743
+ name: "transpose (^T)",
744
+ matches: (p) => {
745
+ const next = p.peek();
746
+ return next?.type === chunkGW32KPCU_cjs.TokenTypes.IDENT && next.value === "T";
747
+ },
748
+ emit: (p, builder) => {
749
+ p.advance();
750
+ builder.emitOpcode(51 /* CALL_BUILTIN */);
751
+ builder.emitIndex(63);
752
+ builder.emitIndex(1);
753
+ }
754
+ },
755
+ {
756
+ name: "inverse (^-1)",
757
+ matches: (p) => {
758
+ const next = p.peek();
759
+ if (next?.typeId !== _PrecedenceParser.MINUS_ID) return false;
760
+ const afterMinus = p.peekAt(1);
761
+ return afterMinus?.type === chunkGW32KPCU_cjs.TokenTypes.NUMBER && afterMinus.value === "1";
762
+ },
763
+ emit: (p, builder) => {
764
+ p.advance();
765
+ p.advance();
766
+ builder.emitOpcode(51 /* CALL_BUILTIN */);
767
+ builder.emitIndex(65);
768
+ builder.emitIndex(1);
769
+ }
770
+ }
771
+ ];
772
+ var PrecedenceParser = _PrecedenceParser;
773
+
774
+ exports.ParseletRegistry = ParseletRegistry;
775
+ exports.PrecedenceParser = PrecedenceParser;
776
+ exports.sharedParseletRegistry = sharedParseletRegistry;
777
+ //# sourceMappingURL=chunk-NMCRQP3Z.cjs.map
778
+ //# sourceMappingURL=chunk-NMCRQP3Z.cjs.map