solve-engine 1.0.0-beta.0 → 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) 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-BVAR5J2F.js +257 -0
  56. package/dist/chunk-BVAR5J2F.js.map +1 -0
  57. package/dist/chunk-C4XZV6E7.cjs +269 -0
  58. package/dist/chunk-C4XZV6E7.cjs.map +1 -0
  59. package/dist/chunk-CCJPSHGI.cjs +40 -0
  60. package/dist/chunk-CCJPSHGI.cjs.map +1 -0
  61. package/dist/chunk-CLL7RUQV.cjs +316 -0
  62. package/dist/chunk-CLL7RUQV.cjs.map +1 -0
  63. package/dist/chunk-DM3LMRBC.js +329 -0
  64. package/dist/chunk-DM3LMRBC.js.map +1 -0
  65. package/dist/chunk-DUEZFTK2.js +38 -0
  66. package/dist/chunk-DUEZFTK2.js.map +1 -0
  67. package/dist/chunk-EBSPLUW4.cjs +489 -0
  68. package/dist/chunk-EBSPLUW4.cjs.map +1 -0
  69. package/dist/chunk-EHAHVROS.cjs +261 -0
  70. package/dist/chunk-EHAHVROS.cjs.map +1 -0
  71. package/dist/chunk-EPOXXJBK.js +96 -0
  72. package/dist/chunk-EPOXXJBK.js.map +1 -0
  73. package/dist/chunk-FEAIOR7N.cjs +91 -0
  74. package/dist/chunk-FEAIOR7N.cjs.map +1 -0
  75. package/dist/chunk-G535KJEG.js +312 -0
  76. package/dist/chunk-G535KJEG.js.map +1 -0
  77. package/dist/chunk-GCM5JHMX.js +88 -0
  78. package/dist/chunk-GCM5JHMX.js.map +1 -0
  79. package/dist/chunk-GOLDJNMZ.js +368 -0
  80. package/dist/chunk-GOLDJNMZ.js.map +1 -0
  81. package/dist/chunk-GW32KPCU.cjs +360 -0
  82. package/dist/chunk-GW32KPCU.cjs.map +1 -0
  83. package/dist/chunk-HO2CDZRC.js +5508 -0
  84. package/dist/chunk-HO2CDZRC.js.map +1 -0
  85. package/dist/chunk-HTXVVJRA.cjs +1549 -0
  86. package/dist/chunk-HTXVVJRA.cjs.map +1 -0
  87. package/dist/chunk-HWSZJQCI.js +311 -0
  88. package/dist/chunk-HWSZJQCI.js.map +1 -0
  89. package/dist/chunk-IF532O7C.js +101 -0
  90. package/dist/chunk-IF532O7C.js.map +1 -0
  91. package/dist/chunk-J73SJHR3.cjs +2415 -0
  92. package/dist/chunk-J73SJHR3.cjs.map +1 -0
  93. package/dist/chunk-KVILKGMS.js +228 -0
  94. package/dist/chunk-KVILKGMS.js.map +1 -0
  95. package/dist/chunk-LIPPNDBE.js +258 -0
  96. package/dist/chunk-LIPPNDBE.js.map +1 -0
  97. package/dist/chunk-M4N5GA5Z.cjs +309 -0
  98. package/dist/chunk-M4N5GA5Z.cjs.map +1 -0
  99. package/dist/chunk-MZOVP3WI.cjs +96 -0
  100. package/dist/chunk-MZOVP3WI.cjs.map +1 -0
  101. package/dist/chunk-N5YFR4UP.cjs +10 -0
  102. package/dist/chunk-N5YFR4UP.cjs.map +1 -0
  103. package/dist/chunk-NGBBNL4K.cjs +4 -0
  104. package/dist/chunk-NGBBNL4K.cjs.map +1 -0
  105. package/dist/chunk-NH2O2AUR.js +146 -0
  106. package/dist/chunk-NH2O2AUR.js.map +1 -0
  107. package/dist/chunk-NLNDMWZC.js +31 -0
  108. package/dist/chunk-NLNDMWZC.js.map +1 -0
  109. package/dist/chunk-NMCRQP3Z.cjs +778 -0
  110. package/dist/chunk-NMCRQP3Z.cjs.map +1 -0
  111. package/dist/chunk-NMD5VRN4.cjs +1327 -0
  112. package/dist/chunk-NMD5VRN4.cjs.map +1 -0
  113. package/dist/chunk-OC6LTXYS.cjs +286 -0
  114. package/dist/chunk-OC6LTXYS.cjs.map +1 -0
  115. package/dist/chunk-OT6OJY7C.cjs +114 -0
  116. package/dist/chunk-OT6OJY7C.cjs.map +1 -0
  117. package/dist/chunk-PEWZMGH7.cjs +5522 -0
  118. package/dist/chunk-PEWZMGH7.cjs.map +1 -0
  119. package/dist/chunk-PFSDGGYL.js +8 -0
  120. package/dist/chunk-PFSDGGYL.js.map +1 -0
  121. package/dist/chunk-QNJ4ACRT.cjs +155 -0
  122. package/dist/chunk-QNJ4ACRT.cjs.map +1 -0
  123. package/dist/chunk-QWY3VEZN.js +1637 -0
  124. package/dist/chunk-QWY3VEZN.js.map +1 -0
  125. package/dist/chunk-RFYD5TJE.js +111 -0
  126. package/dist/chunk-RFYD5TJE.js.map +1 -0
  127. package/dist/chunk-RIN643A3.js +354 -0
  128. package/dist/chunk-RIN643A3.js.map +1 -0
  129. package/dist/chunk-RZCWSXTA.cjs +5122 -0
  130. package/dist/chunk-RZCWSXTA.cjs.map +1 -0
  131. package/dist/chunk-SDGRK7EP.js +774 -0
  132. package/dist/chunk-SDGRK7EP.js.map +1 -0
  133. package/dist/chunk-VEKIWQ3F.cjs +39 -0
  134. package/dist/chunk-VEKIWQ3F.cjs.map +1 -0
  135. package/dist/chunk-W44QGY5J.cjs +172 -0
  136. package/dist/chunk-W44QGY5J.cjs.map +1 -0
  137. package/dist/chunk-WQTTOGXC.cjs +99 -0
  138. package/dist/chunk-WQTTOGXC.cjs.map +1 -0
  139. package/dist/chunk-X6K3HUOY.cjs +86 -0
  140. package/dist/chunk-X6K3HUOY.cjs.map +1 -0
  141. package/dist/chunk-XJCMXB2E.cjs +333 -0
  142. package/dist/chunk-XJCMXB2E.cjs.map +1 -0
  143. package/dist/chunk-XVWCOTR6.js +1324 -0
  144. package/dist/chunk-XVWCOTR6.js.map +1 -0
  145. package/dist/chunk-Z2XP767T.cjs +35 -0
  146. package/dist/chunk-Z2XP767T.cjs.map +1 -0
  147. package/dist/chunk-Z4X2RWOF.js +37 -0
  148. package/dist/chunk-Z4X2RWOF.js.map +1 -0
  149. package/dist/chunk-ZP3UY6ZX.js +167 -0
  150. package/dist/chunk-ZP3UY6ZX.js.map +1 -0
  151. package/dist/constants.cjs +21 -0
  152. package/dist/constants.cjs.map +1 -0
  153. package/dist/constants.d.cts +12 -0
  154. package/dist/constants.d.ts +12 -0
  155. package/dist/constants.js +4 -0
  156. package/dist/constants.js.map +1 -0
  157. package/dist/engine.cjs +78 -0
  158. package/dist/engine.cjs.map +1 -0
  159. package/dist/engine.d.cts +587 -0
  160. package/dist/engine.d.ts +587 -0
  161. package/dist/engine.js +33 -0
  162. package/dist/engine.js.map +1 -0
  163. package/dist/errors.cjs +80 -0
  164. package/dist/errors.cjs.map +1 -0
  165. package/dist/errors.d.cts +95 -0
  166. package/dist/errors.d.ts +95 -0
  167. package/dist/errors.js +3 -0
  168. package/dist/errors.js.map +1 -0
  169. package/dist/format.cjs +170 -0
  170. package/dist/format.cjs.map +1 -0
  171. package/dist/format.d.cts +51 -0
  172. package/dist/format.d.ts +51 -0
  173. package/dist/format.js +167 -0
  174. package/dist/format.js.map +1 -0
  175. package/dist/index.cjs +96 -0
  176. package/dist/index.cjs.map +1 -0
  177. package/dist/index.d.cts +152 -0
  178. package/dist/index.d.ts +152 -0
  179. package/dist/index.js +74 -0
  180. package/dist/index.js.map +1 -0
  181. package/dist/language.cjs +307 -0
  182. package/dist/language.cjs.map +1 -0
  183. package/dist/language.d.cts +110 -0
  184. package/dist/language.d.ts +110 -0
  185. package/dist/language.js +286 -0
  186. package/dist/language.js.map +1 -0
  187. package/dist/lexer.cjs +63 -0
  188. package/dist/lexer.cjs.map +1 -0
  189. package/dist/lexer.d.cts +56 -0
  190. package/dist/lexer.d.ts +56 -0
  191. package/dist/lexer.js +10 -0
  192. package/dist/lexer.js.map +1 -0
  193. package/dist/normalizer.cjs +39 -0
  194. package/dist/normalizer.cjs.map +1 -0
  195. package/dist/normalizer.d.cts +364 -0
  196. package/dist/normalizer.d.ts +364 -0
  197. package/dist/normalizer.js +10 -0
  198. package/dist/normalizer.js.map +1 -0
  199. package/dist/packages.cjs +120 -0
  200. package/dist/packages.cjs.map +1 -0
  201. package/dist/packages.d.cts +691 -0
  202. package/dist/packages.d.ts +691 -0
  203. package/dist/packages.js +23 -0
  204. package/dist/packages.js.map +1 -0
  205. package/dist/parser.cjs +54 -0
  206. package/dist/parser.cjs.map +1 -0
  207. package/dist/parser.d.cts +46 -0
  208. package/dist/parser.d.ts +46 -0
  209. package/dist/parser.js +9 -0
  210. package/dist/parser.js.map +1 -0
  211. package/dist/pipeline-CrsRPmsv.d.ts +285 -0
  212. package/dist/pipeline-DPUQt7yL.d.cts +285 -0
  213. package/dist/resolvers.cjs +12 -0
  214. package/dist/resolvers.cjs.map +1 -0
  215. package/dist/resolvers.d.cts +111 -0
  216. package/dist/resolvers.d.ts +111 -0
  217. package/dist/resolvers.js +3 -0
  218. package/dist/resolvers.js.map +1 -0
  219. package/dist/services.cjs +20 -0
  220. package/dist/services.cjs.map +1 -0
  221. package/dist/services.d.cts +30 -0
  222. package/dist/services.d.ts +30 -0
  223. package/dist/services.js +3 -0
  224. package/dist/services.js.map +1 -0
  225. package/dist/uom.cjs +55 -0
  226. package/dist/uom.cjs.map +1 -0
  227. package/dist/uom.d.cts +224 -0
  228. package/dist/uom.d.ts +224 -0
  229. package/dist/uom.js +10 -0
  230. package/dist/uom.js.map +1 -0
  231. package/dist/utilities.cjs +31 -0
  232. package/dist/utilities.cjs.map +1 -0
  233. package/dist/utilities.d.cts +113 -0
  234. package/dist/utilities.d.ts +113 -0
  235. package/dist/utilities.js +6 -0
  236. package/dist/utilities.js.map +1 -0
  237. package/dist/variables.cjs +16 -0
  238. package/dist/variables.cjs.map +1 -0
  239. package/dist/variables.d.cts +87 -0
  240. package/dist/variables.d.ts +87 -0
  241. package/dist/variables.js +3 -0
  242. package/dist/variables.js.map +1 -0
  243. package/dist/vm.cjs +283 -0
  244. package/dist/vm.cjs.map +1 -0
  245. package/dist/vm.d.cts +68 -0
  246. package/dist/vm.d.ts +68 -0
  247. package/dist/vm.js +193 -0
  248. package/dist/vm.js.map +1 -0
  249. package/package.json +2 -1
