@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,1152 @@
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/indonesian.ts
781
+ var indonesianProfile = {
782
+ code: "id",
783
+ name: "Indonesian",
784
+ nativeName: "Bahasa Indonesia",
785
+ direction: "ltr",
786
+ wordOrder: "SVO",
787
+ markingStrategy: "preposition",
788
+ usesSpaces: true,
789
+ verb: {
790
+ position: "start",
791
+ subjectDrop: true
792
+ },
793
+ references: {
794
+ me: "saya",
795
+ // "I/me"
796
+ it: "itu",
797
+ // "it"
798
+ you: "anda",
799
+ // "you"
800
+ result: "hasil",
801
+ event: "peristiwa",
802
+ target: "target",
803
+ body: "tubuh"
804
+ },
805
+ possessive: {
806
+ marker: "",
807
+ // Indonesian: "X saya" (X of mine), possessor follows noun
808
+ markerPosition: "after-object",
809
+ usePossessiveAdjectives: true,
810
+ specialForms: {
811
+ me: "saya",
812
+ // Possessor follows: "value saya" = "my value"
813
+ it: "nya",
814
+ // Suffix: "valueny" = "its value"
815
+ you: "anda"
816
+ // "value anda" = "your value"
817
+ },
818
+ keywords: {
819
+ // "my" - formal and informal
820
+ saya: "me",
821
+ // formal
822
+ aku: "me",
823
+ // informal
824
+ ku: "me",
825
+ // clitic
826
+ // "your" - formal and informal
827
+ anda: "you",
828
+ // formal
829
+ kamu: "you",
830
+ // informal
831
+ mu: "you",
832
+ // clitic
833
+ // "its/his/her"
834
+ nya: "it",
835
+ // third person clitic (suffix form: -nya)
836
+ dia: "it"
837
+ // third person pronoun
838
+ }
839
+ },
840
+ roleMarkers: {
841
+ destination: { primary: "pada", alternatives: ["ke", "di"], position: "before" },
842
+ source: { primary: "dari", position: "before" },
843
+ patient: { primary: "", position: "before" },
844
+ style: { primary: "dengan", position: "before" }
845
+ },
846
+ keywords: {
847
+ toggle: { primary: "alihkan", alternatives: ["ganti", "tukar"], normalized: "toggle" },
848
+ add: { primary: "tambah", alternatives: ["tambahkan"], normalized: "add" },
849
+ remove: { primary: "hapus", alternatives: ["buang", "hilangkan"], normalized: "remove" },
850
+ put: { primary: "taruh", alternatives: ["letakkan", "masukkan"], normalized: "put" },
851
+ append: { primary: "sisipkan", normalized: "append" },
852
+ prepend: { primary: "awali", normalized: "prepend" },
853
+ take: { primary: "ambil", normalized: "take" },
854
+ make: { primary: "buat", alternatives: ["bikin", "ciptakan"], normalized: "make" },
855
+ clone: { primary: "klon", alternatives: ["salin", "tiru"], normalized: "clone" },
856
+ swap: { primary: "tukar", alternatives: ["ganti"], normalized: "swap" },
857
+ morph: { primary: "ubah", alternatives: ["transformasi"], normalized: "morph" },
858
+ set: { primary: "atur", alternatives: ["tetapkan"], normalized: "set" },
859
+ get: { primary: "dapatkan", alternatives: ["peroleh"], normalized: "get" },
860
+ increment: { primary: "tingkatkan", alternatives: ["naikkan"], normalized: "increment" },
861
+ decrement: { primary: "turunkan", alternatives: ["kurangi"], normalized: "decrement" },
862
+ log: { primary: "catat", alternatives: ["rekam", "cetak"], normalized: "log" },
863
+ show: { primary: "tampilkan", alternatives: ["perlihatkan"], normalized: "show" },
864
+ hide: { primary: "sembunyikan", alternatives: ["tutup"], normalized: "hide" },
865
+ transition: { primary: "transisi", alternatives: ["animasikan"], normalized: "transition" },
866
+ on: { primary: "pada", alternatives: ["saat", "ketika"], normalized: "on" },
867
+ trigger: { primary: "picu", alternatives: ["jalankan"], normalized: "trigger" },
868
+ send: { primary: "kirim", alternatives: ["kirimkan"], normalized: "send" },
869
+ focus: { primary: "fokus", alternatives: ["fokuskan"], normalized: "focus" },
870
+ blur: { primary: "blur", normalized: "blur" },
871
+ go: { primary: "pergi", alternatives: ["pindah", "navigasi"], normalized: "go" },
872
+ wait: { primary: "tunggu", normalized: "wait" },
873
+ fetch: { primary: "ambil", alternatives: ["muat"], normalized: "fetch" },
874
+ settle: { primary: "stabilkan", normalized: "settle" },
875
+ if: { primary: "jika", alternatives: ["kalau", "bila"], normalized: "if" },
876
+ when: { primary: "ketika", normalized: "when" },
877
+ where: { primary: "di_mana", normalized: "where" },
878
+ else: { primary: "selainnya", normalized: "else" },
879
+ repeat: { primary: "ulangi", normalized: "repeat" },
880
+ for: { primary: "untuk", normalized: "for" },
881
+ while: { primary: "selama", normalized: "while" },
882
+ continue: { primary: "lanjutkan", alternatives: ["terus"], normalized: "continue" },
883
+ halt: { primary: "hentikan", alternatives: ["berhenti"], normalized: "halt" },
884
+ throw: { primary: "lempar", normalized: "throw" },
885
+ call: { primary: "panggil", normalized: "call" },
886
+ return: { primary: "kembalikan", alternatives: ["kembali"], normalized: "return" },
887
+ then: { primary: "lalu", alternatives: ["kemudian", "setelah itu"], normalized: "then" },
888
+ and: { primary: "dan", alternatives: ["juga", "serta"], normalized: "and" },
889
+ end: { primary: "selesai", alternatives: ["akhir", "tamat"], normalized: "end" },
890
+ js: { primary: "js", alternatives: ["javascript"], normalized: "js" },
891
+ async: { primary: "asinkron", normalized: "async" },
892
+ tell: { primary: "katakan", alternatives: ["beritahu"], normalized: "tell" },
893
+ default: { primary: "bawaan", normalized: "default" },
894
+ init: { primary: "inisialisasi", alternatives: ["mulai"], normalized: "init" },
895
+ behavior: { primary: "perilaku", normalized: "behavior" },
896
+ install: { primary: "pasang", alternatives: ["instal"], normalized: "install" },
897
+ measure: { primary: "ukur", normalized: "measure" },
898
+ into: { primary: "ke dalam", normalized: "into" },
899
+ before: { primary: "sebelum", normalized: "before" },
900
+ after: { primary: "sesudah", alternatives: ["setelah"], normalized: "after" },
901
+ // Event modifiers (for repeat until event)
902
+ until: { primary: "sampai", normalized: "until" },
903
+ event: { primary: "peristiwa", alternatives: ["event"], normalized: "event" },
904
+ from: { primary: "dari", normalized: "from" }
905
+ },
906
+ eventHandler: {
907
+ keyword: { primary: "pada", alternatives: ["ketika", "saat"] },
908
+ sourceMarker: { primary: "dari", position: "before" },
909
+ conditionalKeyword: { primary: "ketika", alternatives: ["saat", "waktu"] }
910
+ }
911
+ };
912
+
913
+ // src/tokenizers/indonesian.ts
914
+ var { isLetter: isIndonesianLetter, isIdentifierChar: isIndonesianIdentifierChar } = createLatinCharClassifiers(/[a-zA-Z]/);
915
+ var PREPOSITIONS = /* @__PURE__ */ new Set([
916
+ "di",
917
+ // at, in
918
+ "ke",
919
+ // to
920
+ "dari",
921
+ // from
922
+ "pada",
923
+ // on, at
924
+ "dengan",
925
+ // with
926
+ "tanpa",
927
+ // without
928
+ "untuk",
929
+ // for
930
+ "oleh",
931
+ // by
932
+ "antara",
933
+ // between
934
+ "sebelum",
935
+ // before
936
+ "sesudah",
937
+ // after
938
+ "setelah",
939
+ // after
940
+ "selama",
941
+ // during
942
+ "sampai",
943
+ // until
944
+ "hingga",
945
+ // until
946
+ "sejak",
947
+ // since
948
+ "menuju",
949
+ // towards
950
+ "tentang",
951
+ // about
952
+ "terhadap",
953
+ // towards, against
954
+ "melalui",
955
+ // through
956
+ "dalam",
957
+ // inside
958
+ "luar"
959
+ // outside
960
+ ]);
961
+ var INDONESIAN_EXTRAS = [
962
+ // Values/Literals
963
+ { native: "benar", normalized: "true" },
964
+ { native: "salah", normalized: "false" },
965
+ { native: "null", normalized: "null" },
966
+ { native: "kosong", normalized: "null" },
967
+ { native: "tidak terdefinisi", normalized: "undefined" },
968
+ // Positional
969
+ { native: "pertama", normalized: "first" },
970
+ { native: "terakhir", normalized: "last" },
971
+ { native: "selanjutnya", normalized: "next" },
972
+ { native: "berikutnya", normalized: "next" },
973
+ { native: "sebelumnya", normalized: "previous" },
974
+ { native: "terdekat", normalized: "closest" },
975
+ { native: "induk", normalized: "parent" },
976
+ // Events
977
+ { native: "klik", normalized: "click" },
978
+ { native: "click", normalized: "click" },
979
+ { native: "masukan", normalized: "input" },
980
+ { native: "input", normalized: "input" },
981
+ { native: "perubahan", normalized: "change" },
982
+ { native: "tombol turun", normalized: "keydown" },
983
+ { native: "tombol naik", normalized: "keyup" },
984
+ { native: "mouse masuk", normalized: "mouseover" },
985
+ { native: "mouse keluar", normalized: "mouseout" },
986
+ { native: "gulir", normalized: "scroll" },
987
+ // Additional references
988
+ { native: "aku", normalized: "me" },
989
+ { native: "ini", normalized: "me" },
990
+ { native: "milikku", normalized: "my" },
991
+ { native: "dia", normalized: "it" },
992
+ { native: "kejadian", normalized: "event" },
993
+ { native: "sasaran", normalized: "target" },
994
+ // Time units
995
+ { native: "detik", normalized: "s" },
996
+ { native: "milidetik", normalized: "ms" },
997
+ { native: "menit", normalized: "m" },
998
+ { native: "jam", normalized: "h" },
999
+ // Additional synonyms and multi-word phrases
1000
+ { native: "jika tidak", normalized: "else" },
1001
+ { native: "hilangkan fokus", normalized: "blur" },
1002
+ { native: "maka", normalized: "then" }
1003
+ ];
1004
+ var IndonesianTokenizer = class extends BaseTokenizer {
1005
+ constructor() {
1006
+ super();
1007
+ this.language = "id";
1008
+ this.direction = "ltr";
1009
+ this.initializeKeywordsFromProfile(indonesianProfile, INDONESIAN_EXTRAS);
1010
+ }
1011
+ tokenize(input) {
1012
+ const tokens = [];
1013
+ let pos = 0;
1014
+ while (pos < input.length) {
1015
+ if (isWhitespace(input[pos])) {
1016
+ pos++;
1017
+ continue;
1018
+ }
1019
+ if (isSelectorStart(input[pos])) {
1020
+ const modifierToken = this.tryEventModifier(input, pos);
1021
+ if (modifierToken) {
1022
+ tokens.push(modifierToken);
1023
+ pos = modifierToken.position.end;
1024
+ continue;
1025
+ }
1026
+ const selectorToken = this.trySelector(input, pos);
1027
+ if (selectorToken) {
1028
+ tokens.push(selectorToken);
1029
+ pos = selectorToken.position.end;
1030
+ continue;
1031
+ }
1032
+ }
1033
+ if (isQuote(input[pos])) {
1034
+ const stringToken = this.tryString(input, pos);
1035
+ if (stringToken) {
1036
+ tokens.push(stringToken);
1037
+ pos = stringToken.position.end;
1038
+ continue;
1039
+ }
1040
+ }
1041
+ if (isUrlStart(input, pos)) {
1042
+ const urlToken = this.tryUrl(input, pos);
1043
+ if (urlToken) {
1044
+ tokens.push(urlToken);
1045
+ pos = urlToken.position.end;
1046
+ continue;
1047
+ }
1048
+ }
1049
+ if (isDigit(input[pos]) || input[pos] === "-" && pos + 1 < input.length && isDigit(input[pos + 1])) {
1050
+ const numberToken = this.extractNumber(input, pos);
1051
+ if (numberToken) {
1052
+ tokens.push(numberToken);
1053
+ pos = numberToken.position.end;
1054
+ continue;
1055
+ }
1056
+ }
1057
+ const varToken = this.tryVariableRef(input, pos);
1058
+ if (varToken) {
1059
+ tokens.push(varToken);
1060
+ pos = varToken.position.end;
1061
+ continue;
1062
+ }
1063
+ if (isIndonesianLetter(input[pos])) {
1064
+ const wordToken = this.extractWord(input, pos);
1065
+ if (wordToken) {
1066
+ tokens.push(wordToken);
1067
+ pos = wordToken.position.end;
1068
+ continue;
1069
+ }
1070
+ }
1071
+ const operatorToken = this.tryOperator(input, pos);
1072
+ if (operatorToken) {
1073
+ tokens.push(operatorToken);
1074
+ pos = operatorToken.position.end;
1075
+ continue;
1076
+ }
1077
+ pos++;
1078
+ }
1079
+ return new TokenStreamImpl(tokens, "id");
1080
+ }
1081
+ classifyToken(token) {
1082
+ const lower = token.toLowerCase();
1083
+ if (PREPOSITIONS.has(lower)) return "particle";
1084
+ if (this.isKeyword(lower)) return "keyword";
1085
+ if (token.startsWith("#") || token.startsWith(".") || token.startsWith("[")) return "selector";
1086
+ if (token.startsWith('"') || token.startsWith("'")) return "literal";
1087
+ if (/^\d/.test(token)) return "literal";
1088
+ return "identifier";
1089
+ }
1090
+ extractWord(input, startPos) {
1091
+ let pos = startPos;
1092
+ let word = "";
1093
+ while (pos < input.length && isIndonesianIdentifierChar(input[pos])) {
1094
+ word += input[pos++];
1095
+ }
1096
+ if (!word) return null;
1097
+ const lower = word.toLowerCase();
1098
+ const keywordEntry = this.lookupKeyword(lower);
1099
+ if (keywordEntry) {
1100
+ return createToken(word, "keyword", createPosition(startPos, pos), keywordEntry.normalized);
1101
+ }
1102
+ if (PREPOSITIONS.has(lower)) {
1103
+ return createToken(word, "particle", createPosition(startPos, pos));
1104
+ }
1105
+ return createToken(word, "identifier", createPosition(startPos, pos));
1106
+ }
1107
+ extractNumber(input, startPos) {
1108
+ let pos = startPos;
1109
+ let number = "";
1110
+ if (input[pos] === "-" || input[pos] === "+") {
1111
+ number += input[pos++];
1112
+ }
1113
+ while (pos < input.length && isDigit(input[pos])) {
1114
+ number += input[pos++];
1115
+ }
1116
+ if (pos < input.length && input[pos] === ".") {
1117
+ number += input[pos++];
1118
+ while (pos < input.length && isDigit(input[pos])) {
1119
+ number += input[pos++];
1120
+ }
1121
+ }
1122
+ let unitPos = pos;
1123
+ while (unitPos < input.length && isWhitespace(input[unitPos])) {
1124
+ unitPos++;
1125
+ }
1126
+ const remaining = input.slice(unitPos).toLowerCase();
1127
+ if (remaining.startsWith("milidetik")) {
1128
+ number += "ms";
1129
+ pos = unitPos + 9;
1130
+ } else if (remaining.startsWith("detik")) {
1131
+ number += "s";
1132
+ pos = unitPos + 5;
1133
+ } else if (remaining.startsWith("menit")) {
1134
+ number += "m";
1135
+ pos = unitPos + 5;
1136
+ } else if (remaining.startsWith("jam")) {
1137
+ number += "h";
1138
+ pos = unitPos + 3;
1139
+ }
1140
+ if (!number || number === "-" || number === "+") return null;
1141
+ return createToken(number, "literal", createPosition(startPos, pos));
1142
+ }
1143
+ };
1144
+ var indonesianTokenizer = new IndonesianTokenizer();
1145
+
1146
+ // src/languages/id.ts
1147
+ registerLanguage("id", indonesianTokenizer, indonesianProfile);
1148
+ export {
1149
+ indonesianProfile,
1150
+ indonesianTokenizer
1151
+ };
1152
+ //# sourceMappingURL=id.js.map