@lokascript/semantic 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (435) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +686 -0
  3. package/dist/browser-ar.ar.global.js +2 -0
  4. package/dist/browser-core.core.global.js +2 -0
  5. package/dist/browser-de.de.global.js +2 -0
  6. package/dist/browser-east-asian.east-asian.global.js +2 -0
  7. package/dist/browser-en-tr.en-tr.global.js +2 -0
  8. package/dist/browser-en.en.global.js +2 -0
  9. package/dist/browser-es-en.es-en.global.js +2 -0
  10. package/dist/browser-es.es.global.js +2 -0
  11. package/dist/browser-fr.fr.global.js +2 -0
  12. package/dist/browser-id.id.global.js +2 -0
  13. package/dist/browser-ja.ja.global.js +2 -0
  14. package/dist/browser-ko.ko.global.js +2 -0
  15. package/dist/browser-lazy.lazy.global.js +2 -0
  16. package/dist/browser-priority.priority.global.js +2 -0
  17. package/dist/browser-pt.pt.global.js +2 -0
  18. package/dist/browser-qu.qu.global.js +2 -0
  19. package/dist/browser-sw.sw.global.js +2 -0
  20. package/dist/browser-tr.tr.global.js +2 -0
  21. package/dist/browser-western.western.global.js +2 -0
  22. package/dist/browser-zh.zh.global.js +2 -0
  23. package/dist/browser.global.js +3 -0
  24. package/dist/browser.global.js.map +1 -0
  25. package/dist/index.cjs +35051 -0
  26. package/dist/index.cjs.map +1 -0
  27. package/dist/index.d.cts +3426 -0
  28. package/dist/index.d.ts +3426 -0
  29. package/dist/index.js +34890 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/languages/ar.d.ts +78 -0
  32. package/dist/languages/ar.js +1622 -0
  33. package/dist/languages/ar.js.map +1 -0
  34. package/dist/languages/de.d.ts +38 -0
  35. package/dist/languages/de.js +1168 -0
  36. package/dist/languages/de.js.map +1 -0
  37. package/dist/languages/en.d.ts +44 -0
  38. package/dist/languages/en.js +3491 -0
  39. package/dist/languages/en.js.map +1 -0
  40. package/dist/languages/es.d.ts +52 -0
  41. package/dist/languages/es.js +1493 -0
  42. package/dist/languages/es.js.map +1 -0
  43. package/dist/languages/fr.d.ts +37 -0
  44. package/dist/languages/fr.js +1159 -0
  45. package/dist/languages/fr.js.map +1 -0
  46. package/dist/languages/id.d.ts +35 -0
  47. package/dist/languages/id.js +1152 -0
  48. package/dist/languages/id.js.map +1 -0
  49. package/dist/languages/ja.d.ts +53 -0
  50. package/dist/languages/ja.js +1430 -0
  51. package/dist/languages/ja.js.map +1 -0
  52. package/dist/languages/ko.d.ts +51 -0
  53. package/dist/languages/ko.js +1729 -0
  54. package/dist/languages/ko.js.map +1 -0
  55. package/dist/languages/pt.d.ts +37 -0
  56. package/dist/languages/pt.js +1127 -0
  57. package/dist/languages/pt.js.map +1 -0
  58. package/dist/languages/qu.d.ts +36 -0
  59. package/dist/languages/qu.js +1143 -0
  60. package/dist/languages/qu.js.map +1 -0
  61. package/dist/languages/sw.d.ts +35 -0
  62. package/dist/languages/sw.js +1147 -0
  63. package/dist/languages/sw.js.map +1 -0
  64. package/dist/languages/tr.d.ts +45 -0
  65. package/dist/languages/tr.js +1529 -0
  66. package/dist/languages/tr.js.map +1 -0
  67. package/dist/languages/zh.d.ts +58 -0
  68. package/dist/languages/zh.js +1257 -0
  69. package/dist/languages/zh.js.map +1 -0
  70. package/dist/types-C4dcj53L.d.ts +600 -0
  71. package/package.json +202 -0
  72. package/src/__test-utils__/index.ts +7 -0
  73. package/src/__test-utils__/test-helpers.ts +8 -0
  74. package/src/__types__/test-helpers.ts +122 -0
  75. package/src/analysis/index.ts +479 -0
  76. package/src/ast-builder/command-mappers.ts +1133 -0
  77. package/src/ast-builder/expression-parser/index.ts +41 -0
  78. package/src/ast-builder/expression-parser/parser.ts +563 -0
  79. package/src/ast-builder/expression-parser/tokenizer.ts +394 -0
  80. package/src/ast-builder/expression-parser/types.ts +208 -0
  81. package/src/ast-builder/index.ts +536 -0
  82. package/src/ast-builder/value-converters.ts +172 -0
  83. package/src/bridge.ts +275 -0
  84. package/src/browser-ar.ts +162 -0
  85. package/src/browser-core.ts +231 -0
  86. package/src/browser-de.ts +162 -0
  87. package/src/browser-east-asian.ts +173 -0
  88. package/src/browser-en-tr.ts +165 -0
  89. package/src/browser-en.ts +157 -0
  90. package/src/browser-es-en.ts +200 -0
  91. package/src/browser-es.ts +170 -0
  92. package/src/browser-fr.ts +162 -0
  93. package/src/browser-id.ts +162 -0
  94. package/src/browser-ja.ts +162 -0
  95. package/src/browser-ko.ts +162 -0
  96. package/src/browser-lazy.ts +189 -0
  97. package/src/browser-priority.ts +214 -0
  98. package/src/browser-pt.ts +162 -0
  99. package/src/browser-qu.ts +162 -0
  100. package/src/browser-sw.ts +162 -0
  101. package/src/browser-tr.ts +162 -0
  102. package/src/browser-western.ts +181 -0
  103. package/src/browser-zh.ts +162 -0
  104. package/src/browser.ts +268 -0
  105. package/src/cache/index.ts +14 -0
  106. package/src/cache/semantic-cache.ts +344 -0
  107. package/src/core-bridge.ts +372 -0
  108. package/src/explicit/converter.ts +258 -0
  109. package/src/explicit/index.ts +18 -0
  110. package/src/explicit/parser.ts +236 -0
  111. package/src/explicit/renderer.ts +424 -0
  112. package/src/generators/command-schemas.ts +1636 -0
  113. package/src/generators/event-handler-generator.ts +109 -0
  114. package/src/generators/index.ts +117 -0
  115. package/src/generators/language-profiles.ts +139 -0
  116. package/src/generators/pattern-generator.ts +537 -0
  117. package/src/generators/profiles/arabic.ts +131 -0
  118. package/src/generators/profiles/bengali.ts +132 -0
  119. package/src/generators/profiles/chinese.ts +124 -0
  120. package/src/generators/profiles/english.ts +113 -0
  121. package/src/generators/profiles/french.ts +125 -0
  122. package/src/generators/profiles/german.ts +126 -0
  123. package/src/generators/profiles/hindi.ts +146 -0
  124. package/src/generators/profiles/index.ts +46 -0
  125. package/src/generators/profiles/indonesian.ts +125 -0
  126. package/src/generators/profiles/italian.ts +139 -0
  127. package/src/generators/profiles/japanese.ts +149 -0
  128. package/src/generators/profiles/korean.ts +127 -0
  129. package/src/generators/profiles/marker-templates.ts +288 -0
  130. package/src/generators/profiles/ms.ts +130 -0
  131. package/src/generators/profiles/polish.ts +249 -0
  132. package/src/generators/profiles/portuguese.ts +115 -0
  133. package/src/generators/profiles/quechua.ts +113 -0
  134. package/src/generators/profiles/russian.ts +260 -0
  135. package/src/generators/profiles/spanish.ts +130 -0
  136. package/src/generators/profiles/swahili.ts +129 -0
  137. package/src/generators/profiles/thai.ts +132 -0
  138. package/src/generators/profiles/tl.ts +128 -0
  139. package/src/generators/profiles/turkish.ts +124 -0
  140. package/src/generators/profiles/types.ts +165 -0
  141. package/src/generators/profiles/ukrainian.ts +270 -0
  142. package/src/generators/profiles/vietnamese.ts +133 -0
  143. package/src/generators/schema-error-codes.ts +160 -0
  144. package/src/generators/schema-validator.ts +391 -0
  145. package/src/index.ts +429 -0
  146. package/src/language-building-schema.ts +3170 -0
  147. package/src/language-loader.ts +394 -0
  148. package/src/languages/_all.ts +65 -0
  149. package/src/languages/ar.ts +15 -0
  150. package/src/languages/bn.ts +16 -0
  151. package/src/languages/de.ts +15 -0
  152. package/src/languages/en.ts +29 -0
  153. package/src/languages/es.ts +15 -0
  154. package/src/languages/fr.ts +15 -0
  155. package/src/languages/hi.ts +26 -0
  156. package/src/languages/id.ts +15 -0
  157. package/src/languages/index.ts +18 -0
  158. package/src/languages/it.ts +15 -0
  159. package/src/languages/ja.ts +15 -0
  160. package/src/languages/ko.ts +15 -0
  161. package/src/languages/ms.ts +16 -0
  162. package/src/languages/pl.ts +18 -0
  163. package/src/languages/pt.ts +15 -0
  164. package/src/languages/qu.ts +15 -0
  165. package/src/languages/ru.ts +26 -0
  166. package/src/languages/sw.ts +15 -0
  167. package/src/languages/th.ts +16 -0
  168. package/src/languages/tl.ts +16 -0
  169. package/src/languages/tr.ts +15 -0
  170. package/src/languages/uk.ts +26 -0
  171. package/src/languages/vi.ts +16 -0
  172. package/src/languages/zh.ts +15 -0
  173. package/src/parser/index.ts +15 -0
  174. package/src/parser/pattern-matcher.ts +1181 -0
  175. package/src/parser/semantic-parser.ts +573 -0
  176. package/src/parser/utils/index.ts +35 -0
  177. package/src/parser/utils/marker-resolution.ts +111 -0
  178. package/src/parser/utils/possessive-keywords.ts +43 -0
  179. package/src/parser/utils/role-positioning.ts +70 -0
  180. package/src/parser/utils/type-validation.ts +134 -0
  181. package/src/patterns/add/ar.ts +71 -0
  182. package/src/patterns/add/bn.ts +70 -0
  183. package/src/patterns/add/hi.ts +69 -0
  184. package/src/patterns/add/index.ts +87 -0
  185. package/src/patterns/add/it.ts +61 -0
  186. package/src/patterns/add/ja.ts +93 -0
  187. package/src/patterns/add/ko.ts +74 -0
  188. package/src/patterns/add/ms.ts +30 -0
  189. package/src/patterns/add/pl.ts +62 -0
  190. package/src/patterns/add/ru.ts +62 -0
  191. package/src/patterns/add/th.ts +49 -0
  192. package/src/patterns/add/tl.ts +30 -0
  193. package/src/patterns/add/tr.ts +71 -0
  194. package/src/patterns/add/uk.ts +62 -0
  195. package/src/patterns/add/vi.ts +61 -0
  196. package/src/patterns/add/zh.ts +71 -0
  197. package/src/patterns/builders.ts +207 -0
  198. package/src/patterns/decrement/bn.ts +70 -0
  199. package/src/patterns/decrement/de.ts +42 -0
  200. package/src/patterns/decrement/hi.ts +68 -0
  201. package/src/patterns/decrement/index.ts +79 -0
  202. package/src/patterns/decrement/it.ts +69 -0
  203. package/src/patterns/decrement/ms.ts +30 -0
  204. package/src/patterns/decrement/pl.ts +58 -0
  205. package/src/patterns/decrement/ru.ts +58 -0
  206. package/src/patterns/decrement/th.ts +49 -0
  207. package/src/patterns/decrement/tl.ts +30 -0
  208. package/src/patterns/decrement/tr.ts +48 -0
  209. package/src/patterns/decrement/uk.ts +58 -0
  210. package/src/patterns/decrement/vi.ts +61 -0
  211. package/src/patterns/decrement/zh.ts +32 -0
  212. package/src/patterns/en.ts +302 -0
  213. package/src/patterns/event-handler/ar.ts +151 -0
  214. package/src/patterns/event-handler/bn.ts +72 -0
  215. package/src/patterns/event-handler/de.ts +117 -0
  216. package/src/patterns/event-handler/en.ts +117 -0
  217. package/src/patterns/event-handler/es.ts +136 -0
  218. package/src/patterns/event-handler/fr.ts +117 -0
  219. package/src/patterns/event-handler/hi.ts +64 -0
  220. package/src/patterns/event-handler/id.ts +117 -0
  221. package/src/patterns/event-handler/index.ts +119 -0
  222. package/src/patterns/event-handler/it.ts +54 -0
  223. package/src/patterns/event-handler/ja.ts +118 -0
  224. package/src/patterns/event-handler/ko.ts +133 -0
  225. package/src/patterns/event-handler/ms.ts +30 -0
  226. package/src/patterns/event-handler/pl.ts +62 -0
  227. package/src/patterns/event-handler/pt.ts +117 -0
  228. package/src/patterns/event-handler/qu.ts +66 -0
  229. package/src/patterns/event-handler/ru.ts +62 -0
  230. package/src/patterns/event-handler/shared.ts +270 -0
  231. package/src/patterns/event-handler/sw.ts +117 -0
  232. package/src/patterns/event-handler/th.ts +53 -0
  233. package/src/patterns/event-handler/tl.ts +30 -0
  234. package/src/patterns/event-handler/tr.ts +170 -0
  235. package/src/patterns/event-handler/uk.ts +62 -0
  236. package/src/patterns/event-handler/vi.ts +61 -0
  237. package/src/patterns/event-handler/zh.ts +150 -0
  238. package/src/patterns/get/ar.ts +49 -0
  239. package/src/patterns/get/bn.ts +47 -0
  240. package/src/patterns/get/de.ts +32 -0
  241. package/src/patterns/get/hi.ts +52 -0
  242. package/src/patterns/get/index.ts +83 -0
  243. package/src/patterns/get/it.ts +56 -0
  244. package/src/patterns/get/ja.ts +53 -0
  245. package/src/patterns/get/ko.ts +53 -0
  246. package/src/patterns/get/ms.ts +30 -0
  247. package/src/patterns/get/pl.ts +57 -0
  248. package/src/patterns/get/ru.ts +57 -0
  249. package/src/patterns/get/th.ts +29 -0
  250. package/src/patterns/get/tl.ts +30 -0
  251. package/src/patterns/get/uk.ts +57 -0
  252. package/src/patterns/get/vi.ts +48 -0
  253. package/src/patterns/grammar-transformed/index.ts +39 -0
  254. package/src/patterns/grammar-transformed/ja.ts +1713 -0
  255. package/src/patterns/grammar-transformed/ko.ts +1311 -0
  256. package/src/patterns/grammar-transformed/tr.ts +1067 -0
  257. package/src/patterns/hide/ar.ts +67 -0
  258. package/src/patterns/hide/bn.ts +47 -0
  259. package/src/patterns/hide/de.ts +36 -0
  260. package/src/patterns/hide/hi.ts +61 -0
  261. package/src/patterns/hide/index.ts +91 -0
  262. package/src/patterns/hide/it.ts +56 -0
  263. package/src/patterns/hide/ja.ts +69 -0
  264. package/src/patterns/hide/ko.ts +69 -0
  265. package/src/patterns/hide/ms.ts +30 -0
  266. package/src/patterns/hide/pl.ts +57 -0
  267. package/src/patterns/hide/ru.ts +57 -0
  268. package/src/patterns/hide/th.ts +29 -0
  269. package/src/patterns/hide/tl.ts +30 -0
  270. package/src/patterns/hide/tr.ts +65 -0
  271. package/src/patterns/hide/uk.ts +57 -0
  272. package/src/patterns/hide/vi.ts +56 -0
  273. package/src/patterns/hide/zh.ts +68 -0
  274. package/src/patterns/increment/bn.ts +70 -0
  275. package/src/patterns/increment/de.ts +36 -0
  276. package/src/patterns/increment/hi.ts +68 -0
  277. package/src/patterns/increment/index.ts +79 -0
  278. package/src/patterns/increment/it.ts +69 -0
  279. package/src/patterns/increment/ms.ts +30 -0
  280. package/src/patterns/increment/pl.ts +58 -0
  281. package/src/patterns/increment/ru.ts +58 -0
  282. package/src/patterns/increment/th.ts +49 -0
  283. package/src/patterns/increment/tl.ts +30 -0
  284. package/src/patterns/increment/tr.ts +52 -0
  285. package/src/patterns/increment/uk.ts +58 -0
  286. package/src/patterns/increment/vi.ts +61 -0
  287. package/src/patterns/increment/zh.ts +32 -0
  288. package/src/patterns/index.ts +84 -0
  289. package/src/patterns/languages/en/control-flow.ts +93 -0
  290. package/src/patterns/languages/en/fetch.ts +62 -0
  291. package/src/patterns/languages/en/index.ts +42 -0
  292. package/src/patterns/languages/en/repeat.ts +67 -0
  293. package/src/patterns/languages/en/set.ts +48 -0
  294. package/src/patterns/languages/en/swap.ts +38 -0
  295. package/src/patterns/languages/en/temporal.ts +57 -0
  296. package/src/patterns/put/ar.ts +74 -0
  297. package/src/patterns/put/bn.ts +53 -0
  298. package/src/patterns/put/en.ts +74 -0
  299. package/src/patterns/put/es.ts +74 -0
  300. package/src/patterns/put/hi.ts +69 -0
  301. package/src/patterns/put/id.ts +96 -0
  302. package/src/patterns/put/index.ts +99 -0
  303. package/src/patterns/put/it.ts +56 -0
  304. package/src/patterns/put/ja.ts +75 -0
  305. package/src/patterns/put/ko.ts +67 -0
  306. package/src/patterns/put/ms.ts +30 -0
  307. package/src/patterns/put/pl.ts +81 -0
  308. package/src/patterns/put/ru.ts +85 -0
  309. package/src/patterns/put/th.ts +32 -0
  310. package/src/patterns/put/tl.ts +30 -0
  311. package/src/patterns/put/tr.ts +67 -0
  312. package/src/patterns/put/uk.ts +85 -0
  313. package/src/patterns/put/vi.ts +72 -0
  314. package/src/patterns/put/zh.ts +62 -0
  315. package/src/patterns/registry.ts +163 -0
  316. package/src/patterns/remove/ar.ts +71 -0
  317. package/src/patterns/remove/bn.ts +68 -0
  318. package/src/patterns/remove/hi.ts +69 -0
  319. package/src/patterns/remove/index.ts +87 -0
  320. package/src/patterns/remove/it.ts +69 -0
  321. package/src/patterns/remove/ja.ts +74 -0
  322. package/src/patterns/remove/ko.ts +78 -0
  323. package/src/patterns/remove/ms.ts +30 -0
  324. package/src/patterns/remove/pl.ts +62 -0
  325. package/src/patterns/remove/ru.ts +62 -0
  326. package/src/patterns/remove/th.ts +49 -0
  327. package/src/patterns/remove/tl.ts +30 -0
  328. package/src/patterns/remove/tr.ts +78 -0
  329. package/src/patterns/remove/uk.ts +62 -0
  330. package/src/patterns/remove/vi.ts +61 -0
  331. package/src/patterns/remove/zh.ts +72 -0
  332. package/src/patterns/set/ar.ts +84 -0
  333. package/src/patterns/set/bn.ts +53 -0
  334. package/src/patterns/set/de.ts +84 -0
  335. package/src/patterns/set/es.ts +92 -0
  336. package/src/patterns/set/fr.ts +88 -0
  337. package/src/patterns/set/hi.ts +56 -0
  338. package/src/patterns/set/id.ts +84 -0
  339. package/src/patterns/set/index.ts +107 -0
  340. package/src/patterns/set/it.ts +56 -0
  341. package/src/patterns/set/ja.ts +86 -0
  342. package/src/patterns/set/ko.ts +85 -0
  343. package/src/patterns/set/ms.ts +30 -0
  344. package/src/patterns/set/pl.ts +57 -0
  345. package/src/patterns/set/pt.ts +84 -0
  346. package/src/patterns/set/ru.ts +57 -0
  347. package/src/patterns/set/th.ts +31 -0
  348. package/src/patterns/set/tl.ts +30 -0
  349. package/src/patterns/set/tr.ts +107 -0
  350. package/src/patterns/set/uk.ts +57 -0
  351. package/src/patterns/set/vi.ts +53 -0
  352. package/src/patterns/set/zh.ts +84 -0
  353. package/src/patterns/show/ar.ts +67 -0
  354. package/src/patterns/show/bn.ts +47 -0
  355. package/src/patterns/show/de.ts +32 -0
  356. package/src/patterns/show/fr.ts +32 -0
  357. package/src/patterns/show/hi.ts +61 -0
  358. package/src/patterns/show/index.ts +95 -0
  359. package/src/patterns/show/it.ts +56 -0
  360. package/src/patterns/show/ja.ts +69 -0
  361. package/src/patterns/show/ko.ts +73 -0
  362. package/src/patterns/show/ms.ts +30 -0
  363. package/src/patterns/show/pl.ts +57 -0
  364. package/src/patterns/show/ru.ts +57 -0
  365. package/src/patterns/show/th.ts +29 -0
  366. package/src/patterns/show/tl.ts +30 -0
  367. package/src/patterns/show/tr.ts +65 -0
  368. package/src/patterns/show/uk.ts +57 -0
  369. package/src/patterns/show/vi.ts +56 -0
  370. package/src/patterns/show/zh.ts +68 -0
  371. package/src/patterns/take/ar.ts +51 -0
  372. package/src/patterns/take/index.ts +31 -0
  373. package/src/patterns/toggle/ar.ts +61 -0
  374. package/src/patterns/toggle/bn.ts +70 -0
  375. package/src/patterns/toggle/en.ts +61 -0
  376. package/src/patterns/toggle/es.ts +61 -0
  377. package/src/patterns/toggle/hi.ts +80 -0
  378. package/src/patterns/toggle/index.ts +95 -0
  379. package/src/patterns/toggle/it.ts +69 -0
  380. package/src/patterns/toggle/ja.ts +156 -0
  381. package/src/patterns/toggle/ko.ts +113 -0
  382. package/src/patterns/toggle/ms.ts +30 -0
  383. package/src/patterns/toggle/pl.ts +62 -0
  384. package/src/patterns/toggle/ru.ts +62 -0
  385. package/src/patterns/toggle/th.ts +50 -0
  386. package/src/patterns/toggle/tl.ts +30 -0
  387. package/src/patterns/toggle/tr.ts +88 -0
  388. package/src/patterns/toggle/uk.ts +62 -0
  389. package/src/patterns/toggle/vi.ts +61 -0
  390. package/src/patterns/toggle/zh.ts +99 -0
  391. package/src/public-api.ts +286 -0
  392. package/src/registry.ts +441 -0
  393. package/src/tokenizers/arabic.ts +723 -0
  394. package/src/tokenizers/base.ts +1300 -0
  395. package/src/tokenizers/bengali.ts +289 -0
  396. package/src/tokenizers/chinese.ts +481 -0
  397. package/src/tokenizers/english.ts +416 -0
  398. package/src/tokenizers/french.ts +326 -0
  399. package/src/tokenizers/german.ts +324 -0
  400. package/src/tokenizers/hindi.ts +319 -0
  401. package/src/tokenizers/index.ts +127 -0
  402. package/src/tokenizers/indonesian.ts +306 -0
  403. package/src/tokenizers/italian.ts +458 -0
  404. package/src/tokenizers/japanese.ts +447 -0
  405. package/src/tokenizers/korean.ts +642 -0
  406. package/src/tokenizers/morphology/arabic-normalizer.ts +242 -0
  407. package/src/tokenizers/morphology/french-normalizer.ts +268 -0
  408. package/src/tokenizers/morphology/german-normalizer.ts +256 -0
  409. package/src/tokenizers/morphology/index.ts +46 -0
  410. package/src/tokenizers/morphology/italian-normalizer.ts +329 -0
  411. package/src/tokenizers/morphology/japanese-normalizer.ts +288 -0
  412. package/src/tokenizers/morphology/korean-normalizer.ts +428 -0
  413. package/src/tokenizers/morphology/polish-normalizer.ts +264 -0
  414. package/src/tokenizers/morphology/portuguese-normalizer.ts +310 -0
  415. package/src/tokenizers/morphology/spanish-normalizer.ts +327 -0
  416. package/src/tokenizers/morphology/turkish-normalizer.ts +412 -0
  417. package/src/tokenizers/morphology/types.ts +211 -0
  418. package/src/tokenizers/ms.ts +198 -0
  419. package/src/tokenizers/polish.ts +354 -0
  420. package/src/tokenizers/portuguese.ts +304 -0
  421. package/src/tokenizers/quechua.ts +339 -0
  422. package/src/tokenizers/russian.ts +375 -0
  423. package/src/tokenizers/spanish.ts +403 -0
  424. package/src/tokenizers/swahili.ts +303 -0
  425. package/src/tokenizers/thai.ts +236 -0
  426. package/src/tokenizers/tl.ts +198 -0
  427. package/src/tokenizers/turkish.ts +411 -0
  428. package/src/tokenizers/ukrainian.ts +369 -0
  429. package/src/tokenizers/vietnamese.ts +410 -0
  430. package/src/types/grammar-types.ts +617 -0
  431. package/src/types/unified-profile.ts +267 -0
  432. package/src/types.ts +709 -0
  433. package/src/utils/confidence-calculator.ts +147 -0
  434. package/src/validators/command-validator.ts +380 -0
  435. package/src/validators/index.ts +15 -0