@@ -0,0 +1,1324 @@
1
+ import { registerAllTokenTypes, tokenTypeId } from './chunk-RIN643A3.js';
2
+ import { getLocale } from './chunk-GOLDJNMZ.js';
3
+ import { knownUnits } from './chunk-LIPPNDBE.js';
4
+ import { ErrorFactory } from './chunk-6RDSQURE.js';
5
+
6
+ // src/lexer/ExpressionLexer.ts
7
+ registerAllTokenTypes();
8
+ function buildCharClassTable() {
9
+ const table = new Uint8Array(128);
10
+ for (let i = 48; i <= 57; i++) table[i] = 2 /* DIGIT */;
11
+ for (let i = 65; i <= 90; i++) table[i] = 3 /* ALPHA */;
12
+ for (let i = 97; i <= 122; i++) table[i] = 3 /* ALPHA */;
13
+ table[95] = 3 /* ALPHA */;
14
+ table[46] = 4 /* DOT */;
15
+ table[32] = 1 /* WHITESPACE */;
16
+ table[9] = 1 /* WHITESPACE */;
17
+ table[10] = 1 /* WHITESPACE */;
18
+ table[13] = 1 /* WHITESPACE */;
19
+ table[33] = 5 /* OPERATOR */;
20
+ table[37] = 5 /* OPERATOR */;
21
+ table[38] = 5 /* OPERATOR */;
22
+ table[40] = 5 /* OPERATOR */;
23
+ table[41] = 5 /* OPERATOR */;
24
+ table[42] = 5 /* OPERATOR */;
25
+ table[43] = 5 /* OPERATOR */;
26
+ table[44] = 5 /* OPERATOR */;
27
+ table[45] = 5 /* OPERATOR */;
28
+ table[47] = 5 /* OPERATOR */;
29
+ table[58] = 5 /* OPERATOR */;
30
+ table[59] = 5 /* OPERATOR */;
31
+ table[60] = 5 /* OPERATOR */;
32
+ table[61] = 5 /* OPERATOR */;
33
+ table[62] = 5 /* OPERATOR */;
34
+ table[63] = 5 /* OPERATOR */;
35
+ table[91] = 5 /* OPERATOR */;
36
+ table[93] = 5 /* OPERATOR */;
37
+ table[94] = 5 /* OPERATOR */;
38
+ table[123] = 5 /* OPERATOR */;
39
+ table[124] = 5 /* OPERATOR */;
40
+ table[125] = 5 /* OPERATOR */;
41
+ table[126] = 5 /* OPERATOR */;
42
+ table[64] = 5 /* OPERATOR */;
43
+ table[34] = 6 /* QUOTE */;
44
+ table[35] = 7 /* HASH */;
45
+ table[36] = 8 /* DOLLAR */;
46
+ table[96] = 11 /* BACKTICK */;
47
+ return table;
48
+ }
49
+ var LexerToken = class {
50
+ constructor(type, typeId, value, text, offset, lineBreaks, line, col) {
51
+ this.type = type;
52
+ this.typeId = typeId;
53
+ this.value = value;
54
+ this.text = text;
55
+ this.offset = offset;
56
+ this.lineBreaks = lineBreaks;
57
+ this.line = line;
58
+ this.col = col;
59
+ }
60
+ };
61
+ var TWO_CHAR_OPS = {
62
+ 61: { 61: "EQUALITY", 62: "THEREFORE" },
63
+ // ==, => (opposite char order from >='s GTE below — no collision)
64
+ 33: { 61: "NEQ" },
65
+ // !=
66
+ 62: { 61: "GTE" },
67
+ // >=
68
+ 60: { 61: "LTE" },
69
+ // <=
70
+ 38: { 38: "LOGICAL_AND" },
71
+ // &&
72
+ 124: { 124: "LOGICAL_OR" }
73
+ // ||
74
+ // Note: ** is NOT a single token, the existing moo lexer emits two
75
+ // separate STAR tokens, and the parser consumes them that way.
76
+ // 42: { 42: 'EXPONENT' }, // **, disabled for moo compatibility
77
+ };
78
+ var OP_MAP = {
79
+ 43: "PLUS",
80
+ // +
81
+ 45: "MINUS",
82
+ // -
83
+ 42: "STAR",
84
+ // *
85
+ 47: "SLASH",
86
+ // /
87
+ 94: "CARET",
88
+ // ^
89
+ 37: "PERCENT",
90
+ // %
91
+ 40: "LPAREN",
92
+ // (
93
+ 41: "RPAREN",
94
+ // )
95
+ 91: "LBRACKET",
96
+ // [
97
+ 93: "RBRACKET",
98
+ // ]
99
+ 123: "LBRACE",
100
+ // {
101
+ 125: "RBRACE",
102
+ // }
103
+ 44: "COMMA",
104
+ // ,
105
+ 58: "COLON",
106
+ // :
107
+ 59: "SEMICOLON",
108
+ // ;
109
+ 61: "EQUALS",
110
+ // =
111
+ 63: "QUESTION",
112
+ // ?
113
+ 33: "BANG",
114
+ // !
115
+ 38: "BIT_AND",
116
+ // &
117
+ 124: "BIT_OR",
118
+ // |
119
+ 60: "LT",
120
+ // <
121
+ 62: "GT",
122
+ // >
123
+ 126: "BIT_NOT",
124
+ // ~
125
+ // "@", activates the token type name already dormant-reserved for this
126
+ // exact purpose (see Token.ts's OVER/RATE_AT doc comment and
127
+ // normalizer/TokenNormalizer.ts's NON_WORD_NAMES, both of which already
128
+ // anticipated "AT" as a future "@" symbol token before this addition).
129
+ // Backs the time package's video-timecode literal's alternate fps
130
+ // separator (`01:02:03:04 @ 30fps`, equivalent to `... at 30fps`). See
131
+ // packages/time/parselets/VideoTimecodeParselet.ts.
132
+ 64: "AT"
133
+ // @
134
+ };
135
+ var EXPRESSION_INDICATOR_CODES = (() => {
136
+ const set = /* @__PURE__ */ new Set();
137
+ for (let i = 48; i <= 57; i++) set.add(i);
138
+ const opCodes = [43, 45, 42, 47, 94, 37, 40, 41, 91, 93, 123, 125, 61, 60, 62, 33, 38, 124, 126, 59, 63];
139
+ for (const c of opCodes) set.add(c);
140
+ set.add(36);
141
+ set.add(163);
142
+ set.add(8364);
143
+ set.add(165);
144
+ set.add(8381);
145
+ set.add(8361);
146
+ set.add(96);
147
+ set.add(46);
148
+ set.add(35);
149
+ return set;
150
+ })();
151
+ var _ExpressionLexer = class _ExpressionLexer {
152
+ constructor(localeCode = "en", lookup) {
153
+ /**
154
+ * Configured TokenLookup from TokenClassRegistry. When set, replaces
155
+ * the internal keyword map and unit set with registry-built equivalents.
156
+ * Enables data-driven keyword/unit registration across locale keywords,
157
+ * provider keywords, and plugins.
158
+ *
159
+ * Set at construction time via the constructor parameter. Plugin-registered
160
+ * keywords/units (via registerVocabulary()) are checked alongside
161
+ * the configuredLookup, neither source is bypassed.
162
+ */
163
+ this.configuredLookup = null;
164
+ // Instance state
165
+ this.input = "";
166
+ this.pos = 0;
167
+ this.len = 0;
168
+ // Line / column tracking (1-indexed)
169
+ this.line = 1;
170
+ this.lineStartPos = 0;
171
+ // Plugin-extensible keyword map (merged with locale keywordMap)
172
+ this.pluginKeywordMap = /* @__PURE__ */ new Map();
173
+ // Plugin-extensible two-char operators: firstChar → (secondChar → tokenType)
174
+ this.pluginOperators = /* @__PURE__ */ new Map();
175
+ // Plugin-extensible units (merged with knownUnits)
176
+ this.pluginUnits = /* @__PURE__ */ new Set();
177
+ // Fast-path guards: skip plugin lookups entirely when no plugins registered
178
+ this.hasPluginOps = false;
179
+ /**
180
+ * Inline solve spans collected during the most recent tokenization pass.
181
+ * Populated by [Symbol.iterator]() and consumed by scanDocument().
182
+ */
183
+ this._inlineSolveSpans = [];
184
+ // Plugin-extensible raw-line patterns. See LexerVocabulary.rawLinePatterns.
185
+ this.pluginRawLinePatterns = [];
186
+ /**
187
+ * If a `rawLinePatterns` rule matches the FULL text most recently passed
188
+ * to {@link reset}, this holds the single synthetic token that
189
+ * {@link tokenizeAll} should return instead of running the
190
+ * character-by-character scanner. Cleared (re-evaluated) on every
191
+ * {@link reset} call. `null` when no plugin registered any raw-line
192
+ * patterns, or none matched, the overwhelmingly common case, checked
193
+ * with a `length === 0` guard before ever touching this field so a
194
+ * plugin-free lexer pays zero cost for the feature.
195
+ */
196
+ this.pendingRawLineToken = null;
197
+ this.localeCode = localeCode;
198
+ this.locale = getLocale(localeCode);
199
+ this.configuredLookup = lookup ?? null;
200
+ this.keywordMap = /* @__PURE__ */ new Map();
201
+ for (const [k, v] of Object.entries(this.locale.keywordMap)) {
202
+ this.keywordMap.set(k.toLowerCase(), v);
203
+ }
204
+ this.mergedKeywords = new Map(this.keywordMap);
205
+ this.mergedUnits = new Set(knownUnits);
206
+ }
207
+ /**
208
+ * Test `text` against every registered `rawLinePatterns` rule, in
209
+ * registration order. Returns a synthetic token for the first rule
210
+ * whose `pattern` matches AND whose capture group 1 is non-empty after
211
+ * trimming; returns `null` if no rule matches (the normal
212
+ * character-by-character scanner should run instead).
213
+ */
214
+ matchRawLine(text) {
215
+ for (const rule of this.pluginRawLinePatterns) {
216
+ const m = rule.pattern.exec(text);
217
+ if (m && typeof m[1] === "string") {
218
+ const value = m[1].trim();
219
+ if (value.length > 0) {
220
+ return new LexerToken(rule.tokenType, tokenTypeId(rule.tokenType), value, value, 0, 0, this.line, 1);
221
+ }
222
+ }
223
+ }
224
+ return null;
225
+ }
226
+ /** Rebuild merged keyword and unit collections after plugin registration. */
227
+ rebuildMergedCollections() {
228
+ this.mergedKeywords = new Map([...this.keywordMap, ...this.pluginKeywordMap]);
229
+ this.mergedUnits = /* @__PURE__ */ new Set([...knownUnits, ...this.pluginUnits]);
230
+ }
231
+ /**
232
+ * Register a plugin to extend the lexer with custom tokens.
233
+ *
234
+ * All registrations are additive, built-in patterns still work.
235
+ * Keywords, operators, and units from the plugin are merged
236
+ * with existing ones. Calling multiple times adds more entries.
237
+ *
238
+ * Note: multi-word phrases are now handled by the TokenNormalizer
239
+ * (see `IEnginePackage.normalizerRules`), not the lexer.
240
+ *
241
+ * Built-in tokens CANNOT be overridden. Throws a EngineError if the
242
+ * plugin attempts to register a keyword, operator, or unit
243
+ * that conflicts with a built-in one.
244
+ */
245
+ registerVocabulary(plugin) {
246
+ if (plugin.keywords) {
247
+ for (const [keyword, tokenType] of Object.entries(plugin.keywords)) {
248
+ const lower = keyword.toLowerCase();
249
+ if (this.keywordMap.has(lower)) {
250
+ throw ErrorFactory.config(
251
+ "PLUGIN_KEYWORD_COLLISION",
252
+ `Plugin keyword "${keyword}" conflicts with built-in keyword (type: ${this.keywordMap.get(lower)}). Built-in keywords cannot be overridden.`,
253
+ { keyword, builtinType: this.keywordMap.get(lower) }
254
+ );
255
+ }
256
+ this.pluginKeywordMap.set(lower, tokenType);
257
+ }
258
+ this.rebuildMergedCollections();
259
+ }
260
+ if (plugin.operators) {
261
+ this.hasPluginOps = true;
262
+ for (const [chars, tokenType] of Object.entries(plugin.operators)) {
263
+ if (chars.length === 2) {
264
+ const first = chars.charCodeAt(0);
265
+ const second = chars.charCodeAt(1);
266
+ const builtInSecondMap = TWO_CHAR_OPS[first];
267
+ if (builtInSecondMap && builtInSecondMap[second] !== void 0) {
268
+ throw ErrorFactory.config(
269
+ "PLUGIN_OPERATOR_COLLISION",
270
+ `Plugin operator "${chars}" conflicts with built-in operator (type: ${builtInSecondMap[second]}). Built-in operators cannot be overridden.`,
271
+ { operator: chars, builtinType: builtInSecondMap[second] }
272
+ );
273
+ }
274
+ if (first === 60 && second === 60) {
275
+ throw ErrorFactory.config(
276
+ "PLUGIN_OPERATOR_COLLISION",
277
+ `Plugin operator "${chars}" conflicts with built-in operator (type: LSHIFT). Built-in operators cannot be overridden.`,
278
+ { operator: chars, builtinType: "LSHIFT" }
279
+ );
280
+ }
281
+ if (first === 62 && second === 62) {
282
+ throw ErrorFactory.config(
283
+ "PLUGIN_OPERATOR_COLLISION",
284
+ `Plugin operator "${chars}" conflicts with built-in operator (type: RSHIFT). Built-in operators cannot be overridden.`,
285
+ { operator: chars, builtinType: "RSHIFT" }
286
+ );
287
+ }
288
+ if (first === 47 && second === 47) {
289
+ throw ErrorFactory.config(
290
+ "PLUGIN_OPERATOR_COLLISION",
291
+ `Plugin operator "${chars}" conflicts with built-in comment sequence. Comment sequences cannot be overridden.`,
292
+ { operator: chars, builtinType: "COMMENT" }
293
+ );
294
+ }
295
+ let inner = this.pluginOperators.get(first);
296
+ if (!inner) {
297
+ inner = /* @__PURE__ */ new Map();
298
+ this.pluginOperators.set(first, inner);
299
+ }
300
+ inner.set(second, tokenType);
301
+ }
302
+ }
303
+ }
304
+ if (plugin.units) {
305
+ for (const unit of plugin.units) {
306
+ if (knownUnits.has(unit)) {
307
+ throw ErrorFactory.config(
308
+ "PLUGIN_UNIT_COLLISION",
309
+ `Plugin unit "${unit}" conflicts with a built-in unit. Built-in units cannot be overridden.`,
310
+ { unit }
311
+ );
312
+ }
313
+ this.pluginUnits.add(unit);
314
+ }
315
+ this.rebuildMergedCollections();
316
+ }
317
+ if (plugin.rawLinePatterns) {
318
+ this.pluginRawLinePatterns.push(...plugin.rawLinePatterns);
319
+ }
320
+ }
321
+ /**
322
+ * Unregister a plugin, removing its custom tokens from the lexer.
323
+ *
324
+ * This is the inverse of registerVocabulary(). All keywords, operators,
325
+ * and units registered by the plugin are removed. After
326
+ * unregistration, those tokens will revert to their default behavior
327
+ * (e.g., keywords become IDENT, operators become ERROR).
328
+ *
329
+ * Calling unregisterVocabulary with a plugin that was never registered
330
+ * is safe, it simply has no effect.
331
+ */
332
+ unregisterVocabulary(plugin) {
333
+ if (plugin.keywords) {
334
+ for (const keyword of Object.keys(plugin.keywords)) {
335
+ this.pluginKeywordMap.delete(keyword.toLowerCase());
336
+ }
337
+ this.rebuildMergedCollections();
338
+ }
339
+ if (plugin.operators) {
340
+ for (const chars of Object.keys(plugin.operators)) {
341
+ if (chars.length === 2) {
342
+ const first = chars.charCodeAt(0);
343
+ const second = chars.charCodeAt(1);
344
+ const inner = this.pluginOperators.get(first);
345
+ if (inner) {
346
+ inner.delete(second);
347
+ if (inner.size === 0) {
348
+ this.pluginOperators.delete(first);
349
+ }
350
+ }
351
+ }
352
+ }
353
+ this.hasPluginOps = this.pluginOperators.size > 0;
354
+ }
355
+ if (plugin.units) {
356
+ for (const unit of plugin.units) {
357
+ this.pluginUnits.delete(unit);
358
+ }
359
+ this.rebuildMergedCollections();
360
+ }
361
+ if (plugin.rawLinePatterns) {
362
+ const toRemove = new Set(plugin.rawLinePatterns);
363
+ this.pluginRawLinePatterns = this.pluginRawLinePatterns.filter((r) => !toRemove.has(r));
364
+ }
365
+ }
366
+ reset(input) {
367
+ this.input = input;
368
+ this.pos = 0;
369
+ this.len = input.length;
370
+ this.line = 1;
371
+ this.lineStartPos = 0;
372
+ this.pendingRawLineToken = this.pluginRawLinePatterns.length > 0 ? this.matchRawLine(input) : null;
373
+ }
374
+ /**
375
+ * Scan a full document text in a single pass, classifying each line and
376
+ * tokenizing non-skipped lines.
377
+ *
378
+ * Replaces the separate classifyLine() + findInlineSolves() + per-line
379
+ * reset() + tokenizeAll() pattern with a single character-by-character
380
+ * walk through the entire document. Key benefits:
381
+ *
382
+ * - **Single reset()**: `this.pos`, `this.len`, `this.line`, and
383
+ * `this.lineStartPos` are set once for the whole document, not per-line.
384
+ * - **Single classification**: classifyLine() runs once per line inline;
385
+ * skipped lines are jumped over without tokenization.
386
+ * - **Shared tokenization**: Non-skipped lines are tokenized using the
387
+ * existing state machine, yielding Token[] without per-line reset().
388
+ * - **Inline solve detection**: findInlineSolves() is called only for
389
+ * lines that classifyLine() marks as having inline solves.
390
+ *
391
+ * Tokenization is scoped to each line by temporarily restricting
392
+ * `this.len` to the line end position, so the [Symbol.iterator]
393
+ * generator naturally stops at the line boundary. After tokenization,
394
+ * `this.len` is restored and `this.pos` advances past the newline.
395
+ *
396
+ * @param text The full document text (with newlines).
397
+ * @returns Array of ScanLineResult, one per line, in document order.
398
+ */
399
+ scanDocument(text) {
400
+ this.input = text;
401
+ this.pos = 0;
402
+ this.len = text.length;
403
+ this.line = 1;
404
+ this.lineStartPos = 0;
405
+ const results = [];
406
+ const input = this.input;
407
+ const docLen = this.len;
408
+ while (this.pos < docLen) {
409
+ const lineStart = this.pos;
410
+ let lineEnd = this.pos;
411
+ while (lineEnd < docLen) {
412
+ const cc = input.charCodeAt(lineEnd);
413
+ if (cc === 10 || cc === 13) break;
414
+ lineEnd++;
415
+ }
416
+ const lineNumber = this.line;
417
+ const classification = this.classifyFromPositions(lineStart, lineEnd);
418
+ const lineText = input.slice(lineStart, lineEnd);
419
+ let tokens = [];
420
+ if (!classification.skip) {
421
+ const rawToken = this.pluginRawLinePatterns.length > 0 ? this.matchRawLine(lineText) : null;
422
+ if (rawToken) {
423
+ tokens = [rawToken];
424
+ } else {
425
+ const savedLen = this.len;
426
+ this.len = lineEnd;
427
+ tokens = Array.from(this);
428
+ this.len = savedLen;
429
+ }
430
+ }
431
+ let inlineSolves = [];
432
+ if (classification.hasInlineSolve) {
433
+ if (!classification.skip && tokens.length > 0) {
434
+ const charSpans = this.findInlineSolves(lineText);
435
+ inlineSolves = this._inlineSolveSpans.map((span, i) => ({
436
+ start: charSpans[i]?.start ?? 0,
437
+ end: charSpans[i]?.end ?? 0,
438
+ expression: charSpans[i]?.expression ?? "",
439
+ columnNumber: charSpans[i]?.columnNumber ?? span.columnNumber,
440
+ startTokenIndex: span.startTokenIndex,
441
+ endTokenIndex: span.endTokenIndex
442
+ }));
443
+ } else {
444
+ inlineSolves = this.findInlineSolves(lineText);
445
+ }
446
+ }
447
+ results.push({
448
+ text: lineText,
449
+ lineNumber,
450
+ startOffset: lineStart,
451
+ endOffset: lineEnd,
452
+ classification,
453
+ tokens,
454
+ inlineSolves
455
+ });
456
+ this.pos = lineEnd;
457
+ if (this.pos < docLen) {
458
+ const nlChar = input.charCodeAt(this.pos);
459
+ if (nlChar === 13) {
460
+ this.pos++;
461
+ if (this.pos < docLen && input.charCodeAt(this.pos) === 10) {
462
+ this.pos++;
463
+ }
464
+ } else if (nlChar === 10) {
465
+ this.pos++;
466
+ }
467
+ }
468
+ this.line++;
469
+ this.lineStartPos = this.pos;
470
+ }
471
+ return results;
472
+ }
473
+ /**
474
+ * Tokenize an expression string into an array of Tokens.
475
+ *
476
+ * Delegates to the lazy [Symbol.iterator]() generator and collects all
477
+ * yielded tokens via Array.from(). For memory-sensitive use cases, prefer
478
+ * iterating the lexer directly with for...of to avoid array allocation.
479
+ *
480
+ * Optimizations:
481
+ * - CHAR_CLASS jump table (Uint8Array) → switch on small integers
482
+ * - Direct character-code dispatch (c0 cached pattern)
483
+ * - Mathematical digit parsing (integer math, not slice+parseFloat)
484
+ * - Inline operator tokenizer with two-char peek-ahead
485
+ * - Whitespace eliminated in-lexer (never emitted)
486
+ * - 0-char and 1-char fast paths
487
+ */
488
+ tokenizeAll() {
489
+ if (this.pendingRawLineToken) {
490
+ this._inlineSolveSpans = [];
491
+ return [this.pendingRawLineToken];
492
+ }
493
+ return Array.from(this);
494
+ }
495
+ // ── Lazy iterator ─────────────────────────────────────────────────────
496
+ /**
497
+ * Lazy token-by-token generator. Yields each token without allocating an
498
+ * intermediate Token[] array. Supports for...of and spread usage.
499
+ *
500
+ * Usage:
501
+ * for (const t of lexer) { ... } // lazy, no array allocation
502
+ * const tokens = [...lexer]; // materializes via spread
503
+ * const tokens = lexer.tokenizeAll(); // materializes via Array.from()
504
+ *
505
+ * IMPORTANT: This generator captures `this.len` ONCE at creation time
506
+ * (const len = this.len). `scanDocument()` relies on this behavior to
507
+ * scope tokenization to a single line by temporarily restricting
508
+ * `this.len` to the line end position before creating the iterator.
509
+ * Do NOT refactor to re-read `this.len` mid-loop without also updating
510
+ * `scanDocument()`.
511
+ */
512
+ *[Symbol.iterator]() {
513
+ const len = this.len;
514
+ if (len === 0) {
515
+ this._inlineSolveSpans = [];
516
+ return;
517
+ }
518
+ let tokenIndex = 0;
519
+ let openSpan = null;
520
+ const collectedSpans = [];
521
+ if (len === 1) {
522
+ const c0 = this.input.charCodeAt(0);
523
+ const cc = _ExpressionLexer.CHAR_CLASS[c0] ?? 0 /* SKIP */;
524
+ switch (cc) {
525
+ case 2 /* DIGIT */:
526
+ case 4 /* DOT */:
527
+ yield new LexerToken("NUMBER", tokenTypeId("NUMBER"), this.input, this.input, 0, 0, 1, 1);
528
+ tokenIndex++;
529
+ break;
530
+ case 3 /* ALPHA */: {
531
+ const input2 = this.input;
532
+ const identLower = input2.toLowerCase();
533
+ if (this.mergedUnits.has(input2)) {
534
+ yield new LexerToken("UNIT", tokenTypeId("UNIT"), input2, input2, 0, 0, 1, 1);
535
+ } else {
536
+ const kwType = this.mergedKeywords.get(identLower);
537
+ if (kwType) {
538
+ yield new LexerToken(kwType, tokenTypeId(kwType), input2, input2, 0, 0, 1, 1);
539
+ } else {
540
+ yield new LexerToken("IDENT", tokenTypeId("IDENT"), input2, input2, 0, 0, 1, 1);
541
+ }
542
+ }
543
+ tokenIndex++;
544
+ break;
545
+ }
546
+ case 5 /* OPERATOR */: {
547
+ const opType = OP_MAP[c0];
548
+ if (opType) {
549
+ yield new LexerToken(opType, tokenTypeId(opType), this.input, this.input, 0, 0, 1, 1);
550
+ tokenIndex++;
551
+ }
552
+ break;
553
+ }
554
+ case 6 /* QUOTE */:
555
+ this.pos = 0;
556
+ yield this.tokenizeString();
557
+ tokenIndex++;
558
+ break;
559
+ case 7 /* HASH */:
560
+ this.pos = 0;
561
+ yield this.tokenizeComment();
562
+ tokenIndex++;
563
+ break;
564
+ case 8 /* DOLLAR */:
565
+ yield new LexerToken("DOLLAR", tokenTypeId("DOLLAR"), "$", "$", 0, 0, 1, 1);
566
+ tokenIndex++;
567
+ break;
568
+ case 11 /* BACKTICK */:
569
+ yield new LexerToken("BACKTICK_OPEN", tokenTypeId("BACKTICK_OPEN"), "`", "`", 0, 0, 1, 1);
570
+ tokenIndex++;
571
+ break;
572
+ default: {
573
+ if (c0 === 215) {
574
+ yield new LexerToken("STAR", tokenTypeId("STAR"), "\xD7", "\xD7", 0, 0, 1, 1);
575
+ tokenIndex++;
576
+ } else if (c0 === 247) {
577
+ yield new LexerToken("SLASH", tokenTypeId("SLASH"), "\xF7", "\xF7", 0, 0, 1, 1);
578
+ tokenIndex++;
579
+ } else if (c0 === 8800) {
580
+ yield new LexerToken("NEQ", tokenTypeId("NEQ"), "\u2260", "\u2260", 0, 0, 1, 1);
581
+ tokenIndex++;
582
+ } else if (c0 === 163) {
583
+ yield new LexerToken("POUND", tokenTypeId("POUND"), "\xA3", "\xA3", 0, 0, 1, 1);
584
+ tokenIndex++;
585
+ } else if (c0 === 8364) {
586
+ yield new LexerToken("EURO", tokenTypeId("EURO"), "\u20AC", "\u20AC", 0, 0, 1, 1);
587
+ tokenIndex++;
588
+ } else if (c0 === 165) {
589
+ yield new LexerToken("YEN", tokenTypeId("YEN"), "\xA5", "\xA5", 0, 0, 1, 1);
590
+ tokenIndex++;
591
+ } else if (c0 === 8381) {
592
+ yield new LexerToken("RUBLE", tokenTypeId("RUBLE"), "\u20BD", "\u20BD", 0, 0, 1, 1);
593
+ tokenIndex++;
594
+ } else if (c0 === 8361) {
595
+ yield new LexerToken("WON", tokenTypeId("WON"), "\u20A9", "\u20A9", 0, 0, 1, 1);
596
+ tokenIndex++;
597
+ } else if (c0 === 8377) {
598
+ yield new LexerToken("CURRENCY_SYMBOL", tokenTypeId("CURRENCY_SYMBOL"), "\u20B9", "\u20B9", 0, 0, 1, 1);
599
+ tokenIndex++;
600
+ } else if (c0 === 8378) {
601
+ yield new LexerToken("CURRENCY_SYMBOL", tokenTypeId("CURRENCY_SYMBOL"), "\u20BA", "\u20BA", 0, 0, 1, 1);
602
+ tokenIndex++;
603
+ } else if (c0 === 8372) {
604
+ yield new LexerToken("CURRENCY_SYMBOL", tokenTypeId("CURRENCY_SYMBOL"), "\u20B4", "\u20B4", 0, 0, 1, 1);
605
+ tokenIndex++;
606
+ } else if (c0 === 8362) {
607
+ yield new LexerToken("CURRENCY_SYMBOL", tokenTypeId("CURRENCY_SYMBOL"), "\u20AA", "\u20AA", 0, 0, 1, 1);
608
+ tokenIndex++;
609
+ } else if (c0 === 8363) {
610
+ yield new LexerToken("CURRENCY_SYMBOL", tokenTypeId("CURRENCY_SYMBOL"), "\u20AB", "\u20AB", 0, 0, 1, 1);
611
+ tokenIndex++;
612
+ } else if (c0 === 8358) {
613
+ yield new LexerToken("CURRENCY_SYMBOL", tokenTypeId("CURRENCY_SYMBOL"), "\u20A6", "\u20A6", 0, 0, 1, 1);
614
+ tokenIndex++;
615
+ } else if (c0 === 8369) {
616
+ yield new LexerToken("CURRENCY_SYMBOL", tokenTypeId("CURRENCY_SYMBOL"), "\u20B1", "\u20B1", 0, 0, 1, 1);
617
+ tokenIndex++;
618
+ } else if (c0 >= 128) {
619
+ yield new LexerToken("IDENT", tokenTypeId("IDENT"), this.input, this.input, 0, 0, 1, 1);
620
+ tokenIndex++;
621
+ }
622
+ break;
623
+ }
624
+ }
625
+ this._inlineSolveSpans = collectedSpans;
626
+ return;
627
+ }
628
+ const input = this.input;
629
+ while (this.pos < len) {
630
+ const c0 = input.charCodeAt(this.pos);
631
+ const cc = _ExpressionLexer.CHAR_CLASS[c0] ?? 0 /* SKIP */;
632
+ if (openSpan && c0 === 92 && this.pos + 1 < len && input.charCodeAt(this.pos + 1) === 96) {
633
+ this.pos += 2;
634
+ continue;
635
+ }
636
+ switch (cc) {
637
+ // ── Whitespace, skip entirely, track newlines ────────────────
638
+ case 1 /* WHITESPACE */:
639
+ this.pos++;
640
+ if (c0 === 10) {
641
+ this.line++;
642
+ this.lineStartPos = this.pos;
643
+ } else if (c0 === 13) {
644
+ this.line++;
645
+ if (this.pos < len && input.charCodeAt(this.pos) === 10) {
646
+ this.pos++;
647
+ }
648
+ this.lineStartPos = this.pos;
649
+ }
650
+ break;
651
+ // ── Digit, inline number tokenizer ───────────────────────────
652
+ case 2 /* DIGIT */:
653
+ yield this.tokenizeNumber();
654
+ tokenIndex++;
655
+ break;
656
+ // ── Alpha / underscore, identifier or keyword ────────────────
657
+ case 3 /* ALPHA */: {
658
+ const token = this.tokenizeIdentifier();
659
+ if (token.type === "INLINE_SOLVE_START") {
660
+ openSpan = { startTokenIndex: tokenIndex, startColumn: token.col };
661
+ }
662
+ yield token;
663
+ tokenIndex++;
664
+ break;
665
+ }
666
+ // ── Dot, could be decimal (.5) or DOT token ─────────────────
667
+ case 4 /* DOT */:
668
+ if (this.pos + 1 < len) {
669
+ const nextCc = _ExpressionLexer.CHAR_CLASS[input.charCodeAt(this.pos + 1)] ?? 0 /* SKIP */;
670
+ if (nextCc === 2 /* DIGIT */) {
671
+ yield this.tokenizeNumber();
672
+ } else {
673
+ const col = this.pos - this.lineStartPos + 1;
674
+ yield new LexerToken("DOT", tokenTypeId("DOT"), ".", ".", this.pos, 0, this.line, col);
675
+ this.pos++;
676
+ }
677
+ } else {
678
+ const col = this.pos - this.lineStartPos + 1;
679
+ yield new LexerToken("DOT", tokenTypeId("DOT"), ".", ".", this.pos, 0, this.line, col);
680
+ this.pos++;
681
+ }
682
+ tokenIndex++;
683
+ break;
684
+ // ── Operator / punctuation ────────────────────────────────────
685
+ case 5 /* OPERATOR */:
686
+ yield this.tokenizeOperator();
687
+ tokenIndex++;
688
+ break;
689
+ // ── String literal ────────────────────────────────────────────
690
+ case 6 /* QUOTE */:
691
+ yield this.tokenizeString();
692
+ tokenIndex++;
693
+ break;
694
+ // ── Comment (# or //) ─────────────────────────────────────────
695
+ case 7 /* HASH */:
696
+ yield this.tokenizeComment();
697
+ tokenIndex++;
698
+ break;
699
+ // ── Dollar sign $ ─────────────────────────────────────────────
700
+ case 8 /* DOLLAR */: {
701
+ const col = this.pos - this.lineStartPos + 1;
702
+ yield new LexerToken("DOLLAR", tokenTypeId("DOLLAR"), "$", "$", this.pos, 0, this.line, col);
703
+ this.pos++;
704
+ tokenIndex++;
705
+ break;
706
+ }
707
+ // ── Backtick ` ───────────────────────────────────────────────
708
+ case 11 /* BACKTICK */: {
709
+ const col = this.pos - this.lineStartPos + 1;
710
+ yield new LexerToken("BACKTICK_OPEN", tokenTypeId("BACKTICK_OPEN"), "`", "`", this.pos, 0, this.line, col);
711
+ this.pos++;
712
+ if (openSpan) {
713
+ const span = openSpan;
714
+ collectedSpans.push({
715
+ start: 0,
716
+ end: 0,
717
+ expression: "",
718
+ columnNumber: span.startColumn,
719
+ startTokenIndex: span.startTokenIndex,
720
+ endTokenIndex: tokenIndex
721
+ });
722
+ openSpan = null;
723
+ }
724
+ tokenIndex++;
725
+ break;
726
+ }
727
+ // ── Non-ASCII characters ─────────────────────────────────────
728
+ default: {
729
+ const col = this.pos - this.lineStartPos + 1;
730
+ if (c0 === 215) {
731
+ yield new LexerToken("STAR", tokenTypeId("STAR"), "\xD7", "\xD7", this.pos, 0, this.line, col);
732
+ this.pos++;
733
+ tokenIndex++;
734
+ } else if (c0 === 247) {
735
+ yield new LexerToken("SLASH", tokenTypeId("SLASH"), "\xF7", "\xF7", this.pos, 0, this.line, col);
736
+ this.pos++;
737
+ tokenIndex++;
738
+ } else if (c0 === 8800) {
739
+ yield new LexerToken("NEQ", tokenTypeId("NEQ"), "\u2260", "\u2260", this.pos, 0, this.line, col);
740
+ this.pos++;
741
+ tokenIndex++;
742
+ } else if (c0 === 163) {
743
+ yield new LexerToken("POUND", tokenTypeId("POUND"), "\xA3", "\xA3", this.pos, 0, this.line, col);
744
+ this.pos++;
745
+ tokenIndex++;
746
+ } else if (c0 === 8364) {
747
+ yield new LexerToken("EURO", tokenTypeId("EURO"), "\u20AC", "\u20AC", this.pos, 0, this.line, col);
748
+ this.pos++;
749
+ tokenIndex++;
750
+ } else if (c0 === 165) {
751
+ yield new LexerToken("YEN", tokenTypeId("YEN"), "\xA5", "\xA5", this.pos, 0, this.line, col);
752
+ this.pos++;
753
+ tokenIndex++;
754
+ } else if (c0 === 8381) {
755
+ yield new LexerToken("RUBLE", tokenTypeId("RUBLE"), "\u20BD", "\u20BD", this.pos, 0, this.line, col);
756
+ this.pos++;
757
+ tokenIndex++;
758
+ } else if (c0 === 8361) {
759
+ yield new LexerToken("WON", tokenTypeId("WON"), "\u20A9", "\u20A9", this.pos, 0, this.line, col);
760
+ this.pos++;
761
+ tokenIndex++;
762
+ } else if (c0 === 8377) {
763
+ yield new LexerToken("CURRENCY_SYMBOL", tokenTypeId("CURRENCY_SYMBOL"), "\u20B9", "\u20B9", this.pos, 0, this.line, col);
764
+ this.pos++;
765
+ tokenIndex++;
766
+ } else if (c0 === 8378) {
767
+ yield new LexerToken("CURRENCY_SYMBOL", tokenTypeId("CURRENCY_SYMBOL"), "\u20BA", "\u20BA", this.pos, 0, this.line, col);
768
+ this.pos++;
769
+ tokenIndex++;
770
+ } else if (c0 === 8372) {
771
+ yield new LexerToken("CURRENCY_SYMBOL", tokenTypeId("CURRENCY_SYMBOL"), "\u20B4", "\u20B4", this.pos, 0, this.line, col);
772
+ this.pos++;
773
+ tokenIndex++;
774
+ } else if (c0 === 8362) {
775
+ yield new LexerToken("CURRENCY_SYMBOL", tokenTypeId("CURRENCY_SYMBOL"), "\u20AA", "\u20AA", this.pos, 0, this.line, col);
776
+ this.pos++;
777
+ tokenIndex++;
778
+ } else if (c0 === 8363) {
779
+ yield new LexerToken("CURRENCY_SYMBOL", tokenTypeId("CURRENCY_SYMBOL"), "\u20AB", "\u20AB", this.pos, 0, this.line, col);
780
+ this.pos++;
781
+ tokenIndex++;
782
+ } else if (c0 === 8358) {
783
+ yield new LexerToken("CURRENCY_SYMBOL", tokenTypeId("CURRENCY_SYMBOL"), "\u20A6", "\u20A6", this.pos, 0, this.line, col);
784
+ this.pos++;
785
+ tokenIndex++;
786
+ } else if (c0 === 8369) {
787
+ yield new LexerToken("CURRENCY_SYMBOL", tokenTypeId("CURRENCY_SYMBOL"), "\u20B1", "\u20B1", this.pos, 0, this.line, col);
788
+ this.pos++;
789
+ tokenIndex++;
790
+ } else if (c0 >= 128) {
791
+ yield this.tokenizeIdentifier();
792
+ tokenIndex++;
793
+ } else {
794
+ this.pos++;
795
+ }
796
+ break;
797
+ }
798
+ }
799
+ }
800
+ this._inlineSolveSpans = collectedSpans;
801
+ }
802
+ // ── Inline number tokenizer ────────────────────────────────────────────
803
+ /**
804
+ * Character-by-character number parsing.
805
+ *
806
+ * Supports: integers, floats, scientific notation (1.5e10, 1.5e-10),
807
+ * hex (0xFF), binary (0b1010), octal (0o17), BigInt suffix (123n),
808
+ * thousands separators (1,234 or 1.234.567).
809
+ *
810
+ * Returns a LexerToken and advances `this.pos` past the number.
811
+ */
812
+ tokenizeNumber() {
813
+ const input = this.input;
814
+ const len = this.len;
815
+ let pos = this.pos;
816
+ const start = pos;
817
+ const startCol = pos - this.lineStartPos + 1;
818
+ let cc;
819
+ if (input.charCodeAt(pos) === 48 && pos + 1 < len) {
820
+ const next = input.charCodeAt(pos + 1);
821
+ if (next === 120 || next === 88) {
822
+ pos += 2;
823
+ while (pos < len && (cc = input.charCodeAt(pos), cc >= 48 && cc <= 57 || cc >= 65 && cc <= 70 || cc >= 97 && cc <= 102)) {
824
+ pos++;
825
+ }
826
+ const text2 = input.slice(start, pos);
827
+ this.pos = pos;
828
+ return new LexerToken("NUMBER", tokenTypeId("NUMBER"), text2, text2, start, 0, this.line, startCol);
829
+ }
830
+ if (next === 98 || next === 66) {
831
+ pos += 2;
832
+ while (pos < len && (cc = input.charCodeAt(pos), cc === 48 || cc === 49)) {
833
+ pos++;
834
+ }
835
+ const text2 = input.slice(start, pos);
836
+ this.pos = pos;
837
+ return new LexerToken("NUMBER", tokenTypeId("NUMBER"), text2, text2, start, 0, this.line, startCol);
838
+ }
839
+ if (next === 111 || next === 79) {
840
+ pos += 2;
841
+ while (pos < len && (cc = input.charCodeAt(pos), cc >= 48 && cc <= 55)) {
842
+ pos++;
843
+ }
844
+ const text2 = input.slice(start, pos);
845
+ this.pos = pos;
846
+ return new LexerToken("NUMBER", tokenTypeId("NUMBER"), text2, text2, start, 0, this.line, startCol);
847
+ }
848
+ }
849
+ let hasIntPart = false;
850
+ while (pos < len && (cc = input.charCodeAt(pos), cc >= 48 && cc <= 57)) {
851
+ hasIntPart = true;
852
+ pos++;
853
+ }
854
+ while (hasIntPart && pos < len && (input.charCodeAt(pos) === 44 || input.charCodeAt(pos) === 46)) {
855
+ if (pos + 4 <= len) {
856
+ const d1 = input.charCodeAt(pos + 1);
857
+ const d2 = input.charCodeAt(pos + 2);
858
+ const d3 = input.charCodeAt(pos + 3);
859
+ const d4 = pos + 4 < len ? input.charCodeAt(pos + 4) : -1;
860
+ const isGroupOfExactlyThree = !(d4 >= 48 && d4 <= 57);
861
+ if (d1 >= 48 && d1 <= 57 && d2 >= 48 && d2 <= 57 && d3 >= 48 && d3 <= 57 && isGroupOfExactlyThree) {
862
+ pos += 4;
863
+ hasIntPart = true;
864
+ continue;
865
+ }
866
+ }
867
+ break;
868
+ }
869
+ let hasDecimal = false;
870
+ if (pos < len && input.charCodeAt(pos) === 46) {
871
+ if (pos + 1 < len) {
872
+ const nextCc = input.charCodeAt(pos + 1);
873
+ if (nextCc >= 48 && nextCc <= 57) {
874
+ hasDecimal = true;
875
+ pos++;
876
+ while (pos < len && (cc = input.charCodeAt(pos), cc >= 48 && cc <= 57)) {
877
+ pos++;
878
+ }
879
+ }
880
+ }
881
+ }
882
+ let hasExponent = false;
883
+ if (pos < len) {
884
+ const ec = input.charCodeAt(pos);
885
+ if (ec === 101 || ec === 69) {
886
+ if (pos + 1 < len) {
887
+ const next = input.charCodeAt(pos + 1);
888
+ if (next >= 48 && next <= 57 || next === 43 || next === 45) {
889
+ hasExponent = true;
890
+ pos++;
891
+ if (next === 43 || next === 45) pos++;
892
+ while (pos < len && (cc = input.charCodeAt(pos), cc >= 48 && cc <= 57)) {
893
+ pos++;
894
+ }
895
+ }
896
+ }
897
+ }
898
+ }
899
+ if (pos < len && input.charCodeAt(pos) === 110) {
900
+ if (hasIntPart && !hasDecimal && !hasExponent) {
901
+ pos++;
902
+ const text2 = input.slice(start, pos);
903
+ this.pos = pos;
904
+ return new LexerToken("BIGINT", tokenTypeId("BIGINT"), text2, text2, start, 0, this.line, startCol);
905
+ }
906
+ }
907
+ const text = input.slice(start, pos);
908
+ this.pos = pos;
909
+ return new LexerToken("NUMBER", tokenTypeId("NUMBER"), text, text, start, 0, this.line, startCol);
910
+ }
911
+ // ── Inline identifier / keyword tokenizer ──────────────────────────────
912
+ /**
913
+ * Reads [a-zA-Z_][a-zA-Z0-9_]* and resolves to:
914
+ * - A unit type (via knownUnits, case-sensitive)
915
+ * - A keyword type (via locale keywordMap, case-insensitive)
916
+ * - IDENT if none of the above
917
+ *
918
+ * Multi-word phrases (e.g., "to the power of") are handled by the
919
+ * TokenNormalizer post-lexer pass, not the lexer.
920
+ */
921
+ tokenizeIdentifier() {
922
+ const input = this.input;
923
+ const len = this.len;
924
+ let pos = this.pos;
925
+ const start = pos;
926
+ const startCol = pos - this.lineStartPos + 1;
927
+ let cc;
928
+ while (pos < len && (cc = input.charCodeAt(pos), cc >= 48 && cc <= 57 || // 0-9
929
+ cc >= 65 && cc <= 90 || // A-Z
930
+ cc >= 97 && cc <= 122 || // a-z
931
+ cc === 95 || // _
932
+ cc >= 128)) {
933
+ pos++;
934
+ }
935
+ const identText = input.slice(start, pos);
936
+ const identLower = identText.toLowerCase();
937
+ if (identLower === "s" && pos < len && input.charCodeAt(pos) === 96) {
938
+ pos++;
939
+ this.pos = pos;
940
+ const fullText = input.slice(start, pos);
941
+ return new LexerToken("INLINE_SOLVE_START", tokenTypeId("INLINE_SOLVE_START"), fullText, fullText, start, 0, this.line, startCol);
942
+ }
943
+ const isKnownUnit = this.mergedUnits.has(identText);
944
+ if (isKnownUnit) {
945
+ if (!this.isFollowedByLParen(pos)) {
946
+ this.pos = pos;
947
+ return new LexerToken("UNIT", tokenTypeId("UNIT"), identText, identText, start, 0, this.line, startCol);
948
+ }
949
+ }
950
+ const localeKwType = this.mergedKeywords.get(identLower);
951
+ if (localeKwType) {
952
+ this.pos = pos;
953
+ return new LexerToken(localeKwType, tokenTypeId(localeKwType), identText, identText, start, 0, this.line, startCol);
954
+ }
955
+ this.pos = pos;
956
+ return new LexerToken("IDENT", tokenTypeId("IDENT"), identText, identText, start, 0, this.line, startCol);
957
+ }
958
+ /**
959
+ * Peek past in-expression whitespace (space, tab) from `pos` to check
960
+ * if the next significant character is '('.
961
+ */
962
+ isFollowedByLParen(pos) {
963
+ const len = this.len;
964
+ let lookPos = pos;
965
+ while (lookPos < len) {
966
+ const cc = this.input.charCodeAt(lookPos);
967
+ if (cc === 40) return true;
968
+ if (cc !== 32 && cc !== 9) break;
969
+ lookPos++;
970
+ }
971
+ return false;
972
+ }
973
+ // ── Inline operator tokenizer ─────────────────────────────────────────
974
+ /**
975
+ * Reads an operator/punctuation token.
976
+ * Handles two-char operators (==, !=, >=, <=, **) and the special
977
+ * cases << (LSHIFT) and >> (RSHIFT).
978
+ */
979
+ tokenizeOperator() {
980
+ const input = this.input;
981
+ const pos = this.pos;
982
+ const col = pos - this.lineStartPos + 1;
983
+ const c0 = input.charCodeAt(pos);
984
+ const len = this.len;
985
+ if (pos + 1 < len) {
986
+ const c1 = input.charCodeAt(pos + 1);
987
+ const secondMap = TWO_CHAR_OPS[c0];
988
+ if (secondMap) {
989
+ const twoCharType = secondMap[c1];
990
+ if (twoCharType) {
991
+ const text2 = input.slice(pos, pos + 2);
992
+ this.pos = pos + 2;
993
+ return new LexerToken(twoCharType, tokenTypeId(twoCharType), text2, text2, pos, 0, this.line, col);
994
+ }
995
+ }
996
+ if (c0 === 47 && c1 === 47) {
997
+ let commentPos = pos + 2;
998
+ while (commentPos < len) {
999
+ const cc = input.charCodeAt(commentPos);
1000
+ if (cc === 10 || cc === 13) break;
1001
+ commentPos++;
1002
+ }
1003
+ const text2 = input.slice(pos, commentPos);
1004
+ this.pos = commentPos;
1005
+ return new LexerToken("COMMENT", tokenTypeId("COMMENT"), text2, text2, pos, 0, this.line, col);
1006
+ }
1007
+ if (c0 === 60 && c1 === 60) {
1008
+ this.pos = pos + 2;
1009
+ return new LexerToken("LSHIFT", tokenTypeId("LSHIFT"), "<<", "<<", pos, 0, this.line, col);
1010
+ }
1011
+ if (c0 === 62 && c1 === 62) {
1012
+ if (input.charCodeAt(pos + 2) === 62) {
1013
+ this.pos = pos + 3;
1014
+ return new LexerToken("URSHIFT", tokenTypeId("URSHIFT"), ">>>", ">>>", pos, 0, this.line, col);
1015
+ }
1016
+ this.pos = pos + 2;
1017
+ return new LexerToken("RSHIFT", tokenTypeId("RSHIFT"), ">>", ">>", pos, 0, this.line, col);
1018
+ }
1019
+ if (this.hasPluginOps) {
1020
+ const pluginInner = this.pluginOperators.get(c0);
1021
+ if (pluginInner) {
1022
+ const pluginType = pluginInner.get(c1);
1023
+ if (pluginType) {
1024
+ const text2 = input.slice(pos, pos + 2);
1025
+ this.pos = pos + 2;
1026
+ return new LexerToken(pluginType, tokenTypeId(pluginType), text2, text2, pos, 0, this.line, col);
1027
+ }
1028
+ }
1029
+ }
1030
+ }
1031
+ this.pos = pos + 1;
1032
+ const opType = OP_MAP[c0];
1033
+ const text = input.charAt(pos);
1034
+ return new LexerToken(opType || "ERROR", tokenTypeId(opType || "ERROR"), text, text, pos, 0, this.line, col);
1035
+ }
1036
+ // ── String literal tokenizer ──────────────────────────────────────────
1037
+ /**
1038
+ * Reads a double-quoted string literal. Supports backslash escapes.
1039
+ */
1040
+ tokenizeString() {
1041
+ const input = this.input;
1042
+ const len = this.len;
1043
+ const start = this.pos;
1044
+ const startCol = start - this.lineStartPos + 1;
1045
+ let pos = start + 1;
1046
+ let lineBreaks = 0;
1047
+ while (pos < len) {
1048
+ const c0 = input.charCodeAt(pos);
1049
+ if (c0 === 34) {
1050
+ pos++;
1051
+ const text2 = input.slice(start, pos);
1052
+ this.pos = pos;
1053
+ return new LexerToken("STRING", tokenTypeId("STRING"), text2, text2, start, lineBreaks, this.line, startCol);
1054
+ }
1055
+ if (c0 === 92 && pos + 1 < len) {
1056
+ pos += 2;
1057
+ continue;
1058
+ }
1059
+ if (c0 === 10) {
1060
+ this.line++;
1061
+ this.lineStartPos = pos + 1;
1062
+ lineBreaks++;
1063
+ }
1064
+ pos++;
1065
+ }
1066
+ const text = input.slice(start, pos);
1067
+ this.pos = pos;
1068
+ return new LexerToken("STRING", tokenTypeId("STRING"), text, text, start, lineBreaks, this.line, startCol);
1069
+ }
1070
+ // ── Markdown line scanner (Phase B) ───────────────────────────────────
1071
+ /**
1072
+ * L1 expression gating: quickly determine if a line contains any
1073
+ * characters that indicate an expression (digits, operators, currency,
1074
+ * backticks, parentheses, etc.).
1075
+ *
1076
+ * Pure prose lines (e.g., "The quick brown fox jumps over the lazy dog")
1077
+ * return false and can be skipped without full tokenization (L2).
1078
+ *
1079
+ * This is a fast character-by-character scan that stops at the first
1080
+ * expression indicator. Called once per line in classifyFromPositions().
1081
+ */
1082
+ static hasExpressionIndicators(input, start, end) {
1083
+ const indicatorCodes = EXPRESSION_INDICATOR_CODES;
1084
+ for (let i = start; i < end; i++) {
1085
+ const cc = input.charCodeAt(i);
1086
+ if (indicatorCodes.has(cc)) return true;
1087
+ if (cc >= 128) {
1088
+ if (cc === 215 || cc === 247 || cc === 8800 || cc === 163 || cc === 8364 || cc === 165 || cc === 8381 || cc === 8361) {
1089
+ return true;
1090
+ }
1091
+ }
1092
+ }
1093
+ return false;
1094
+ }
1095
+ /**
1096
+ * Classify a line by its character positions within this.input.
1097
+ * Reads directly from this.input using start/end boundaries.
1098
+ * DOES NOT modify this.pos, purely a read-only classifier.
1099
+ */
1100
+ classifyFromPositions(start, end) {
1101
+ const len = end;
1102
+ if (start >= len) {
1103
+ return { type: "empty", skip: true, hasInlineSolve: false };
1104
+ }
1105
+ const input = this.input;
1106
+ let pos = start;
1107
+ while (pos < len) {
1108
+ const cc = input.charCodeAt(pos);
1109
+ if (cc !== 32 && cc !== 9) break;
1110
+ pos++;
1111
+ }
1112
+ if (pos >= len) {
1113
+ return { type: "empty", skip: true, hasInlineSolve: false };
1114
+ }
1115
+ const c0 = input.charCodeAt(pos);
1116
+ let hasInline;
1117
+ if (c0 === 35) {
1118
+ let hashCount = 1;
1119
+ while (pos + hashCount < len && input.charCodeAt(pos + hashCount) === 35) {
1120
+ hashCount++;
1121
+ }
1122
+ if (hashCount <= 6 && pos + hashCount < len && input.charCodeAt(pos + hashCount) === 32) {
1123
+ return { type: "heading", skip: true, hasInlineSolve: false };
1124
+ }
1125
+ return { type: "heading", skip: true, hasInlineSolve: false };
1126
+ }
1127
+ if (c0 === 62) {
1128
+ if (pos + 1 < len && input.charCodeAt(pos + 1) === 32) {
1129
+ return { type: "blockquote", skip: true, hasInlineSolve: false };
1130
+ }
1131
+ }
1132
+ if (c0 === 96 && pos + 2 < len && input.charCodeAt(pos + 1) === 96 && input.charCodeAt(pos + 2) === 96) {
1133
+ return { type: "code_fence", skip: true, hasInlineSolve: false };
1134
+ }
1135
+ if (c0 === 126 && pos + 2 < len && input.charCodeAt(pos + 1) === 126 && input.charCodeAt(pos + 2) === 126) {
1136
+ return { type: "code_fence", skip: true, hasInlineSolve: false };
1137
+ }
1138
+ if (c0 === 36 && pos + 1 < len && input.charCodeAt(pos + 1) === 36) {
1139
+ return { type: "math_fence", skip: true, hasInlineSolve: false };
1140
+ }
1141
+ if (c0 === 45 || c0 === 42 || c0 === 95) {
1142
+ let count = 1;
1143
+ while (pos + count < len && input.charCodeAt(pos + count) === c0) {
1144
+ count++;
1145
+ }
1146
+ if (count >= 3) {
1147
+ let trailPos = pos + count;
1148
+ while (trailPos < len && (input.charCodeAt(trailPos) === 32 || input.charCodeAt(trailPos) === 9)) {
1149
+ trailPos++;
1150
+ }
1151
+ if (trailPos >= len) {
1152
+ return { type: "hr", skip: true, hasInlineSolve: false };
1153
+ }
1154
+ }
1155
+ }
1156
+ if ((c0 === 45 || c0 === 42 || c0 === 43) && pos + 1 < len && input.charCodeAt(pos + 1) === 32) {
1157
+ if (hasInline === void 0) {
1158
+ const idx = input.indexOf("s`", pos);
1159
+ hasInline = idx !== -1 && idx < len;
1160
+ }
1161
+ return { type: "list", skip: false, hasInlineSolve: hasInline };
1162
+ }
1163
+ if (c0 >= 48 && c0 <= 57) {
1164
+ let digitPos = pos;
1165
+ while (digitPos < len && input.charCodeAt(digitPos) >= 48 && input.charCodeAt(digitPos) <= 57) {
1166
+ digitPos++;
1167
+ }
1168
+ if (digitPos < len && input.charCodeAt(digitPos) === 46) {
1169
+ if (digitPos + 1 < len && input.charCodeAt(digitPos + 1) === 32) {
1170
+ if (hasInline === void 0) {
1171
+ const idx = input.indexOf("s`", pos);
1172
+ hasInline = idx !== -1 && idx < len;
1173
+ }
1174
+ return { type: "list", skip: false, hasInlineSolve: hasInline };
1175
+ }
1176
+ }
1177
+ }
1178
+ if (c0 === 124) {
1179
+ let tPos = pos + 1;
1180
+ while (tPos < len) {
1181
+ const tc = input.charCodeAt(tPos);
1182
+ if (tc !== 45 && tc !== 58 && tc !== 124 && tc !== 32 && tc !== 9 && tc !== 13) break;
1183
+ tPos++;
1184
+ }
1185
+ if (tPos >= len) {
1186
+ return { type: "table_separator", skip: true, hasInlineSolve: false };
1187
+ }
1188
+ }
1189
+ if (c0 === 91 && pos + 1 < len && input.charCodeAt(pos + 1) === 91) {
1190
+ const closePos = input.indexOf("]]", pos + 2);
1191
+ if (closePos !== -1 && closePos < len) {
1192
+ let trailPos = closePos + 2;
1193
+ while (trailPos < len && (input.charCodeAt(trailPos) === 32 || input.charCodeAt(trailPos) === 9)) {
1194
+ trailPos++;
1195
+ }
1196
+ if (trailPos >= len) {
1197
+ return { type: "wikilink", skip: true, hasInlineSolve: false };
1198
+ }
1199
+ }
1200
+ }
1201
+ if (c0 === 33 && pos + 2 < len && input.charCodeAt(pos + 1) === 91 && input.charCodeAt(pos + 2) === 91) {
1202
+ const closePos = input.indexOf("]]", pos + 3);
1203
+ if (closePos !== -1 && closePos < len) {
1204
+ let trailPos = closePos + 2;
1205
+ while (trailPos < len && (input.charCodeAt(trailPos) === 32 || input.charCodeAt(trailPos) === 9)) {
1206
+ trailPos++;
1207
+ }
1208
+ if (trailPos >= len) {
1209
+ return { type: "wikilink", skip: true, hasInlineSolve: false };
1210
+ }
1211
+ }
1212
+ }
1213
+ if (c0 === 47 && pos + 1 < len && input.charCodeAt(pos + 1) === 47) {
1214
+ return { type: "comment", skip: true, hasInlineSolve: false };
1215
+ }
1216
+ if (c0 === 62) {
1217
+ let trail = pos + 1;
1218
+ while (trail < len && (input.charCodeAt(trail) === 32 || input.charCodeAt(trail) === 9)) trail++;
1219
+ if (trail >= len) return { type: "blockquote", skip: true, hasInlineSolve: false };
1220
+ }
1221
+ if (c0 === 45 || c0 === 42 || c0 === 43) {
1222
+ let trail = pos + 1;
1223
+ while (trail < len && (input.charCodeAt(trail) === 32 || input.charCodeAt(trail) === 9)) trail++;
1224
+ if (trail >= len) return { type: "list", skip: false, hasInlineSolve: false };
1225
+ }
1226
+ if (hasInline === void 0) {
1227
+ const idx = input.indexOf("s`", pos);
1228
+ hasInline = idx !== -1 && idx < len;
1229
+ }
1230
+ return { type: "expression", skip: false, hasInlineSolve: hasInline };
1231
+ }
1232
+ /**
1233
+ * Classify a single line of markdown text.
1234
+ */
1235
+ classifyLine(lineText) {
1236
+ const savedInput = this.input;
1237
+ const savedLen = this.len;
1238
+ const savedPos = this.pos;
1239
+ this.input = lineText;
1240
+ this.len = lineText.length;
1241
+ this.pos = 0;
1242
+ const result = this.classifyFromPositions(0, lineText.length);
1243
+ this.input = savedInput;
1244
+ this.len = savedLen;
1245
+ this.pos = savedPos;
1246
+ return result;
1247
+ }
1248
+ /**
1249
+ * Every keyword this lexer currently recognizes, locale keywords
1250
+ * (`pi`, `sqrt`, `convert`, ...) merged with any plugin-contributed ones
1251
+ * from `registerVocabulary()` (e.g. a package's custom keywords), mapped to
1252
+ * the token type they lex to. A snapshot copy, not a live reference
1253
+ * mutating the return value has no effect on the lexer.
1254
+ */
1255
+ getKeywords() {
1256
+ return Object.fromEntries(this.mergedKeywords);
1257
+ }
1258
+ /**
1259
+ * Find all inline solve markers in a line with precise coordinate mapping.
1260
+ */
1261
+ findInlineSolves(lineText) {
1262
+ const results = [];
1263
+ const len = lineText.length;
1264
+ let pos = 0;
1265
+ while (pos < len) {
1266
+ const sPos = lineText.indexOf("s`", pos);
1267
+ if (sPos === -1) break;
1268
+ const exprStart = sPos + 2;
1269
+ let exprEnd = exprStart;
1270
+ while (exprEnd < len) {
1271
+ const cc = lineText.charCodeAt(exprEnd);
1272
+ if (cc === 92 && exprEnd + 1 < len) {
1273
+ exprEnd += 2;
1274
+ continue;
1275
+ }
1276
+ if (cc === 96) break;
1277
+ exprEnd++;
1278
+ }
1279
+ if (exprEnd >= len) {
1280
+ exprEnd = len;
1281
+ }
1282
+ const expression = lineText.slice(exprStart, exprEnd);
1283
+ const end = exprEnd < len ? exprEnd + 1 : exprEnd;
1284
+ results.push({
1285
+ start: sPos,
1286
+ end,
1287
+ expression,
1288
+ columnNumber: sPos + 1
1289
+ });
1290
+ pos = end;
1291
+ }
1292
+ return results;
1293
+ }
1294
+ // ── Comment tokenizer ─────────────────────────────────────────────────
1295
+ /**
1296
+ * Reads a comment: # to end of line, or // to end of line.
1297
+ */
1298
+ tokenizeComment() {
1299
+ const input = this.input;
1300
+ const len = this.len;
1301
+ const start = this.pos;
1302
+ const startCol = start - this.lineStartPos + 1;
1303
+ let pos = this.pos;
1304
+ if (pos + 1 < len && input.charCodeAt(pos + 1) === 47) {
1305
+ pos += 2;
1306
+ } else {
1307
+ pos++;
1308
+ }
1309
+ while (pos < len) {
1310
+ const c0 = input.charCodeAt(pos);
1311
+ if (c0 === 10 || c0 === 13) break;
1312
+ pos++;
1313
+ }
1314
+ const text = input.slice(start, pos);
1315
+ this.pos = pos;
1316
+ return new LexerToken("COMMENT", tokenTypeId("COMMENT"), text, text, start, 0, this.line, startCol);
1317
+ }
1318
+ };
1319
+ _ExpressionLexer.CHAR_CLASS = buildCharClassTable();
1320
+ var ExpressionLexer = _ExpressionLexer;
1321
+
1322
+ export { ExpressionLexer, LexerToken };
1323
+ //# sourceMappingURL=chunk-XVWCOTR6.js.map
1324
+ //# sourceMappingURL=chunk-XVWCOTR6.js.map