@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,1143 @@
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 createLatinCharClassifiers(letterPattern) {
110
+ const isLetter = (char) => letterPattern.test(char);
111
+ const isIdentifierChar = (char) => isLetter(char) || /[0-9_-]/.test(char);
112
+ return { isLetter, isIdentifierChar };
113
+ }
114
+ function extractCssSelector(input, startPos) {
115
+ if (startPos >= input.length) return null;
116
+ const char = input[startPos];
117
+ if (!isSelectorStart(char)) return null;
118
+ let pos = startPos;
119
+ let selector = "";
120
+ if (char === "#" || char === ".") {
121
+ selector += input[pos++];
122
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
123
+ selector += input[pos++];
124
+ }
125
+ if (selector.length <= 1) return null;
126
+ if (pos < input.length && input[pos] === "." && char === "#") {
127
+ const methodStart = pos + 1;
128
+ let methodEnd = methodStart;
129
+ while (methodEnd < input.length && isAsciiIdentifierChar(input[methodEnd])) {
130
+ methodEnd++;
131
+ }
132
+ if (methodEnd < input.length && input[methodEnd] === "(") {
133
+ return selector;
134
+ }
135
+ }
136
+ } else if (char === "[") {
137
+ let depth = 1;
138
+ let inQuote = false;
139
+ let quoteChar = null;
140
+ let escaped = false;
141
+ selector += input[pos++];
142
+ while (pos < input.length && depth > 0) {
143
+ const c = input[pos];
144
+ selector += c;
145
+ if (escaped) {
146
+ escaped = false;
147
+ } else if (c === "\\") {
148
+ escaped = true;
149
+ } else if (inQuote) {
150
+ if (c === quoteChar) {
151
+ inQuote = false;
152
+ quoteChar = null;
153
+ }
154
+ } else {
155
+ if (c === '"' || c === "'" || c === "`") {
156
+ inQuote = true;
157
+ quoteChar = c;
158
+ } else if (c === "[") {
159
+ depth++;
160
+ } else if (c === "]") {
161
+ depth--;
162
+ }
163
+ }
164
+ pos++;
165
+ }
166
+ if (depth !== 0) return null;
167
+ } else if (char === "@") {
168
+ selector += input[pos++];
169
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
170
+ selector += input[pos++];
171
+ }
172
+ if (selector.length <= 1) return null;
173
+ } else if (char === "*") {
174
+ selector += input[pos++];
175
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
176
+ selector += input[pos++];
177
+ }
178
+ if (selector.length <= 1) return null;
179
+ } else if (char === "<") {
180
+ selector += input[pos++];
181
+ if (pos >= input.length || !isAsciiLetter(input[pos])) return null;
182
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
183
+ selector += input[pos++];
184
+ }
185
+ while (pos < input.length) {
186
+ const modChar = input[pos];
187
+ if (modChar === ".") {
188
+ selector += input[pos++];
189
+ if (pos >= input.length || !isAsciiIdentifierChar(input[pos])) {
190
+ return null;
191
+ }
192
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
193
+ selector += input[pos++];
194
+ }
195
+ } else if (modChar === "#") {
196
+ selector += input[pos++];
197
+ if (pos >= input.length || !isAsciiIdentifierChar(input[pos])) {
198
+ return null;
199
+ }
200
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
201
+ selector += input[pos++];
202
+ }
203
+ } else if (modChar === "[") {
204
+ let depth = 1;
205
+ let inQuote = false;
206
+ let quoteChar = null;
207
+ let escaped = false;
208
+ selector += input[pos++];
209
+ while (pos < input.length && depth > 0) {
210
+ const c = input[pos];
211
+ selector += c;
212
+ if (escaped) {
213
+ escaped = false;
214
+ } else if (c === "\\") {
215
+ escaped = true;
216
+ } else if (inQuote) {
217
+ if (c === quoteChar) {
218
+ inQuote = false;
219
+ quoteChar = null;
220
+ }
221
+ } else {
222
+ if (c === '"' || c === "'" || c === "`") {
223
+ inQuote = true;
224
+ quoteChar = c;
225
+ } else if (c === "[") {
226
+ depth++;
227
+ } else if (c === "]") {
228
+ depth--;
229
+ }
230
+ }
231
+ pos++;
232
+ }
233
+ if (depth !== 0) return null;
234
+ } else {
235
+ break;
236
+ }
237
+ }
238
+ while (pos < input.length && isWhitespace(input[pos])) {
239
+ selector += input[pos++];
240
+ }
241
+ if (pos < input.length && input[pos] === "/") {
242
+ selector += input[pos++];
243
+ while (pos < input.length && isWhitespace(input[pos])) {
244
+ selector += input[pos++];
245
+ }
246
+ }
247
+ if (pos >= input.length || input[pos] !== ">") return null;
248
+ selector += input[pos++];
249
+ }
250
+ return selector || null;
251
+ }
252
+ function isPossessiveMarker(input, pos) {
253
+ if (pos >= input.length || input[pos] !== "'") return false;
254
+ if (pos + 1 >= input.length) return false;
255
+ const nextChar = input[pos + 1].toLowerCase();
256
+ if (nextChar !== "s") return false;
257
+ if (pos + 2 >= input.length) return true;
258
+ const afterS = input[pos + 2];
259
+ return isWhitespace(afterS) || afterS === "*" || !isAsciiIdentifierChar(afterS);
260
+ }
261
+ function extractStringLiteral(input, startPos) {
262
+ if (startPos >= input.length) return null;
263
+ const openQuote = input[startPos];
264
+ if (!isQuote(openQuote)) return null;
265
+ if (openQuote === "'" && isPossessiveMarker(input, startPos)) {
266
+ return null;
267
+ }
268
+ const closeQuoteMap = {
269
+ '"': '"',
270
+ "'": "'",
271
+ "`": "`",
272
+ "\u300C": "\u300D"
273
+ };
274
+ const closeQuote = closeQuoteMap[openQuote];
275
+ if (!closeQuote) return null;
276
+ let pos = startPos + 1;
277
+ let literal = openQuote;
278
+ let escaped = false;
279
+ while (pos < input.length) {
280
+ const char = input[pos];
281
+ literal += char;
282
+ if (escaped) {
283
+ escaped = false;
284
+ } else if (char === "\\") {
285
+ escaped = true;
286
+ } else if (char === closeQuote) {
287
+ return literal;
288
+ }
289
+ pos++;
290
+ }
291
+ return literal;
292
+ }
293
+ function isUrlStart(input, pos) {
294
+ if (pos >= input.length) return false;
295
+ const char = input[pos];
296
+ const next = input[pos + 1] || "";
297
+ const third = input[pos + 2] || "";
298
+ if (char === "/" && next !== "/" && /[a-zA-Z0-9._-]/.test(next)) {
299
+ return true;
300
+ }
301
+ if (char === "/" && next === "/" && /[a-zA-Z]/.test(third)) {
302
+ return true;
303
+ }
304
+ if (char === "." && (next === "/" || next === "." && third === "/")) {
305
+ return true;
306
+ }
307
+ const slice = input.slice(pos, pos + 8).toLowerCase();
308
+ if (slice.startsWith("http://") || slice.startsWith("https://")) {
309
+ return true;
310
+ }
311
+ return false;
312
+ }
313
+ function extractUrl(input, startPos) {
314
+ if (!isUrlStart(input, startPos)) return null;
315
+ let pos = startPos;
316
+ let url = "";
317
+ const urlChars = /[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;
318
+ while (pos < input.length) {
319
+ const char = input[pos];
320
+ if (char === "#") {
321
+ if (url.length > 0 && /[a-zA-Z0-9/.]$/.test(url)) {
322
+ url += char;
323
+ pos++;
324
+ while (pos < input.length && /[a-zA-Z0-9_-]/.test(input[pos])) {
325
+ url += input[pos++];
326
+ }
327
+ }
328
+ break;
329
+ }
330
+ if (urlChars.test(char)) {
331
+ url += char;
332
+ pos++;
333
+ } else {
334
+ break;
335
+ }
336
+ }
337
+ if (url.length < 2) return null;
338
+ return url;
339
+ }
340
+ function extractNumber(input, startPos) {
341
+ if (startPos >= input.length) return null;
342
+ const char = input[startPos];
343
+ if (!isDigit(char) && char !== "-" && char !== "+") return null;
344
+ let pos = startPos;
345
+ let number = "";
346
+ if (input[pos] === "-" || input[pos] === "+") {
347
+ number += input[pos++];
348
+ }
349
+ if (pos >= input.length || !isDigit(input[pos])) {
350
+ return null;
351
+ }
352
+ while (pos < input.length && isDigit(input[pos])) {
353
+ number += input[pos++];
354
+ }
355
+ if (pos < input.length && input[pos] === ".") {
356
+ number += input[pos++];
357
+ while (pos < input.length && isDigit(input[pos])) {
358
+ number += input[pos++];
359
+ }
360
+ }
361
+ if (pos < input.length) {
362
+ const suffix = input.slice(pos, pos + 2);
363
+ if (suffix === "ms") {
364
+ number += "ms";
365
+ } else if (input[pos] === "s" || input[pos] === "m" || input[pos] === "h") {
366
+ number += input[pos];
367
+ }
368
+ }
369
+ return number;
370
+ }
371
+ var _BaseTokenizer = class _BaseTokenizer {
372
+ constructor() {
373
+ /** Keywords derived from profile, sorted longest-first for greedy matching */
374
+ this.profileKeywords = [];
375
+ /** Map for O(1) keyword lookups by lowercase native word */
376
+ this.profileKeywordMap = /* @__PURE__ */ new Map();
377
+ }
378
+ /**
379
+ * Initialize keyword mappings from a language profile.
380
+ * Builds a list of native→english mappings from:
381
+ * - profile.keywords (primary + alternatives)
382
+ * - profile.references (me, it, you, etc.)
383
+ * - profile.roleMarkers (into, from, with, etc.)
384
+ *
385
+ * Results are sorted longest-first for greedy matching (important for non-space languages).
386
+ * Extras take precedence over profile entries when there are duplicates.
387
+ *
388
+ * @param profile - Language profile containing keyword translations
389
+ * @param extras - Additional keyword entries to include (literals, positional, events)
390
+ */
391
+ initializeKeywordsFromProfile(profile, extras = []) {
392
+ const keywordMap = /* @__PURE__ */ new Map();
393
+ if (profile.keywords) {
394
+ for (const [normalized, translation] of Object.entries(profile.keywords)) {
395
+ keywordMap.set(translation.primary, {
396
+ native: translation.primary,
397
+ normalized: translation.normalized || normalized
398
+ });
399
+ if (translation.alternatives) {
400
+ for (const alt of translation.alternatives) {
401
+ keywordMap.set(alt, {
402
+ native: alt,
403
+ normalized: translation.normalized || normalized
404
+ });
405
+ }
406
+ }
407
+ }
408
+ }
409
+ if (profile.references) {
410
+ for (const [normalized, native] of Object.entries(profile.references)) {
411
+ keywordMap.set(native, { native, normalized });
412
+ }
413
+ }
414
+ if (profile.roleMarkers) {
415
+ for (const [role, marker] of Object.entries(profile.roleMarkers)) {
416
+ if (marker.primary) {
417
+ keywordMap.set(marker.primary, { native: marker.primary, normalized: role });
418
+ }
419
+ if (marker.alternatives) {
420
+ for (const alt of marker.alternatives) {
421
+ keywordMap.set(alt, { native: alt, normalized: role });
422
+ }
423
+ }
424
+ }
425
+ }
426
+ for (const extra of extras) {
427
+ keywordMap.set(extra.native, extra);
428
+ }
429
+ this.profileKeywords = Array.from(keywordMap.values()).sort(
430
+ (a, b) => b.native.length - a.native.length
431
+ );
432
+ this.profileKeywordMap = /* @__PURE__ */ new Map();
433
+ for (const keyword of this.profileKeywords) {
434
+ this.profileKeywordMap.set(keyword.native.toLowerCase(), keyword);
435
+ const normalized = this.removeDiacritics(keyword.native);
436
+ if (normalized !== keyword.native && !this.profileKeywordMap.has(normalized.toLowerCase())) {
437
+ this.profileKeywordMap.set(normalized.toLowerCase(), keyword);
438
+ }
439
+ }
440
+ }
441
+ /**
442
+ * Remove diacritical marks from a word for normalization.
443
+ * Primarily for Arabic (shadda, fatha, kasra, damma, sukun, etc.)
444
+ * but could be extended for other languages.
445
+ *
446
+ * @param word - Word to normalize
447
+ * @returns Word without diacritics
448
+ */
449
+ removeDiacritics(word) {
450
+ return word.replace(/[\u064B-\u0652\u0670]/g, "");
451
+ }
452
+ /**
453
+ * Try to match a keyword from profile at the current position.
454
+ * Uses longest-first greedy matching (important for non-space languages).
455
+ *
456
+ * @param input - Input string
457
+ * @param pos - Current position
458
+ * @returns Token if matched, null otherwise
459
+ */
460
+ tryProfileKeyword(input, pos) {
461
+ for (const entry of this.profileKeywords) {
462
+ if (input.slice(pos).startsWith(entry.native)) {
463
+ return createToken(
464
+ entry.native,
465
+ "keyword",
466
+ createPosition(pos, pos + entry.native.length),
467
+ entry.normalized
468
+ );
469
+ }
470
+ }
471
+ return null;
472
+ }
473
+ /**
474
+ * Check if the remaining input starts with any known keyword.
475
+ * Useful for non-space languages to detect word boundaries.
476
+ *
477
+ * @param input - Input string
478
+ * @param pos - Current position
479
+ * @returns true if a keyword starts at this position
480
+ */
481
+ isKeywordStart(input, pos) {
482
+ const remaining = input.slice(pos);
483
+ return this.profileKeywords.some((entry) => remaining.startsWith(entry.native));
484
+ }
485
+ /**
486
+ * Look up a keyword by native word (case-insensitive).
487
+ * O(1) lookup using the keyword map.
488
+ *
489
+ * @param native - Native word to look up
490
+ * @returns KeywordEntry if found, undefined otherwise
491
+ */
492
+ lookupKeyword(native) {
493
+ return this.profileKeywordMap.get(native.toLowerCase());
494
+ }
495
+ /**
496
+ * Check if a word is a known keyword (case-insensitive).
497
+ * O(1) lookup using the keyword map.
498
+ *
499
+ * @param native - Native word to check
500
+ * @returns true if the word is a keyword
501
+ */
502
+ isKeyword(native) {
503
+ return this.profileKeywordMap.has(native.toLowerCase());
504
+ }
505
+ /**
506
+ * Set the morphological normalizer for this tokenizer.
507
+ */
508
+ setNormalizer(normalizer) {
509
+ this.normalizer = normalizer;
510
+ }
511
+ /**
512
+ * Try to normalize a word using the morphological normalizer.
513
+ * Returns null if no normalizer is set or normalization fails.
514
+ *
515
+ * Note: We don't check isNormalizable() here because the individual tokenizers
516
+ * historically called normalize() directly without that check. The normalize()
517
+ * method itself handles returning noChange() for words that can't be normalized.
518
+ */
519
+ tryNormalize(word) {
520
+ if (!this.normalizer) return null;
521
+ const result = this.normalizer.normalize(word);
522
+ if (result.stem !== word && result.confidence >= 0.7) {
523
+ return result;
524
+ }
525
+ return null;
526
+ }
527
+ /**
528
+ * Try morphological normalization and keyword lookup.
529
+ *
530
+ * If the word can be normalized to a stem that matches a known keyword,
531
+ * returns a keyword token with morphological metadata (stem, stemConfidence).
532
+ *
533
+ * This is the common pattern for handling conjugated verbs across languages:
534
+ * 1. Normalize the word (e.g., "toggled" → "toggle")
535
+ * 2. Look up the stem in the keyword map
536
+ * 3. Create a token with both the original form and stem metadata
537
+ *
538
+ * @param word - The word to normalize and look up
539
+ * @param startPos - Start position for the token
540
+ * @param endPos - End position for the token
541
+ * @returns Token if stem matches a keyword, null otherwise
542
+ */
543
+ tryMorphKeywordMatch(word, startPos, endPos) {
544
+ const result = this.tryNormalize(word);
545
+ if (!result) return null;
546
+ const stemEntry = this.lookupKeyword(result.stem);
547
+ if (!stemEntry) return null;
548
+ const tokenOptions = {
549
+ normalized: stemEntry.normalized,
550
+ stem: result.stem,
551
+ stemConfidence: result.confidence
552
+ };
553
+ return createToken(word, "keyword", createPosition(startPos, endPos), tokenOptions);
554
+ }
555
+ /**
556
+ * Try to extract a CSS selector at the current position.
557
+ */
558
+ trySelector(input, pos) {
559
+ const selector = extractCssSelector(input, pos);
560
+ if (selector) {
561
+ return createToken(selector, "selector", createPosition(pos, pos + selector.length));
562
+ }
563
+ return null;
564
+ }
565
+ /**
566
+ * Try to extract an event modifier at the current position.
567
+ * Event modifiers are .once, .debounce(N), .throttle(N), .queue(strategy)
568
+ */
569
+ tryEventModifier(input, pos) {
570
+ if (input[pos] !== ".") {
571
+ return null;
572
+ }
573
+ const match = input.slice(pos).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);
574
+ if (!match) {
575
+ return null;
576
+ }
577
+ const fullMatch = match[0].replace(/(\s|\.)$/, "");
578
+ const modifierName = fullMatch.slice(1).split("(")[0];
579
+ const value = match[1];
580
+ const token = createToken(
581
+ fullMatch,
582
+ "event-modifier",
583
+ createPosition(pos, pos + fullMatch.length)
584
+ );
585
+ return {
586
+ ...token,
587
+ metadata: {
588
+ modifierName,
589
+ value: value ? modifierName === "queue" ? value : parseInt(value, 10) : void 0
590
+ }
591
+ };
592
+ }
593
+ /**
594
+ * Try to extract a string literal at the current position.
595
+ */
596
+ tryString(input, pos) {
597
+ const literal = extractStringLiteral(input, pos);
598
+ if (literal) {
599
+ return createToken(literal, "literal", createPosition(pos, pos + literal.length));
600
+ }
601
+ return null;
602
+ }
603
+ /**
604
+ * Try to extract a number at the current position.
605
+ */
606
+ tryNumber(input, pos) {
607
+ const number = extractNumber(input, pos);
608
+ if (number) {
609
+ return createToken(number, "literal", createPosition(pos, pos + number.length));
610
+ }
611
+ return null;
612
+ }
613
+ /**
614
+ * Try to match a time unit from a list of patterns.
615
+ *
616
+ * @param input - Input string
617
+ * @param pos - Position after the number
618
+ * @param timeUnits - Array of time unit mappings (native pattern → standard suffix)
619
+ * @param skipWhitespace - Whether to skip whitespace before time unit (default: false)
620
+ * @returns Object with matched suffix and new position, or null if no match
621
+ */
622
+ tryMatchTimeUnit(input, pos, timeUnits, skipWhitespace = false) {
623
+ let unitPos = pos;
624
+ if (skipWhitespace) {
625
+ while (unitPos < input.length && isWhitespace(input[unitPos])) {
626
+ unitPos++;
627
+ }
628
+ }
629
+ const remaining = input.slice(unitPos);
630
+ for (const unit of timeUnits) {
631
+ const candidate = remaining.slice(0, unit.length);
632
+ const matches = unit.caseInsensitive ? candidate.toLowerCase() === unit.pattern.toLowerCase() : candidate === unit.pattern;
633
+ if (matches) {
634
+ if (unit.notFollowedBy) {
635
+ const nextChar = remaining[unit.length] || "";
636
+ if (nextChar === unit.notFollowedBy) continue;
637
+ }
638
+ if (unit.checkBoundary) {
639
+ const nextChar = remaining[unit.length] || "";
640
+ if (isAsciiIdentifierChar(nextChar)) continue;
641
+ }
642
+ return { suffix: unit.suffix, endPos: unitPos + unit.length };
643
+ }
644
+ }
645
+ return null;
646
+ }
647
+ /**
648
+ * Parse a base number (sign, integer, decimal) without time units.
649
+ * Returns the number string and end position.
650
+ *
651
+ * @param input - Input string
652
+ * @param startPos - Start position
653
+ * @param allowSign - Whether to allow +/- sign (default: true)
654
+ * @returns Object with number string and end position, or null
655
+ */
656
+ parseBaseNumber(input, startPos, allowSign = true) {
657
+ let pos = startPos;
658
+ let number = "";
659
+ if (allowSign && (input[pos] === "-" || input[pos] === "+")) {
660
+ number += input[pos++];
661
+ }
662
+ if (pos >= input.length || !isDigit(input[pos])) {
663
+ return null;
664
+ }
665
+ while (pos < input.length && isDigit(input[pos])) {
666
+ number += input[pos++];
667
+ }
668
+ if (pos < input.length && input[pos] === ".") {
669
+ number += input[pos++];
670
+ while (pos < input.length && isDigit(input[pos])) {
671
+ number += input[pos++];
672
+ }
673
+ }
674
+ if (!number || number === "-" || number === "+") return null;
675
+ return { number, endPos: pos };
676
+ }
677
+ /**
678
+ * Try to extract a number with native language time units.
679
+ *
680
+ * This is a template method that handles the common pattern:
681
+ * 1. Parse the base number (sign, integer, decimal)
682
+ * 2. Try to match native language time units
683
+ * 3. Fall back to standard time units (ms, s, m, h)
684
+ *
685
+ * @param input - Input string
686
+ * @param pos - Start position
687
+ * @param nativeTimeUnits - Language-specific time unit mappings
688
+ * @param options - Configuration options
689
+ * @returns Token if number found, null otherwise
690
+ */
691
+ tryNumberWithTimeUnits(input, pos, nativeTimeUnits, options = {}) {
692
+ const { allowSign = true, skipWhitespace = false } = options;
693
+ const baseResult = this.parseBaseNumber(input, pos, allowSign);
694
+ if (!baseResult) return null;
695
+ let { number, endPos } = baseResult;
696
+ const allUnits = [...nativeTimeUnits, ..._BaseTokenizer.STANDARD_TIME_UNITS];
697
+ const timeMatch = this.tryMatchTimeUnit(input, endPos, allUnits, skipWhitespace);
698
+ if (timeMatch) {
699
+ number += timeMatch.suffix;
700
+ endPos = timeMatch.endPos;
701
+ }
702
+ return createToken(number, "literal", createPosition(pos, endPos));
703
+ }
704
+ /**
705
+ * Try to extract a URL at the current position.
706
+ * Handles /path, ./path, ../path, //domain.com, http://, https://
707
+ */
708
+ tryUrl(input, pos) {
709
+ const url = extractUrl(input, pos);
710
+ if (url) {
711
+ return createToken(url, "url", createPosition(pos, pos + url.length));
712
+ }
713
+ return null;
714
+ }
715
+ /**
716
+ * Try to extract a variable reference (:varname) at the current position.
717
+ * In hyperscript, :x refers to a local variable named x.
718
+ */
719
+ tryVariableRef(input, pos) {
720
+ if (input[pos] !== ":") return null;
721
+ if (pos + 1 >= input.length) return null;
722
+ if (!isAsciiIdentifierChar(input[pos + 1])) return null;
723
+ let endPos = pos + 1;
724
+ while (endPos < input.length && isAsciiIdentifierChar(input[endPos])) {
725
+ endPos++;
726
+ }
727
+ const varRef = input.slice(pos, endPos);
728
+ return createToken(varRef, "identifier", createPosition(pos, endPos));
729
+ }
730
+ /**
731
+ * Try to extract an operator or punctuation token at the current position.
732
+ * Handles two-character operators (==, !=, etc.) and single-character operators.
733
+ */
734
+ tryOperator(input, pos) {
735
+ const twoChar = input.slice(pos, pos + 2);
736
+ if (["==", "!=", "<=", ">=", "&&", "||", "->"].includes(twoChar)) {
737
+ return createToken(twoChar, "operator", createPosition(pos, pos + 2));
738
+ }
739
+ const oneChar = input[pos];
740
+ if (["<", ">", "!", "+", "-", "*", "/", "="].includes(oneChar)) {
741
+ return createToken(oneChar, "operator", createPosition(pos, pos + 1));
742
+ }
743
+ if (["(", ")", "{", "}", ",", ";", ":"].includes(oneChar)) {
744
+ return createToken(oneChar, "punctuation", createPosition(pos, pos + 1));
745
+ }
746
+ return null;
747
+ }
748
+ /**
749
+ * Try to match a multi-character particle from a list.
750
+ *
751
+ * Used by languages like Japanese, Korean, and Chinese that have
752
+ * multi-character particles (e.g., Japanese から, まで, より).
753
+ *
754
+ * @param input - Input string
755
+ * @param pos - Current position
756
+ * @param particles - Array of multi-character particles to match
757
+ * @returns Token if matched, null otherwise
758
+ */
759
+ tryMultiCharParticle(input, pos, particles) {
760
+ for (const particle of particles) {
761
+ if (input.slice(pos, pos + particle.length) === particle) {
762
+ return createToken(particle, "particle", createPosition(pos, pos + particle.length));
763
+ }
764
+ }
765
+ return null;
766
+ }
767
+ };
768
+ /**
769
+ * Configuration for native language time units.
770
+ * Maps patterns to their standard suffix (ms, s, m, h).
771
+ */
772
+ _BaseTokenizer.STANDARD_TIME_UNITS = [
773
+ { pattern: "ms", suffix: "ms", length: 2 },
774
+ { pattern: "s", suffix: "s", length: 1, checkBoundary: true },
775
+ { pattern: "m", suffix: "m", length: 1, checkBoundary: true, notFollowedBy: "s" },
776
+ { pattern: "h", suffix: "h", length: 1, checkBoundary: true }
777
+ ];
778
+ var BaseTokenizer = _BaseTokenizer;
779
+
780
+ // src/generators/profiles/quechua.ts
781
+ var quechuaProfile = {
782
+ code: "qu",
783
+ name: "Quechua",
784
+ nativeName: "Runasimi",
785
+ direction: "ltr",
786
+ wordOrder: "SOV",
787
+ markingStrategy: "postposition",
788
+ usesSpaces: true,
789
+ verb: {
790
+ position: "end",
791
+ subjectDrop: true
792
+ },
793
+ references: {
794
+ me: "\xF1uqa",
795
+ // "I/me"
796
+ it: "pay",
797
+ // "it/he/she" (same pronoun)
798
+ you: "qam",
799
+ // "you"
800
+ result: "rurasqa",
801
+ event: "ruwakuq",
802
+ target: "\xF1awpaqman",
803
+ body: "ukhu"
804
+ },
805
+ possessive: {
806
+ marker: "-pa",
807
+ // Genitive suffix
808
+ markerPosition: "after-object",
809
+ // Quechua: ñuqapa value = "my value"
810
+ keywords: {
811
+ // Genitive forms (pronoun + -pa suffix)
812
+ // "my" - ñuqapa, ñuqaypa
813
+ \u00F1uqapa: "me",
814
+ \u00F1uqaypa: "me",
815
+ // "your" - qampa
816
+ qampa: "you",
817
+ // "its/his/her" - paypa
818
+ paypa: "it"
819
+ }
820
+ },
821
+ roleMarkers: {
822
+ patient: { primary: "-ta", position: "after" },
823
+ destination: { primary: "-man", position: "after" },
824
+ source: { primary: "-manta", position: "after" },
825
+ style: { primary: "-wan", position: "after" },
826
+ event: { primary: "-ta", position: "after" }
827
+ // Event as accusative
828
+ },
829
+ keywords: {
830
+ toggle: { primary: "t'ikray", alternatives: ["tikray", "kutichiy"], normalized: "toggle" },
831
+ add: { primary: "yapay", alternatives: ["yapaykuy"], normalized: "add" },
832
+ remove: { primary: "qichuy", alternatives: ["hurquy", "anchuchiy"], normalized: "remove" },
833
+ put: { primary: "churay", alternatives: ["tiyachiy"], normalized: "put" },
834
+ append: { primary: "qatichiy", normalized: "append" },
835
+ prepend: { primary: "\xF1awpachiy", normalized: "prepend" },
836
+ take: { primary: "hapiy", normalized: "take" },
837
+ make: { primary: "ruray", alternatives: ["kamay"], normalized: "make" },
838
+ clone: { primary: "kikinchay", alternatives: ["qillqay"], normalized: "clone" },
839
+ swap: { primary: "t'inkuy", alternatives: ["rantikunakuy"], normalized: "swap" },
840
+ morph: { primary: "tikray", alternatives: ["kutichiy"], normalized: "morph" },
841
+ set: { primary: "churay", alternatives: ["kamaykuy"], normalized: "set" },
842
+ get: { primary: "taripay", normalized: "get" },
843
+ increment: { primary: "yapachiy", normalized: "increment" },
844
+ decrement: { primary: "pisiyachiy", normalized: "decrement" },
845
+ log: { primary: "qillqakuy", alternatives: ["willakuy"], normalized: "log" },
846
+ show: { primary: "rikuchiy", alternatives: ["qawachiy"], normalized: "show" },
847
+ hide: { primary: "pakay", alternatives: ["pakakuy"], normalized: "hide" },
848
+ transition: { primary: "tikray", alternatives: ["kuyuchiy"], normalized: "transition" },
849
+ on: { primary: "chaypim", alternatives: ["kaypi"], normalized: "on" },
850
+ trigger: { primary: "qallarichiy", normalized: "trigger" },
851
+ send: { primary: "kachay", alternatives: ["apachiy"], normalized: "send" },
852
+ focus: { primary: "qhawachiy", normalized: "focus" },
853
+ blur: { primary: "mana qhawachiy", normalized: "blur" },
854
+ go: { primary: "riy", alternatives: ["puriy"], normalized: "go" },
855
+ wait: { primary: "suyay", normalized: "wait" },
856
+ fetch: { primary: "apamuy", alternatives: ["taripakaramuy"], normalized: "fetch" },
857
+ settle: { primary: "tiyakuy", normalized: "settle" },
858
+ if: { primary: "sichus", normalized: "if" },
859
+ when: { primary: "maykama", normalized: "when" },
860
+ where: { primary: "maypi", normalized: "where" },
861
+ else: { primary: "manachus", alternatives: ["hukniraq"], normalized: "else" },
862
+ repeat: { primary: "kutipay", alternatives: ["muyu"], normalized: "repeat" },
863
+ for: { primary: "sapankaq", normalized: "for" },
864
+ while: { primary: "kaykamaqa", normalized: "while" },
865
+ continue: { primary: "qatipay", normalized: "continue" },
866
+ halt: { primary: "sayay", alternatives: ["tukuy"], normalized: "halt" },
867
+ throw: { primary: "chanqay", normalized: "throw" },
868
+ call: { primary: "waqyay", normalized: "call" },
869
+ return: { primary: "kutichiy", alternatives: ["kutimuy"], normalized: "return" },
870
+ then: { primary: "chaymantataq", alternatives: ["hinaspa", "chaymanta"], normalized: "then" },
871
+ and: { primary: "hinallataq", alternatives: ["ima", "chaymantawan"], normalized: "and" },
872
+ end: { primary: "tukukuy", alternatives: ["tukuy", "puchukay"], normalized: "end" },
873
+ js: { primary: "js", normalized: "js" },
874
+ async: { primary: "mana waqtalla", normalized: "async" },
875
+ tell: { primary: "niy", alternatives: ["willakuy"], normalized: "tell" },
876
+ default: { primary: "qallariy", normalized: "default" },
877
+ init: { primary: "qallarichiy", normalized: "init" },
878
+ behavior: { primary: "ruwana", normalized: "behavior" },
879
+ install: { primary: "churay", normalized: "install" },
880
+ measure: { primary: "tupuy", normalized: "measure" },
881
+ into: { primary: "ukuman", normalized: "into" },
882
+ before: { primary: "\xF1awpaq", normalized: "before" },
883
+ after: { primary: "qhipa", normalized: "after" },
884
+ // Event modifiers (for repeat until event)
885
+ until: { primary: "-kama", alternatives: ["kama"], normalized: "until" },
886
+ event: { primary: "ruwakuq", alternatives: ["imayna"], normalized: "event" },
887
+ from: { primary: "-manta", normalized: "from" }
888
+ }
889
+ };
890
+
891
+ // src/tokenizers/quechua.ts
892
+ var { isLetter: isQuechuaLetter, isIdentifierChar: isQuechuaIdentifierChar } = createLatinCharClassifiers(/[a-zA-ZñÑ']/);
893
+ var SUFFIXES = /* @__PURE__ */ new Set([
894
+ "-ta",
895
+ // accusative (direct object)
896
+ "-man",
897
+ // allative (to, towards)
898
+ "-manta",
899
+ // ablative (from)
900
+ "-pi",
901
+ // locative (at, in)
902
+ "-wan",
903
+ // comitative/instrumental (with)
904
+ "-paq",
905
+ // benefactive (for)
906
+ "-kama",
907
+ // limitative (until, up to)
908
+ "-rayku",
909
+ // causative (because of)
910
+ "-hina"
911
+ // simulative (like, as)
912
+ ]);
913
+ var QUECHUA_EXTRAS = [
914
+ // Values/Literals
915
+ { native: "ar\xED", normalized: "true" },
916
+ { native: "ari", normalized: "true" },
917
+ { native: "manan", normalized: "false" },
918
+ { native: "mana", normalized: "false" },
919
+ { native: "ch'usaq", normalized: "null" },
920
+ { native: "chusaq", normalized: "null" },
921
+ { native: "mana riqsisqa", normalized: "undefined" },
922
+ // Positional
923
+ { native: "\xF1awpaq", normalized: "first" },
924
+ { native: "nawpaq", normalized: "first" },
925
+ { native: "qhipa", normalized: "last" },
926
+ { native: "hamuq", normalized: "next" },
927
+ { native: "\xF1awpaq kaq", normalized: "previous" },
928
+ { native: "aswan qayllaqa", normalized: "closest" },
929
+ { native: "tayta", normalized: "parent" },
930
+ // Events
931
+ { native: "llikllay", normalized: "click" },
932
+ { native: "click", normalized: "click" },
933
+ { native: "yaykuy", normalized: "input" },
934
+ { native: "llave uray", normalized: "keydown" },
935
+ { native: "llave hawa", normalized: "keyup" },
936
+ { native: "mausiri yayku", normalized: "mouseover" },
937
+ { native: "mausiri lluqsi", normalized: "mouseout" },
938
+ { native: "qhaway", normalized: "focus" },
939
+ { native: "mana qhaway", normalized: "blur" },
940
+ { native: "kargay", normalized: "load" },
941
+ { native: "muyuy", normalized: "scroll" },
942
+ // References
943
+ { native: "\xF1uqa", normalized: "me" },
944
+ { native: "nuqa", normalized: "me" },
945
+ { native: "\xF1uqap", normalized: "my" },
946
+ { native: "nuqap", normalized: "my" },
947
+ { native: "chay", normalized: "it" },
948
+ { native: "chaymi", normalized: "it" },
949
+ { native: "lluqsiy", normalized: "result" },
950
+ { native: "ruway", normalized: "event" },
951
+ { native: "maypi", normalized: "target" },
952
+ // Time units
953
+ { native: "sikundu", normalized: "s" },
954
+ { native: "segundu", normalized: "s" },
955
+ { native: "waranqa sikundu", normalized: "ms" },
956
+ { native: "minutu", normalized: "m" },
957
+ { native: "ura", normalized: "h" },
958
+ { native: "hora", normalized: "h" },
959
+ // Event triggers (on)
960
+ { native: "chaypim", normalized: "on" },
961
+ { native: "kaypi", normalized: "on" },
962
+ // Control flow helpers
963
+ { native: "chayqa", normalized: "then" },
964
+ { native: "chaymanta", normalized: "then" },
965
+ { native: "chaymantataq", normalized: "then" },
966
+ { native: "hinaspa", normalized: "then" },
967
+ { native: "tukukuy", normalized: "end" },
968
+ { native: "puchukay", normalized: "end" },
969
+ { native: "kaykama", normalized: "until" },
970
+ // Command overrides
971
+ { native: "yapay", normalized: "add" },
972
+ // Profile may have this as 'append'
973
+ { native: "t'ikray", normalized: "toggle" },
974
+ { native: "tikray", normalized: "toggle" },
975
+ // DOM focus
976
+ { native: "qhawachiy", normalized: "focus" },
977
+ { native: "mana qhawachiy", normalized: "blur" },
978
+ // Suffix modifiers
979
+ { native: "-manta", normalized: "from" }
980
+ ];
981
+ var QuechuaTokenizer = class extends BaseTokenizer {
982
+ constructor() {
983
+ super();
984
+ this.language = "qu";
985
+ this.direction = "ltr";
986
+ this.initializeKeywordsFromProfile(quechuaProfile, QUECHUA_EXTRAS);
987
+ }
988
+ tokenize(input) {
989
+ const tokens = [];
990
+ let pos = 0;
991
+ while (pos < input.length) {
992
+ if (isWhitespace(input[pos])) {
993
+ pos++;
994
+ continue;
995
+ }
996
+ if (isSelectorStart(input[pos])) {
997
+ const modifierToken = this.tryEventModifier(input, pos);
998
+ if (modifierToken) {
999
+ tokens.push(modifierToken);
1000
+ pos = modifierToken.position.end;
1001
+ continue;
1002
+ }
1003
+ const selectorToken = this.trySelector(input, pos);
1004
+ if (selectorToken) {
1005
+ tokens.push(selectorToken);
1006
+ pos = selectorToken.position.end;
1007
+ continue;
1008
+ }
1009
+ }
1010
+ if (isQuote(input[pos])) {
1011
+ const stringToken = this.tryString(input, pos);
1012
+ if (stringToken) {
1013
+ tokens.push(stringToken);
1014
+ pos = stringToken.position.end;
1015
+ continue;
1016
+ }
1017
+ }
1018
+ if (isUrlStart(input, pos)) {
1019
+ const urlToken = this.tryUrl(input, pos);
1020
+ if (urlToken) {
1021
+ tokens.push(urlToken);
1022
+ pos = urlToken.position.end;
1023
+ continue;
1024
+ }
1025
+ }
1026
+ if (isDigit(input[pos]) || input[pos] === "-" && pos + 1 < input.length && isDigit(input[pos + 1])) {
1027
+ const numberToken = this.extractNumber(input, pos);
1028
+ if (numberToken) {
1029
+ tokens.push(numberToken);
1030
+ pos = numberToken.position.end;
1031
+ continue;
1032
+ }
1033
+ }
1034
+ const varToken = this.tryVariableRef(input, pos);
1035
+ if (varToken) {
1036
+ tokens.push(varToken);
1037
+ pos = varToken.position.end;
1038
+ continue;
1039
+ }
1040
+ if (input[pos] === "-") {
1041
+ const suffixToken = this.trySuffix(input, pos);
1042
+ if (suffixToken) {
1043
+ tokens.push(suffixToken);
1044
+ pos = suffixToken.position.end;
1045
+ continue;
1046
+ }
1047
+ }
1048
+ if (isQuechuaLetter(input[pos])) {
1049
+ const wordToken = this.extractWord(input, pos);
1050
+ if (wordToken) {
1051
+ tokens.push(wordToken);
1052
+ pos = wordToken.position.end;
1053
+ continue;
1054
+ }
1055
+ }
1056
+ const operatorToken = this.tryOperator(input, pos);
1057
+ if (operatorToken) {
1058
+ tokens.push(operatorToken);
1059
+ pos = operatorToken.position.end;
1060
+ continue;
1061
+ }
1062
+ pos++;
1063
+ }
1064
+ return new TokenStreamImpl(tokens, "qu");
1065
+ }
1066
+ classifyToken(token) {
1067
+ const lower = token.toLowerCase();
1068
+ if (SUFFIXES.has(lower)) return "particle";
1069
+ if (this.isKeyword(lower)) return "keyword";
1070
+ if (token.startsWith("#") || token.startsWith(".") || token.startsWith("[")) return "selector";
1071
+ if (token.startsWith('"') || token.startsWith("'")) return "literal";
1072
+ if (/^\d/.test(token)) return "literal";
1073
+ return "identifier";
1074
+ }
1075
+ trySuffix(input, startPos) {
1076
+ for (const suffix of SUFFIXES) {
1077
+ if (input.slice(startPos, startPos + suffix.length).toLowerCase() === suffix) {
1078
+ return createToken(
1079
+ input.slice(startPos, startPos + suffix.length),
1080
+ "particle",
1081
+ createPosition(startPos, startPos + suffix.length)
1082
+ );
1083
+ }
1084
+ }
1085
+ return null;
1086
+ }
1087
+ extractWord(input, startPos) {
1088
+ let pos = startPos;
1089
+ let word = "";
1090
+ while (pos < input.length && isQuechuaIdentifierChar(input[pos])) {
1091
+ word += input[pos++];
1092
+ }
1093
+ if (!word) return null;
1094
+ const lower = word.toLowerCase();
1095
+ const keywordEntry = this.lookupKeyword(lower);
1096
+ if (keywordEntry) {
1097
+ return createToken(word, "keyword", createPosition(startPos, pos), keywordEntry.normalized);
1098
+ }
1099
+ return createToken(word, "identifier", createPosition(startPos, pos));
1100
+ }
1101
+ extractNumber(input, startPos) {
1102
+ let pos = startPos;
1103
+ let number = "";
1104
+ if (input[pos] === "-" || input[pos] === "+") {
1105
+ number += input[pos++];
1106
+ }
1107
+ while (pos < input.length && isDigit(input[pos])) {
1108
+ number += input[pos++];
1109
+ }
1110
+ if (pos < input.length && input[pos] === ".") {
1111
+ number += input[pos++];
1112
+ while (pos < input.length && isDigit(input[pos])) {
1113
+ number += input[pos++];
1114
+ }
1115
+ }
1116
+ let unitPos = pos;
1117
+ while (unitPos < input.length && isWhitespace(input[unitPos])) {
1118
+ unitPos++;
1119
+ }
1120
+ const remaining = input.slice(unitPos).toLowerCase();
1121
+ if (remaining.startsWith("sikundu") || remaining.startsWith("segundu")) {
1122
+ number += "s";
1123
+ pos = unitPos + 7;
1124
+ } else if (remaining.startsWith("minutu")) {
1125
+ number += "m";
1126
+ pos = unitPos + 6;
1127
+ } else if (remaining.startsWith("hora") || remaining.startsWith("ura")) {
1128
+ number += "h";
1129
+ pos = unitPos + (remaining.startsWith("hora") ? 4 : 3);
1130
+ }
1131
+ if (!number || number === "-" || number === "+") return null;
1132
+ return createToken(number, "literal", createPosition(startPos, pos));
1133
+ }
1134
+ };
1135
+ var quechuaTokenizer = new QuechuaTokenizer();
1136
+
1137
+ // src/languages/qu.ts
1138
+ registerLanguage("qu", quechuaTokenizer, quechuaProfile);
1139
+ export {
1140
+ quechuaProfile,
1141
+ quechuaTokenizer
1142
+ };
1143
+ //# sourceMappingURL=qu.js.map