@@ -0,0 +1,1257 @@
1
+ // src/registry.ts
2
+ var tokenizers = /* @__PURE__ */ new Map();
3
+ var profiles = /* @__PURE__ */ new Map();
4
+ var patternCache = /* @__PURE__ */ new Map();
5
+ function registerLanguage(code, tokenizer, profile) {
6
+ tokenizers.set(code, tokenizer);
7
+ profiles.set(code, profile);
8
+ patternCache.delete(code);
9
+ }
10
+
11
+ // src/tokenizers/base.ts
12
+ var TokenStreamImpl = class {
13
+ constructor(tokens, language) {
14
+ this.pos = 0;
15
+ this.tokens = tokens;
16
+ this.language = language;
17
+ }
18
+ peek(offset = 0) {
19
+ const index = this.pos + offset;
20
+ if (index < 0 || index >= this.tokens.length) {
21
+ return null;
22
+ }
23
+ return this.tokens[index];
24
+ }
25
+ advance() {
26
+ if (this.isAtEnd()) {
27
+ throw new Error("Unexpected end of token stream");
28
+ }
29
+ return this.tokens[this.pos++];
30
+ }
31
+ isAtEnd() {
32
+ return this.pos >= this.tokens.length;
33
+ }
34
+ mark() {
35
+ return { position: this.pos };
36
+ }
37
+ reset(mark) {
38
+ this.pos = mark.position;
39
+ }
40
+ position() {
41
+ return this.pos;
42
+ }
43
+ /**
44
+ * Get remaining tokens as an array.
45
+ */
46
+ remaining() {
47
+ return this.tokens.slice(this.pos);
48
+ }
49
+ /**
50
+ * Consume tokens while predicate is true.
51
+ */
52
+ takeWhile(predicate) {
53
+ const result = [];
54
+ while (!this.isAtEnd() && predicate(this.peek())) {
55
+ result.push(this.advance());
56
+ }
57
+ return result;
58
+ }
59
+ /**
60
+ * Skip tokens while predicate is true.
61
+ */
62
+ skipWhile(predicate) {
63
+ while (!this.isAtEnd() && predicate(this.peek())) {
64
+ this.advance();
65
+ }
66
+ }
67
+ };
68
+ function createPosition(start, end) {
69
+ return { start, end };
70
+ }
71
+ function createToken(value, kind, position, normalizedOrOptions) {
72
+ if (typeof normalizedOrOptions === "string") {
73
+ return { value, kind, position, normalized: normalizedOrOptions };
74
+ }
75
+ if (normalizedOrOptions) {
76
+ const { normalized, stem, stemConfidence } = normalizedOrOptions;
77
+ const token = { value, kind, position };
78
+ if (normalized !== void 0) {
79
+ token.normalized = normalized;
80
+ }
81
+ if (stem !== void 0) {
82
+ token.stem = stem;
83
+ if (stemConfidence !== void 0) {
84
+ token.stemConfidence = stemConfidence;
85
+ }
86
+ }
87
+ return token;
88
+ }
89
+ return { value, kind, position };
90
+ }
91
+ function isWhitespace(char) {
92
+ return /\s/.test(char);
93
+ }
94
+ function isSelectorStart(char) {
95
+ return char === "#" || char === "." || char === "[" || char === "@" || char === "*" || char === "<";
96
+ }
97
+ function isQuote(char) {
98
+ return char === '"' || char === "'" || char === "`" || char === "\u300C" || char === "\u300D";
99
+ }
100
+ function isDigit(char) {
101
+ return /\d/.test(char);
102
+ }
103
+ function isAsciiLetter(char) {
104
+ return /[a-zA-Z]/.test(char);
105
+ }
106
+ function isAsciiIdentifierChar(char) {
107
+ return /[a-zA-Z0-9_-]/.test(char);
108
+ }
109
+ function createUnicodeRangeClassifier(ranges) {
110
+ return (char) => {
111
+ const code = char.charCodeAt(0);
112
+ return ranges.some(([start, end]) => code >= start && code <= end);
113
+ };
114
+ }
115
+ function extractCssSelector(input, startPos) {
116
+ if (startPos >= input.length) return null;
117
+ const char = input[startPos];
118
+ if (!isSelectorStart(char)) return null;
119
+ let pos = startPos;
120
+ let selector = "";
121
+ if (char === "#" || char === ".") {
122
+ selector += input[pos++];
123
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
124
+ selector += input[pos++];
125
+ }
126
+ if (selector.length <= 1) return null;
127
+ if (pos < input.length && input[pos] === "." && char === "#") {
128
+ const methodStart = pos + 1;
129
+ let methodEnd = methodStart;
130
+ while (methodEnd < input.length && isAsciiIdentifierChar(input[methodEnd])) {
131
+ methodEnd++;
132
+ }
133
+ if (methodEnd < input.length && input[methodEnd] === "(") {
134
+ return selector;
135
+ }
136
+ }
137
+ } else if (char === "[") {
138
+ let depth = 1;
139
+ let inQuote = false;
140
+ let quoteChar = null;
141
+ let escaped = false;
142
+ selector += input[pos++];
143
+ while (pos < input.length && depth > 0) {
144
+ const c = input[pos];
145
+ selector += c;
146
+ if (escaped) {
147
+ escaped = false;
148
+ } else if (c === "\\") {
149
+ escaped = true;
150
+ } else if (inQuote) {
151
+ if (c === quoteChar) {
152
+ inQuote = false;
153
+ quoteChar = null;
154
+ }
155
+ } else {
156
+ if (c === '"' || c === "'" || c === "`") {
157
+ inQuote = true;
158
+ quoteChar = c;
159
+ } else if (c === "[") {
160
+ depth++;
161
+ } else if (c === "]") {
162
+ depth--;
163
+ }
164
+ }
165
+ pos++;
166
+ }
167
+ if (depth !== 0) return null;
168
+ } else if (char === "@") {
169
+ selector += input[pos++];
170
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
171
+ selector += input[pos++];
172
+ }
173
+ if (selector.length <= 1) return null;
174
+ } else if (char === "*") {
175
+ selector += input[pos++];
176
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
177
+ selector += input[pos++];
178
+ }
179
+ if (selector.length <= 1) return null;
180
+ } else if (char === "<") {
181
+ selector += input[pos++];
182
+ if (pos >= input.length || !isAsciiLetter(input[pos])) return null;
183
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
184
+ selector += input[pos++];
185
+ }
186
+ while (pos < input.length) {
187
+ const modChar = input[pos];
188
+ if (modChar === ".") {
189
+ selector += input[pos++];
190
+ if (pos >= input.length || !isAsciiIdentifierChar(input[pos])) {
191
+ return null;
192
+ }
193
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
194
+ selector += input[pos++];
195
+ }
196
+ } else if (modChar === "#") {
197
+ selector += input[pos++];
198
+ if (pos >= input.length || !isAsciiIdentifierChar(input[pos])) {
199
+ return null;
200
+ }
201
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
202
+ selector += input[pos++];
203
+ }
204
+ } else if (modChar === "[") {
205
+ let depth = 1;
206
+ let inQuote = false;
207
+ let quoteChar = null;
208
+ let escaped = false;
209
+ selector += input[pos++];
210
+ while (pos < input.length && depth > 0) {
211
+ const c = input[pos];
212
+ selector += c;
213
+ if (escaped) {
214
+ escaped = false;
215
+ } else if (c === "\\") {
216
+ escaped = true;
217
+ } else if (inQuote) {
218
+ if (c === quoteChar) {
219
+ inQuote = false;
220
+ quoteChar = null;
221
+ }
222
+ } else {
223
+ if (c === '"' || c === "'" || c === "`") {
224
+ inQuote = true;
225
+ quoteChar = c;
226
+ } else if (c === "[") {
227
+ depth++;
228
+ } else if (c === "]") {
229
+ depth--;
230
+ }
231
+ }
232
+ pos++;
233
+ }
234
+ if (depth !== 0) return null;
235
+ } else {
236
+ break;
237
+ }
238
+ }
239
+ while (pos < input.length && isWhitespace(input[pos])) {
240
+ selector += input[pos++];
241
+ }
242
+ if (pos < input.length && input[pos] === "/") {
243
+ selector += input[pos++];
244
+ while (pos < input.length && isWhitespace(input[pos])) {
245
+ selector += input[pos++];
246
+ }
247
+ }
248
+ if (pos >= input.length || input[pos] !== ">") return null;
249
+ selector += input[pos++];
250
+ }
251
+ return selector || null;
252
+ }
253
+ function isPossessiveMarker(input, pos) {
254
+ if (pos >= input.length || input[pos] !== "'") return false;
255
+ if (pos + 1 >= input.length) return false;
256
+ const nextChar = input[pos + 1].toLowerCase();
257
+ if (nextChar !== "s") return false;
258
+ if (pos + 2 >= input.length) return true;
259
+ const afterS = input[pos + 2];
260
+ return isWhitespace(afterS) || afterS === "*" || !isAsciiIdentifierChar(afterS);
261
+ }
262
+ function extractStringLiteral(input, startPos) {
263
+ if (startPos >= input.length) return null;
264
+ const openQuote = input[startPos];
265
+ if (!isQuote(openQuote)) return null;
266
+ if (openQuote === "'" && isPossessiveMarker(input, startPos)) {
267
+ return null;
268
+ }
269
+ const closeQuoteMap = {
270
+ '"': '"',
271
+ "'": "'",
272
+ "`": "`",
273
+ "\u300C": "\u300D"
274
+ };
275
+ const closeQuote = closeQuoteMap[openQuote];
276
+ if (!closeQuote) return null;
277
+ let pos = startPos + 1;
278
+ let literal = openQuote;
279
+ let escaped = false;
280
+ while (pos < input.length) {
281
+ const char = input[pos];
282
+ literal += char;
283
+ if (escaped) {
284
+ escaped = false;
285
+ } else if (char === "\\") {
286
+ escaped = true;
287
+ } else if (char === closeQuote) {
288
+ return literal;
289
+ }
290
+ pos++;
291
+ }
292
+ return literal;
293
+ }
294
+ function isUrlStart(input, pos) {
295
+ if (pos >= input.length) return false;
296
+ const char = input[pos];
297
+ const next = input[pos + 1] || "";
298
+ const third = input[pos + 2] || "";
299
+ if (char === "/" && next !== "/" && /[a-zA-Z0-9._-]/.test(next)) {
300
+ return true;
301
+ }
302
+ if (char === "/" && next === "/" && /[a-zA-Z]/.test(third)) {
303
+ return true;
304
+ }
305
+ if (char === "." && (next === "/" || next === "." && third === "/")) {
306
+ return true;
307
+ }
308
+ const slice = input.slice(pos, pos + 8).toLowerCase();
309
+ if (slice.startsWith("http://") || slice.startsWith("https://")) {
310
+ return true;
311
+ }
312
+ return false;
313
+ }
314
+ function extractUrl(input, startPos) {
315
+ if (!isUrlStart(input, startPos)) return null;
316
+ let pos = startPos;
317
+ let url = "";
318
+ const urlChars = /[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;
319
+ while (pos < input.length) {
320
+ const char = input[pos];
321
+ if (char === "#") {
322
+ if (url.length > 0 && /[a-zA-Z0-9/.]$/.test(url)) {
323
+ url += char;
324
+ pos++;
325
+ while (pos < input.length && /[a-zA-Z0-9_-]/.test(input[pos])) {
326
+ url += input[pos++];
327
+ }
328
+ }
329
+ break;
330
+ }
331
+ if (urlChars.test(char)) {
332
+ url += char;
333
+ pos++;
334
+ } else {
335
+ break;
336
+ }
337
+ }
338
+ if (url.length < 2) return null;
339
+ return url;
340
+ }
341
+ function extractNumber(input, startPos) {
342
+ if (startPos >= input.length) return null;
343
+ const char = input[startPos];
344
+ if (!isDigit(char) && char !== "-" && char !== "+") return null;
345
+ let pos = startPos;
346
+ let number = "";
347
+ if (input[pos] === "-" || input[pos] === "+") {
348
+ number += input[pos++];
349
+ }
350
+ if (pos >= input.length || !isDigit(input[pos])) {
351
+ return null;
352
+ }
353
+ while (pos < input.length && isDigit(input[pos])) {
354
+ number += input[pos++];
355
+ }
356
+ if (pos < input.length && input[pos] === ".") {
357
+ number += input[pos++];
358
+ while (pos < input.length && isDigit(input[pos])) {
359
+ number += input[pos++];
360
+ }
361
+ }
362
+ if (pos < input.length) {
363
+ const suffix = input.slice(pos, pos + 2);
364
+ if (suffix === "ms") {
365
+ number += "ms";
366
+ } else if (input[pos] === "s" || input[pos] === "m" || input[pos] === "h") {
367
+ number += input[pos];
368
+ }
369
+ }
370
+ return number;
371
+ }
372
+ var _BaseTokenizer = class _BaseTokenizer {
373
+ constructor() {
374
+ /** Keywords derived from profile, sorted longest-first for greedy matching */
375
+ this.profileKeywords = [];
376
+ /** Map for O(1) keyword lookups by lowercase native word */
377
+ this.profileKeywordMap = /* @__PURE__ */ new Map();
378
+ }
379
+ /**
380
+ * Initialize keyword mappings from a language profile.
381
+ * Builds a list of native→english mappings from:
382
+ * - profile.keywords (primary + alternatives)
383
+ * - profile.references (me, it, you, etc.)
384
+ * - profile.roleMarkers (into, from, with, etc.)
385
+ *
386
+ * Results are sorted longest-first for greedy matching (important for non-space languages).
387
+ * Extras take precedence over profile entries when there are duplicates.
388
+ *
389
+ * @param profile - Language profile containing keyword translations
390
+ * @param extras - Additional keyword entries to include (literals, positional, events)
391
+ */
392
+ initializeKeywordsFromProfile(profile, extras = []) {
393
+ const keywordMap = /* @__PURE__ */ new Map();
394
+ if (profile.keywords) {
395
+ for (const [normalized, translation] of Object.entries(profile.keywords)) {
396
+ keywordMap.set(translation.primary, {
397
+ native: translation.primary,
398
+ normalized: translation.normalized || normalized
399
+ });
400
+ if (translation.alternatives) {
401
+ for (const alt of translation.alternatives) {
402
+ keywordMap.set(alt, {
403
+ native: alt,
404
+ normalized: translation.normalized || normalized
405
+ });
406
+ }
407
+ }
408
+ }
409
+ }
410
+ if (profile.references) {
411
+ for (const [normalized, native] of Object.entries(profile.references)) {
412
+ keywordMap.set(native, { native, normalized });
413
+ }
414
+ }
415
+ if (profile.roleMarkers) {
416
+ for (const [role, marker] of Object.entries(profile.roleMarkers)) {
417
+ if (marker.primary) {
418
+ keywordMap.set(marker.primary, { native: marker.primary, normalized: role });
419
+ }
420
+ if (marker.alternatives) {
421
+ for (const alt of marker.alternatives) {
422
+ keywordMap.set(alt, { native: alt, normalized: role });
423
+ }
424
+ }
425
+ }
426
+ }
427
+ for (const extra of extras) {
428
+ keywordMap.set(extra.native, extra);
429
+ }
430
+ this.profileKeywords = Array.from(keywordMap.values()).sort(
431
+ (a, b) => b.native.length - a.native.length
432
+ );
433
+ this.profileKeywordMap = /* @__PURE__ */ new Map();
434
+ for (const keyword of this.profileKeywords) {
435
+ this.profileKeywordMap.set(keyword.native.toLowerCase(), keyword);
436
+ const normalized = this.removeDiacritics(keyword.native);
437
+ if (normalized !== keyword.native && !this.profileKeywordMap.has(normalized.toLowerCase())) {
438
+ this.profileKeywordMap.set(normalized.toLowerCase(), keyword);
439
+ }
440
+ }
441
+ }
442
+ /**
443
+ * Remove diacritical marks from a word for normalization.
444
+ * Primarily for Arabic (shadda, fatha, kasra, damma, sukun, etc.)
445
+ * but could be extended for other languages.
446
+ *
447
+ * @param word - Word to normalize
448
+ * @returns Word without diacritics
449
+ */
450
+ removeDiacritics(word) {
451
+ return word.replace(/[\u064B-\u0652\u0670]/g, "");
452
+ }
453
+ /**
454
+ * Try to match a keyword from profile at the current position.
455
+ * Uses longest-first greedy matching (important for non-space languages).
456
+ *
457
+ * @param input - Input string
458
+ * @param pos - Current position
459
+ * @returns Token if matched, null otherwise
460
+ */
461
+ tryProfileKeyword(input, pos) {
462
+ for (const entry of this.profileKeywords) {
463
+ if (input.slice(pos).startsWith(entry.native)) {
464
+ return createToken(
465
+ entry.native,
466
+ "keyword",
467
+ createPosition(pos, pos + entry.native.length),
468
+ entry.normalized
469
+ );
470
+ }
471
+ }
472
+ return null;
473
+ }
474
+ /**
475
+ * Check if the remaining input starts with any known keyword.
476
+ * Useful for non-space languages to detect word boundaries.
477
+ *
478
+ * @param input - Input string
479
+ * @param pos - Current position
480
+ * @returns true if a keyword starts at this position
481
+ */
482
+ isKeywordStart(input, pos) {
483
+ const remaining = input.slice(pos);
484
+ return this.profileKeywords.some((entry) => remaining.startsWith(entry.native));
485
+ }
486
+ /**
487
+ * Look up a keyword by native word (case-insensitive).
488
+ * O(1) lookup using the keyword map.
489
+ *
490
+ * @param native - Native word to look up
491
+ * @returns KeywordEntry if found, undefined otherwise
492
+ */
493
+ lookupKeyword(native) {
494
+ return this.profileKeywordMap.get(native.toLowerCase());
495
+ }
496
+ /**
497
+ * Check if a word is a known keyword (case-insensitive).
498
+ * O(1) lookup using the keyword map.
499
+ *
500
+ * @param native - Native word to check
501
+ * @returns true if the word is a keyword
502
+ */
503
+ isKeyword(native) {
504
+ return this.profileKeywordMap.has(native.toLowerCase());
505
+ }
506
+ /**
507
+ * Set the morphological normalizer for this tokenizer.
508
+ */
509
+ setNormalizer(normalizer) {
510
+ this.normalizer = normalizer;
511
+ }
512
+ /**
513
+ * Try to normalize a word using the morphological normalizer.
514
+ * Returns null if no normalizer is set or normalization fails.
515
+ *
516
+ * Note: We don't check isNormalizable() here because the individual tokenizers
517
+ * historically called normalize() directly without that check. The normalize()
518
+ * method itself handles returning noChange() for words that can't be normalized.
519
+ */
520
+ tryNormalize(word) {
521
+ if (!this.normalizer) return null;
522
+ const result = this.normalizer.normalize(word);
523
+ if (result.stem !== word && result.confidence >= 0.7) {
524
+ return result;
525
+ }
526
+ return null;
527
+ }
528
+ /**
529
+ * Try morphological normalization and keyword lookup.
530
+ *
531
+ * If the word can be normalized to a stem that matches a known keyword,
532
+ * returns a keyword token with morphological metadata (stem, stemConfidence).
533
+ *
534
+ * This is the common pattern for handling conjugated verbs across languages:
535
+ * 1. Normalize the word (e.g., "toggled" → "toggle")
536
+ * 2. Look up the stem in the keyword map
537
+ * 3. Create a token with both the original form and stem metadata
538
+ *
539
+ * @param word - The word to normalize and look up
540
+ * @param startPos - Start position for the token
541
+ * @param endPos - End position for the token
542
+ * @returns Token if stem matches a keyword, null otherwise
543
+ */
544
+ tryMorphKeywordMatch(word, startPos, endPos) {
545
+ const result = this.tryNormalize(word);
546
+ if (!result) return null;
547
+ const stemEntry = this.lookupKeyword(result.stem);
548
+ if (!stemEntry) return null;
549
+ const tokenOptions = {
550
+ normalized: stemEntry.normalized,
551
+ stem: result.stem,
552
+ stemConfidence: result.confidence
553
+ };
554
+ return createToken(word, "keyword", createPosition(startPos, endPos), tokenOptions);
555
+ }
556
+ /**
557
+ * Try to extract a CSS selector at the current position.
558
+ */
559
+ trySelector(input, pos) {
560
+ const selector = extractCssSelector(input, pos);
561
+ if (selector) {
562
+ return createToken(selector, "selector", createPosition(pos, pos + selector.length));
563
+ }
564
+ return null;
565
+ }
566
+ /**
567
+ * Try to extract an event modifier at the current position.
568
+ * Event modifiers are .once, .debounce(N), .throttle(N), .queue(strategy)
569
+ */
570
+ tryEventModifier(input, pos) {
571
+ if (input[pos] !== ".") {
572
+ return null;
573
+ }
574
+ const match = input.slice(pos).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);
575
+ if (!match) {
576
+ return null;
577
+ }
578
+ const fullMatch = match[0].replace(/(\s|\.)$/, "");
579
+ const modifierName = fullMatch.slice(1).split("(")[0];
580
+ const value = match[1];
581
+ const token = createToken(
582
+ fullMatch,
583
+ "event-modifier",
584
+ createPosition(pos, pos + fullMatch.length)
585
+ );
586
+ return {
587
+ ...token,
588
+ metadata: {
589
+ modifierName,
590
+ value: value ? modifierName === "queue" ? value : parseInt(value, 10) : void 0
591
+ }
592
+ };
593
+ }
594
+ /**
595
+ * Try to extract a string literal at the current position.
596
+ */
597
+ tryString(input, pos) {
598
+ const literal = extractStringLiteral(input, pos);
599
+ if (literal) {
600
+ return createToken(literal, "literal", createPosition(pos, pos + literal.length));
601
+ }
602
+ return null;
603
+ }
604
+ /**
605
+ * Try to extract a number at the current position.
606
+ */
607
+ tryNumber(input, pos) {
608
+ const number = extractNumber(input, pos);
609
+ if (number) {
610
+ return createToken(number, "literal", createPosition(pos, pos + number.length));
611
+ }
612
+ return null;
613
+ }
614
+ /**
615
+ * Try to match a time unit from a list of patterns.
616
+ *
617
+ * @param input - Input string
618
+ * @param pos - Position after the number
619
+ * @param timeUnits - Array of time unit mappings (native pattern → standard suffix)
620
+ * @param skipWhitespace - Whether to skip whitespace before time unit (default: false)
621
+ * @returns Object with matched suffix and new position, or null if no match
622
+ */
623
+ tryMatchTimeUnit(input, pos, timeUnits, skipWhitespace = false) {
624
+ let unitPos = pos;
625
+ if (skipWhitespace) {
626
+ while (unitPos < input.length && isWhitespace(input[unitPos])) {
627
+ unitPos++;
628
+ }
629
+ }
630
+ const remaining = input.slice(unitPos);
631
+ for (const unit of timeUnits) {
632
+ const candidate = remaining.slice(0, unit.length);
633
+ const matches = unit.caseInsensitive ? candidate.toLowerCase() === unit.pattern.toLowerCase() : candidate === unit.pattern;
634
+ if (matches) {
635
+ if (unit.notFollowedBy) {
636
+ const nextChar = remaining[unit.length] || "";
637
+ if (nextChar === unit.notFollowedBy) continue;
638
+ }
639
+ if (unit.checkBoundary) {
640
+ const nextChar = remaining[unit.length] || "";
641
+ if (isAsciiIdentifierChar(nextChar)) continue;
642
+ }
643
+ return { suffix: unit.suffix, endPos: unitPos + unit.length };
644
+ }
645
+ }
646
+ return null;
647
+ }
648
+ /**
649
+ * Parse a base number (sign, integer, decimal) without time units.
650
+ * Returns the number string and end position.
651
+ *
652
+ * @param input - Input string
653
+ * @param startPos - Start position
654
+ * @param allowSign - Whether to allow +/- sign (default: true)
655
+ * @returns Object with number string and end position, or null
656
+ */
657
+ parseBaseNumber(input, startPos, allowSign = true) {
658
+ let pos = startPos;
659
+ let number = "";
660
+ if (allowSign && (input[pos] === "-" || input[pos] === "+")) {
661
+ number += input[pos++];
662
+ }
663
+ if (pos >= input.length || !isDigit(input[pos])) {
664
+ return null;
665
+ }
666
+ while (pos < input.length && isDigit(input[pos])) {
667
+ number += input[pos++];
668
+ }
669
+ if (pos < input.length && input[pos] === ".") {
670
+ number += input[pos++];
671
+ while (pos < input.length && isDigit(input[pos])) {
672
+ number += input[pos++];
673
+ }
674
+ }
675
+ if (!number || number === "-" || number === "+") return null;
676
+ return { number, endPos: pos };
677
+ }
678
+ /**
679
+ * Try to extract a number with native language time units.
680
+ *
681
+ * This is a template method that handles the common pattern:
682
+ * 1. Parse the base number (sign, integer, decimal)
683
+ * 2. Try to match native language time units
684
+ * 3. Fall back to standard time units (ms, s, m, h)
685
+ *
686
+ * @param input - Input string
687
+ * @param pos - Start position
688
+ * @param nativeTimeUnits - Language-specific time unit mappings
689
+ * @param options - Configuration options
690
+ * @returns Token if number found, null otherwise
691
+ */
692
+ tryNumberWithTimeUnits(input, pos, nativeTimeUnits, options = {}) {
693
+ const { allowSign = true, skipWhitespace = false } = options;
694
+ const baseResult = this.parseBaseNumber(input, pos, allowSign);
695
+ if (!baseResult) return null;
696
+ let { number, endPos } = baseResult;
697
+ const allUnits = [...nativeTimeUnits, ..._BaseTokenizer.STANDARD_TIME_UNITS];
698
+ const timeMatch = this.tryMatchTimeUnit(input, endPos, allUnits, skipWhitespace);
699
+ if (timeMatch) {
700
+ number += timeMatch.suffix;
701
+ endPos = timeMatch.endPos;
702
+ }
703
+ return createToken(number, "literal", createPosition(pos, endPos));
704
+ }
705
+ /**
706
+ * Try to extract a URL at the current position.
707
+ * Handles /path, ./path, ../path, //domain.com, http://, https://
708
+ */
709
+ tryUrl(input, pos) {
710
+ const url = extractUrl(input, pos);
711
+ if (url) {
712
+ return createToken(url, "url", createPosition(pos, pos + url.length));
713
+ }
714
+ return null;
715
+ }
716
+ /**
717
+ * Try to extract a variable reference (:varname) at the current position.
718
+ * In hyperscript, :x refers to a local variable named x.
719
+ */
720
+ tryVariableRef(input, pos) {
721
+ if (input[pos] !== ":") return null;
722
+ if (pos + 1 >= input.length) return null;
723
+ if (!isAsciiIdentifierChar(input[pos + 1])) return null;
724
+ let endPos = pos + 1;
725
+ while (endPos < input.length && isAsciiIdentifierChar(input[endPos])) {
726
+ endPos++;
727
+ }
728
+ const varRef = input.slice(pos, endPos);
729
+ return createToken(varRef, "identifier", createPosition(pos, endPos));
730
+ }
731
+ /**
732
+ * Try to extract an operator or punctuation token at the current position.
733
+ * Handles two-character operators (==, !=, etc.) and single-character operators.
734
+ */
735
+ tryOperator(input, pos) {
736
+ const twoChar = input.slice(pos, pos + 2);
737
+ if (["==", "!=", "<=", ">=", "&&", "||", "->"].includes(twoChar)) {
738
+ return createToken(twoChar, "operator", createPosition(pos, pos + 2));
739
+ }
740
+ const oneChar = input[pos];
741
+ if (["<", ">", "!", "+", "-", "*", "/", "="].includes(oneChar)) {
742
+ return createToken(oneChar, "operator", createPosition(pos, pos + 1));
743
+ }
744
+ if (["(", ")", "{", "}", ",", ";", ":"].includes(oneChar)) {
745
+ return createToken(oneChar, "punctuation", createPosition(pos, pos + 1));
746
+ }
747
+ return null;
748
+ }
749
+ /**
750
+ * Try to match a multi-character particle from a list.
751
+ *
752
+ * Used by languages like Japanese, Korean, and Chinese that have
753
+ * multi-character particles (e.g., Japanese から, まで, より).
754
+ *
755
+ * @param input - Input string
756
+ * @param pos - Current position
757
+ * @param particles - Array of multi-character particles to match
758
+ * @returns Token if matched, null otherwise
759
+ */
760
+ tryMultiCharParticle(input, pos, particles) {
761
+ for (const particle of particles) {
762
+ if (input.slice(pos, pos + particle.length) === particle) {
763
+ return createToken(particle, "particle", createPosition(pos, pos + particle.length));
764
+ }
765
+ }
766
+ return null;
767
+ }
768
+ };
769
+ /**
770
+ * Configuration for native language time units.
771
+ * Maps patterns to their standard suffix (ms, s, m, h).
772
+ */
773
+ _BaseTokenizer.STANDARD_TIME_UNITS = [
774
+ { pattern: "ms", suffix: "ms", length: 2 },
775
+ { pattern: "s", suffix: "s", length: 1, checkBoundary: true },
776
+ { pattern: "m", suffix: "m", length: 1, checkBoundary: true, notFollowedBy: "s" },
777
+ { pattern: "h", suffix: "h", length: 1, checkBoundary: true }
778
+ ];
779
+ var BaseTokenizer = _BaseTokenizer;
780
+
781
+ // src/generators/profiles/chinese.ts
782
+ var chineseProfile = {
783
+ code: "zh",
784
+ name: "Chinese",
785
+ nativeName: "\u4E2D\u6587",
786
+ direction: "ltr",
787
+ wordOrder: "SVO",
788
+ markingStrategy: "preposition",
789
+ // Uses prepositions but often implicit
790
+ usesSpaces: false,
791
+ verb: {
792
+ position: "second",
793
+ subjectDrop: true
794
+ },
795
+ references: {
796
+ me: "\u6211",
797
+ // "I/me"
798
+ it: "\u5B83",
799
+ // "it"
800
+ you: "\u4F60",
801
+ // "you"
802
+ result: "\u7ED3\u679C",
803
+ event: "\u4E8B\u4EF6",
804
+ target: "\u76EE\u6807",
805
+ body: "\u4E3B\u4F53"
806
+ },
807
+ possessive: {
808
+ marker: "\u7684",
809
+ // Possessive particle (de)
810
+ markerPosition: "between",
811
+ // Chinese: 我的 value (wǒ de value) = "my value"
812
+ keywords: {
813
+ // Compound possessive forms (pronoun + 的)
814
+ \u6211\u7684: "me",
815
+ // wǒ de (my)
816
+ \u4F60\u7684: "you",
817
+ // nǐ de (your)
818
+ \u5B83\u7684: "it",
819
+ // tā de (its)
820
+ \u4ED6\u7684: "it",
821
+ // tā de (his)
822
+ \u5979\u7684: "it"
823
+ // tā de (her)
824
+ }
825
+ },
826
+ roleMarkers: {
827
+ destination: { primary: "\u5728", alternatives: ["\u5230", "\u4E8E"], position: "before" },
828
+ source: { primary: "\u4ECE", alternatives: ["\u7531"], position: "before" },
829
+ patient: { primary: "\u628A", position: "before" },
830
+ // BA construction
831
+ style: { primary: "\u7528", alternatives: ["\u4EE5"], position: "before" }
832
+ },
833
+ keywords: {
834
+ // Class/Attribute operations
835
+ toggle: { primary: "\u5207\u6362", normalized: "toggle" },
836
+ add: { primary: "\u6DFB\u52A0", alternatives: ["\u52A0"], normalized: "add" },
837
+ remove: { primary: "\u79FB\u9664", alternatives: ["\u5220\u9664", "\u53BB\u6389"], normalized: "remove" },
838
+ // Content operations
839
+ put: { primary: "\u653E\u7F6E", alternatives: ["\u653E", "\u653E\u5165"], normalized: "put" },
840
+ append: { primary: "\u8FFD\u52A0", alternatives: ["\u9644\u52A0"], normalized: "append" },
841
+ prepend: { primary: "\u524D\u7F6E", alternatives: ["\u9884\u7F6E"], normalized: "prepend" },
842
+ take: { primary: "\u83B7\u53D6", normalized: "take" },
843
+ make: { primary: "\u5236\u4F5C", normalized: "make" },
844
+ clone: { primary: "\u590D\u5236", normalized: "clone" },
845
+ swap: { primary: "\u4EA4\u6362", normalized: "swap" },
846
+ morph: { primary: "\u53D8\u5F62", alternatives: ["\u8F6C\u6362"], normalized: "morph" },
847
+ // Variable operations
848
+ set: { primary: "\u8BBE\u7F6E", alternatives: ["\u8BBE\u5B9A"], normalized: "set" },
849
+ get: { primary: "\u83B7\u5F97", alternatives: ["\u83B7\u53D6", "\u53D6\u5F97"], normalized: "get" },
850
+ increment: { primary: "\u589E\u52A0", normalized: "increment" },
851
+ decrement: { primary: "\u51CF\u5C11", normalized: "decrement" },
852
+ log: { primary: "\u65E5\u5FD7", normalized: "log" },
853
+ // Visibility
854
+ show: { primary: "\u663E\u793A", alternatives: ["\u5C55\u793A"], normalized: "show" },
855
+ hide: { primary: "\u9690\u85CF", normalized: "hide" },
856
+ transition: { primary: "\u8FC7\u6E21", normalized: "transition" },
857
+ // Events
858
+ on: { primary: "\u5F53", alternatives: ["\u5728...\u65F6"], normalized: "on" },
859
+ trigger: { primary: "\u89E6\u53D1", normalized: "trigger" },
860
+ send: { primary: "\u53D1\u9001", normalized: "send" },
861
+ // DOM focus
862
+ focus: { primary: "\u805A\u7126", normalized: "focus" },
863
+ blur: { primary: "\u5931\u7126", normalized: "blur" },
864
+ // Navigation
865
+ go: { primary: "\u524D\u5F80", normalized: "go" },
866
+ // Async
867
+ wait: { primary: "\u7B49\u5F85", normalized: "wait" },
868
+ fetch: { primary: "\u83B7\u53D6", normalized: "fetch" },
869
+ settle: { primary: "\u7A33\u5B9A", normalized: "settle" },
870
+ // Control flow
871
+ if: { primary: "\u5982\u679C", normalized: "if" },
872
+ when: { primary: "\u5F53", normalized: "when" },
873
+ where: { primary: "\u54EA\u91CC", normalized: "where" },
874
+ else: { primary: "\u5426\u5219", normalized: "else" },
875
+ repeat: { primary: "\u91CD\u590D", normalized: "repeat" },
876
+ for: { primary: "\u4E3A", normalized: "for" },
877
+ while: { primary: "\u5F53", normalized: "while" },
878
+ continue: { primary: "\u7EE7\u7EED", normalized: "continue" },
879
+ halt: { primary: "\u505C\u6B62", normalized: "halt" },
880
+ throw: { primary: "\u629B\u51FA", normalized: "throw" },
881
+ call: { primary: "\u8C03\u7528", normalized: "call" },
882
+ return: { primary: "\u8FD4\u56DE", normalized: "return" },
883
+ then: { primary: "\u7136\u540E", alternatives: ["\u63A5\u7740", "\u4E4B\u540E"], normalized: "then" },
884
+ and: { primary: "\u5E76\u4E14", alternatives: ["\u548C", "\u800C\u4E14"], normalized: "and" },
885
+ end: { primary: "\u7ED3\u675F", alternatives: ["\u7EC8\u6B62", "\u5B8C"], normalized: "end" },
886
+ // Advanced
887
+ js: { primary: "JS\u6267\u884C", alternatives: ["js"], normalized: "js" },
888
+ async: { primary: "\u5F02\u6B65", normalized: "async" },
889
+ tell: { primary: "\u544A\u8BC9", normalized: "tell" },
890
+ default: { primary: "\u9ED8\u8BA4", normalized: "default" },
891
+ init: { primary: "\u521D\u59CB\u5316", normalized: "init" },
892
+ behavior: { primary: "\u884C\u4E3A", normalized: "behavior" },
893
+ install: { primary: "\u5B89\u88C5", normalized: "install" },
894
+ measure: { primary: "\u6D4B\u91CF", normalized: "measure" },
895
+ // Modifiers
896
+ into: { primary: "\u8FDB\u5165", normalized: "into" },
897
+ before: { primary: "\u4E4B\u524D", normalized: "before" },
898
+ after: { primary: "\u4E4B\u540E", normalized: "after" },
899
+ // Event modifiers (for repeat until event)
900
+ until: { primary: "\u76F4\u5230", normalized: "until" },
901
+ event: { primary: "\u4E8B\u4EF6", normalized: "event" },
902
+ from: { primary: "\u4ECE", normalized: "from" }
903
+ },
904
+ tokenization: {
905
+ boundaryStrategy: "character"
906
+ }
907
+ };
908
+
909
+ // src/tokenizers/chinese.ts
910
+ var isChinese = createUnicodeRangeClassifier([
911
+ [19968, 40959],
912
+ // CJK Unified Ideographs
913
+ [13312, 19903],
914
+ // CJK Unified Ideographs Extension A
915
+ [131072, 173791],
916
+ // CJK Unified Ideographs Extension B
917
+ [63744, 64255],
918
+ // CJK Compatibility Ideographs
919
+ [194560, 195103]
920
+ // CJK Compatibility Ideographs Supplement
921
+ ]);
922
+ var PARTICLES = /* @__PURE__ */ new Set([
923
+ "\u628A",
924
+ // ba - marks direct object (BA construction)
925
+ "\u5728",
926
+ // zai - at, in, on (location)
927
+ "\u4ECE",
928
+ // cong - from
929
+ "\u5230",
930
+ // dao - to, until
931
+ "\u5411",
932
+ // xiang - towards
933
+ "\u7ED9",
934
+ // gei - to, for (recipient)
935
+ "\u5BF9",
936
+ // dui - to, towards
937
+ "\u7528",
938
+ // yong - with, using
939
+ "\u88AB",
940
+ // bei - by (passive)
941
+ "\u8BA9",
942
+ // rang - let, allow
943
+ "\u7684",
944
+ // de - possessive/attributive
945
+ "\u5730",
946
+ // de - adverbial marker
947
+ "\u5F97",
948
+ // de - complement marker
949
+ "\u4E86",
950
+ // le - completion marker
951
+ "\u7740",
952
+ // zhe - progressive marker
953
+ "\u8FC7",
954
+ // guo - experiential marker
955
+ "\u5417",
956
+ // ma - question particle
957
+ "\u5462",
958
+ // ne - question/emphasis particle
959
+ "\u5427"
960
+ // ba - suggestion particle
961
+ ]);
962
+ var MULTI_CHAR_PARTICLES = ["\u7136\u540E", "\u63A5\u7740", "\u5E76\u4E14", "\u6216\u8005", "\u5982\u679C", "\u90A3\u4E48", "\u5426\u5219"];
963
+ var CHINESE_EXTRAS = [
964
+ // Values/Literals
965
+ { native: "\u771F", normalized: "true" },
966
+ { native: "\u5047", normalized: "false" },
967
+ { native: "\u7A7A", normalized: "null" },
968
+ { native: "\u672A\u5B9A\u4E49", normalized: "undefined" },
969
+ // Positional
970
+ { native: "\u7B2C\u4E00\u4E2A", normalized: "first" },
971
+ { native: "\u9996\u4E2A", normalized: "first" },
972
+ { native: "\u6700\u540E\u4E00\u4E2A", normalized: "last" },
973
+ { native: "\u672B\u4E2A", normalized: "last" },
974
+ { native: "\u4E0B\u4E00\u4E2A", normalized: "next" },
975
+ { native: "\u4E0A\u4E00\u4E2A", normalized: "previous" },
976
+ { native: "\u6700\u8FD1\u7684", normalized: "closest" },
977
+ { native: "\u7236\u7EA7", normalized: "parent" },
978
+ // Events
979
+ { native: "\u70B9\u51FB", normalized: "click" },
980
+ { native: "\u53CC\u51FB", normalized: "dblclick" },
981
+ { native: "\u8F93\u5165", normalized: "input" },
982
+ { native: "\u53D8\u66F4", normalized: "change" },
983
+ { native: "\u6539\u53D8", normalized: "change" },
984
+ { native: "\u63D0\u4EA4", normalized: "submit" },
985
+ { native: "\u6309\u952E", normalized: "keydown" },
986
+ { native: "\u91CA\u653E\u952E", normalized: "keyup" },
987
+ { native: "\u9F20\u6807\u79FB\u5165", normalized: "mouseover" },
988
+ { native: "\u9F20\u6807\u79FB\u51FA", normalized: "mouseout" },
989
+ { native: "\u83B7\u5F97\u7126\u70B9", normalized: "focus" },
990
+ { native: "\u5931\u53BB\u7126\u70B9", normalized: "blur" },
991
+ { native: "\u52A0\u8F7D", normalized: "load" },
992
+ { native: "\u6EDA\u52A8", normalized: "scroll" },
993
+ // Additional references
994
+ { native: "\u6211\u7684", normalized: "my" },
995
+ { native: "\u5B83\u7684", normalized: "its" },
996
+ // Time units
997
+ { native: "\u79D2", normalized: "s" },
998
+ { native: "\u6BEB\u79D2", normalized: "ms" },
999
+ { native: "\u5206\u949F", normalized: "m" },
1000
+ { native: "\u5C0F\u65F6", normalized: "h" },
1001
+ // Logical operators
1002
+ { native: "\u548C", normalized: "and" },
1003
+ { native: "\u6216\u8005", normalized: "or" },
1004
+ { native: "\u6216", normalized: "or" },
1005
+ { native: "\u4E0D", normalized: "not" },
1006
+ { native: "\u975E", normalized: "not" },
1007
+ { native: "\u662F", normalized: "is" },
1008
+ // Additional synonyms not in profile
1009
+ { native: "\u82E5", normalized: "if" },
1010
+ { native: "\u4E0D\u7136", normalized: "else" },
1011
+ { native: "\u5FAA\u73AF", normalized: "repeat" },
1012
+ { native: "\u904D\u5386", normalized: "for" },
1013
+ { native: "\u6BCF\u4E2A", normalized: "for" },
1014
+ { native: "\u4E3A\u6BCF", normalized: "for" },
1015
+ { native: "\u4E2D\u6B62", normalized: "halt" },
1016
+ { native: "\u629B", normalized: "throw" },
1017
+ { native: "\u547C\u53EB", normalized: "call" },
1018
+ { native: "\u56DE", normalized: "return" },
1019
+ { native: "\u811A\u672C", normalized: "js" },
1020
+ { native: "\u901A\u77E5", normalized: "tell" },
1021
+ { native: "\u7F3A\u7701", normalized: "default" },
1022
+ { native: "\u521D\u59CB", normalized: "init" },
1023
+ { native: "\u52A8\u4F5C", normalized: "behavior" },
1024
+ { native: "\u6FC0\u53D1", normalized: "trigger" },
1025
+ { native: "\u5BF9\u7126", normalized: "focus" },
1026
+ { native: "\u6A21\u7CCA", normalized: "blur" },
1027
+ { native: "\u8DF3\u8F6C", normalized: "go" },
1028
+ { native: "\u5BFC\u822A", normalized: "go" },
1029
+ { native: "\u6293\u53D6", normalized: "fetch" },
1030
+ { native: "\u83B7\u53D6\u6570\u636E", normalized: "fetch" },
1031
+ { native: "\u5B89\u5B9A", normalized: "settle" },
1032
+ { native: "\u62FF\u53D6", normalized: "take" },
1033
+ { native: "\u53D6", normalized: "take" },
1034
+ { native: "\u521B\u5EFA", normalized: "make" },
1035
+ { native: "\u514B\u9686", normalized: "clone" },
1036
+ { native: "\u8BB0\u5F55", normalized: "log" },
1037
+ { native: "\u6253\u5370", normalized: "log" },
1038
+ { native: "\u52A8\u753B", normalized: "transition" },
1039
+ // Modifiers
1040
+ { native: "\u5230\u91CC\u9762", normalized: "into" },
1041
+ { native: "\u91CC", normalized: "into" },
1042
+ { native: "\u524D", normalized: "before" },
1043
+ { native: "\u540E", normalized: "after" },
1044
+ { native: "\u90A3\u4E48", normalized: "then" },
1045
+ { native: "\u5B8C", normalized: "end" }
1046
+ ];
1047
+ var CHINESE_TIME_UNITS = [
1048
+ { pattern: "\u6BEB\u79D2", suffix: "ms", length: 2 },
1049
+ { pattern: "\u5206\u949F", suffix: "m", length: 2 },
1050
+ { pattern: "\u5C0F\u65F6", suffix: "h", length: 2 },
1051
+ { pattern: "\u79D2", suffix: "s", length: 1 },
1052
+ { pattern: "\u5206", suffix: "m", length: 1 }
1053
+ ];
1054
+ var ChineseTokenizer = class extends BaseTokenizer {
1055
+ constructor() {
1056
+ super();
1057
+ this.language = "zh";
1058
+ this.direction = "ltr";
1059
+ this.initializeKeywordsFromProfile(chineseProfile, CHINESE_EXTRAS);
1060
+ }
1061
+ tokenize(input) {
1062
+ const tokens = [];
1063
+ let pos = 0;
1064
+ while (pos < input.length) {
1065
+ if (isWhitespace(input[pos])) {
1066
+ pos++;
1067
+ continue;
1068
+ }
1069
+ if (isSelectorStart(input[pos])) {
1070
+ const modifierToken = this.tryEventModifier(input, pos);
1071
+ if (modifierToken) {
1072
+ tokens.push(modifierToken);
1073
+ pos = modifierToken.position.end;
1074
+ continue;
1075
+ }
1076
+ const selectorToken = this.trySelector(input, pos);
1077
+ if (selectorToken) {
1078
+ tokens.push(selectorToken);
1079
+ pos = selectorToken.position.end;
1080
+ continue;
1081
+ }
1082
+ }
1083
+ if (isQuote(input[pos]) || input[pos] === "\u201C" || input[pos] === "\u201D" || input[pos] === "\u2018" || input[pos] === "\u2019") {
1084
+ const stringToken = this.tryChineseString(input, pos);
1085
+ if (stringToken) {
1086
+ tokens.push(stringToken);
1087
+ pos = stringToken.position.end;
1088
+ continue;
1089
+ }
1090
+ }
1091
+ if (isUrlStart(input, pos)) {
1092
+ const urlToken = this.tryUrl(input, pos);
1093
+ if (urlToken) {
1094
+ tokens.push(urlToken);
1095
+ pos = urlToken.position.end;
1096
+ continue;
1097
+ }
1098
+ }
1099
+ if (isDigit(input[pos])) {
1100
+ const numberToken = this.extractChineseNumber(input, pos);
1101
+ if (numberToken) {
1102
+ tokens.push(numberToken);
1103
+ pos = numberToken.position.end;
1104
+ continue;
1105
+ }
1106
+ }
1107
+ const varToken = this.tryVariableRef(input, pos);
1108
+ if (varToken) {
1109
+ tokens.push(varToken);
1110
+ pos = varToken.position.end;
1111
+ continue;
1112
+ }
1113
+ const multiParticle = this.tryMultiCharParticle(input, pos, MULTI_CHAR_PARTICLES);
1114
+ if (multiParticle) {
1115
+ tokens.push(multiParticle);
1116
+ pos = multiParticle.position.end;
1117
+ continue;
1118
+ }
1119
+ if (isChinese(input[pos])) {
1120
+ const wordToken = this.extractChineseWord(input, pos);
1121
+ if (wordToken) {
1122
+ tokens.push(wordToken);
1123
+ pos = wordToken.position.end;
1124
+ continue;
1125
+ }
1126
+ }
1127
+ if (isAsciiIdentifierChar(input[pos])) {
1128
+ const asciiToken = this.extractAsciiWord(input, pos);
1129
+ if (asciiToken) {
1130
+ tokens.push(asciiToken);
1131
+ pos = asciiToken.position.end;
1132
+ continue;
1133
+ }
1134
+ }
1135
+ pos++;
1136
+ }
1137
+ return new TokenStreamImpl(tokens, "zh");
1138
+ }
1139
+ classifyToken(token) {
1140
+ if (PARTICLES.has(token)) return "particle";
1141
+ if (this.isKeyword(token)) return "keyword";
1142
+ if (token.startsWith("#") || token.startsWith(".") || token.startsWith("[") || token.startsWith("<"))
1143
+ return "selector";
1144
+ if (token.startsWith('"') || token.startsWith("'") || token.startsWith("\u201C") || token.startsWith("\u2018"))
1145
+ return "literal";
1146
+ if (/^\d/.test(token)) return "literal";
1147
+ return "identifier";
1148
+ }
1149
+ /**
1150
+ * Extract a Chinese word.
1151
+ * Uses greedy matching to find the longest known keyword.
1152
+ * Chinese doesn't have inflection, so we don't need morphological normalization.
1153
+ * profileKeywords is already sorted longest-first, enabling greedy matching.
1154
+ */
1155
+ extractChineseWord(input, startPos) {
1156
+ for (const entry of this.profileKeywords) {
1157
+ const keyword = entry.native;
1158
+ const candidate = input.slice(startPos, startPos + keyword.length);
1159
+ if (candidate === keyword) {
1160
+ let allChinese = true;
1161
+ for (let i = 0; i < keyword.length; i++) {
1162
+ if (!isChinese(keyword[i])) {
1163
+ allChinese = false;
1164
+ break;
1165
+ }
1166
+ }
1167
+ if (allChinese) {
1168
+ return createToken(
1169
+ candidate,
1170
+ "keyword",
1171
+ createPosition(startPos, startPos + keyword.length),
1172
+ entry.normalized
1173
+ );
1174
+ }
1175
+ }
1176
+ }
1177
+ let pos = startPos;
1178
+ let word = "";
1179
+ while (pos < input.length) {
1180
+ const char = input[pos];
1181
+ if (PARTICLES.has(char) && word.length > 0) {
1182
+ break;
1183
+ }
1184
+ if (isChinese(char)) {
1185
+ word += char;
1186
+ pos++;
1187
+ } else {
1188
+ break;
1189
+ }
1190
+ }
1191
+ if (!word) return null;
1192
+ if (PARTICLES.has(word)) {
1193
+ return createToken(word, "particle", createPosition(startPos, pos));
1194
+ }
1195
+ return createToken(word, "identifier", createPosition(startPos, pos));
1196
+ }
1197
+ /**
1198
+ * Extract an ASCII word (for mixed Chinese/English content).
1199
+ */
1200
+ extractAsciiWord(input, startPos) {
1201
+ let pos = startPos;
1202
+ let word = "";
1203
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
1204
+ word += input[pos++];
1205
+ }
1206
+ if (!word) return null;
1207
+ return createToken(word, "identifier", createPosition(startPos, pos));
1208
+ }
1209
+ /**
1210
+ * Try to extract a string literal, including Chinese quotes.
1211
+ * Chinese quotes: \u201C " (open) \u201D " (close) \u2018 ' (open) \u2019 ' (close)
1212
+ */
1213
+ tryChineseString(input, pos) {
1214
+ const char = input[pos];
1215
+ if (char === '"' || char === "'" || char === "`") {
1216
+ return this.tryString(input, pos);
1217
+ }
1218
+ if (char === "\u201C") {
1219
+ let endPos = pos + 1;
1220
+ while (endPos < input.length && input[endPos] !== "\u201D") {
1221
+ endPos++;
1222
+ }
1223
+ if (endPos >= input.length) return null;
1224
+ const value = input.slice(pos, endPos + 1);
1225
+ return createToken(value, "literal", createPosition(pos, endPos + 1));
1226
+ }
1227
+ if (char === "\u2018") {
1228
+ let endPos = pos + 1;
1229
+ while (endPos < input.length && input[endPos] !== "\u2019") {
1230
+ endPos++;
1231
+ }
1232
+ if (endPos >= input.length) return null;
1233
+ const value = input.slice(pos, endPos + 1);
1234
+ return createToken(value, "literal", createPosition(pos, endPos + 1));
1235
+ }
1236
+ return null;
1237
+ }
1238
+ /**
1239
+ * Extract a number, including Chinese time unit suffixes.
1240
+ * Chinese time units attach directly without whitespace.
1241
+ */
1242
+ extractChineseNumber(input, startPos) {
1243
+ return this.tryNumberWithTimeUnits(input, startPos, CHINESE_TIME_UNITS, {
1244
+ allowSign: false,
1245
+ skipWhitespace: false
1246
+ });
1247
+ }
1248
+ };
1249
+ var chineseTokenizer = new ChineseTokenizer();
1250
+
1251
+ // src/languages/zh.ts
1252
+ registerLanguage("zh", chineseTokenizer, chineseProfile);
1253
+ export {
1254
+ chineseProfile,
1255
+ chineseTokenizer
1256
+ };
1257
+ //# sourceMappingURL=zh.js.map