@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,1493 @@
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: normalized2, stem, stemConfidence } = normalizedOrOptions;
77
+ const token = { value, kind, position };
78
+ if (normalized2 !== void 0) {
79
+ token.normalized = normalized2;
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 [normalized2, translation] of Object.entries(profile.keywords)) {
395
+ keywordMap.set(translation.primary, {
396
+ native: translation.primary,
397
+ normalized: translation.normalized || normalized2
398
+ });
399
+ if (translation.alternatives) {
400
+ for (const alt of translation.alternatives) {
401
+ keywordMap.set(alt, {
402
+ native: alt,
403
+ normalized: translation.normalized || normalized2
404
+ });
405
+ }
406
+ }
407
+ }
408
+ }
409
+ if (profile.references) {
410
+ for (const [normalized2, native] of Object.entries(profile.references)) {
411
+ keywordMap.set(native, { native, normalized: normalized2 });
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 normalized2 = this.removeDiacritics(keyword.native);
436
+ if (normalized2 !== keyword.native && !this.profileKeywordMap.has(normalized2.toLowerCase())) {
437
+ this.profileKeywordMap.set(normalized2.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/tokenizers/morphology/types.ts
781
+ function noChange(word) {
782
+ return { stem: word, confidence: 1 };
783
+ }
784
+ function normalized(stem, confidence, metadata) {
785
+ if (metadata) {
786
+ return { stem, confidence, metadata };
787
+ }
788
+ return { stem, confidence };
789
+ }
790
+
791
+ // src/tokenizers/morphology/spanish-normalizer.ts
792
+ function isSpanishSpecificLetter(char) {
793
+ return /[áéíóúüñÁÉÍÓÚÜÑ]/.test(char);
794
+ }
795
+ function looksLikeSpanishVerb(word) {
796
+ const lower = word.toLowerCase();
797
+ if (lower.endsWith("ar") || lower.endsWith("er") || lower.endsWith("ir")) return true;
798
+ if (lower.endsWith("ando") || lower.endsWith("iendo")) return true;
799
+ if (lower.endsWith("ado") || lower.endsWith("ido")) return true;
800
+ if (lower.endsWith("arse") || lower.endsWith("erse") || lower.endsWith("irse")) return true;
801
+ for (const char of word) {
802
+ if (isSpanishSpecificLetter(char)) return true;
803
+ }
804
+ return false;
805
+ }
806
+ var REFLEXIVE_SUFFIXES = ["se", "me", "te", "nos", "os"];
807
+ var AR_ENDINGS = [
808
+ // Gerund (-ando)
809
+ { ending: "ando", stem: "ar", confidence: 0.88, type: "gerund" },
810
+ // Past participle (-ado)
811
+ { ending: "ado", stem: "ar", confidence: 0.88, type: "participle" },
812
+ { ending: "ada", stem: "ar", confidence: 0.88, type: "participle" },
813
+ { ending: "ados", stem: "ar", confidence: 0.88, type: "participle" },
814
+ { ending: "adas", stem: "ar", confidence: 0.88, type: "participle" },
815
+ // Present indicative
816
+ { ending: "o", stem: "ar", confidence: 0.75, type: "present" },
817
+ // yo
818
+ { ending: "as", stem: "ar", confidence: 0.82, type: "present" },
819
+ // tú
820
+ { ending: "a", stem: "ar", confidence: 0.75, type: "present" },
821
+ // él/ella
822
+ { ending: "amos", stem: "ar", confidence: 0.85, type: "present" },
823
+ // nosotros
824
+ { ending: "\xE1is", stem: "ar", confidence: 0.85, type: "present" },
825
+ // vosotros
826
+ { ending: "ais", stem: "ar", confidence: 0.82, type: "present" },
827
+ // vosotros (no accent)
828
+ { ending: "an", stem: "ar", confidence: 0.8, type: "present" },
829
+ // ellos
830
+ // Preterite
831
+ { ending: "\xE9", stem: "ar", confidence: 0.85, type: "past" },
832
+ // yo
833
+ { ending: "aste", stem: "ar", confidence: 0.88, type: "past" },
834
+ // tú
835
+ { ending: "\xF3", stem: "ar", confidence: 0.82, type: "past" },
836
+ // él/ella
837
+ { ending: "amos", stem: "ar", confidence: 0.85, type: "past" },
838
+ // nosotros (same as present)
839
+ { ending: "asteis", stem: "ar", confidence: 0.88, type: "past" },
840
+ // vosotros
841
+ { ending: "aron", stem: "ar", confidence: 0.88, type: "past" },
842
+ // ellos
843
+ // Imperfect
844
+ { ending: "aba", stem: "ar", confidence: 0.88, type: "past" },
845
+ // yo/él
846
+ { ending: "abas", stem: "ar", confidence: 0.88, type: "past" },
847
+ // tú
848
+ { ending: "\xE1bamos", stem: "ar", confidence: 0.88, type: "past" },
849
+ // nosotros
850
+ { ending: "abamos", stem: "ar", confidence: 0.85, type: "past" },
851
+ // nosotros (no accent)
852
+ { ending: "abais", stem: "ar", confidence: 0.88, type: "past" },
853
+ // vosotros
854
+ { ending: "aban", stem: "ar", confidence: 0.88, type: "past" },
855
+ // ellos
856
+ // Subjunctive
857
+ { ending: "e", stem: "ar", confidence: 0.72, type: "subjunctive" },
858
+ // yo/él (ambiguous)
859
+ { ending: "es", stem: "ar", confidence: 0.78, type: "subjunctive" },
860
+ // tú
861
+ { ending: "emos", stem: "ar", confidence: 0.82, type: "subjunctive" },
862
+ // nosotros
863
+ { ending: "\xE9is", stem: "ar", confidence: 0.85, type: "subjunctive" },
864
+ // vosotros
865
+ { ending: "eis", stem: "ar", confidence: 0.82, type: "subjunctive" },
866
+ // vosotros (no accent)
867
+ { ending: "en", stem: "ar", confidence: 0.78, type: "subjunctive" },
868
+ // ellos
869
+ // Imperative
870
+ { ending: "a", stem: "ar", confidence: 0.75, type: "imperative" },
871
+ // tú (same as 3rd present)
872
+ { ending: "ad", stem: "ar", confidence: 0.85, type: "imperative" },
873
+ // vosotros
874
+ // Infinitive
875
+ { ending: "ar", stem: "ar", confidence: 0.92, type: "dictionary" }
876
+ ];
877
+ var ER_ENDINGS = [
878
+ // Gerund (-iendo)
879
+ { ending: "iendo", stem: "er", confidence: 0.88, type: "gerund" },
880
+ // Past participle (-ido)
881
+ { ending: "ido", stem: "er", confidence: 0.85, type: "participle" },
882
+ { ending: "ida", stem: "er", confidence: 0.85, type: "participle" },
883
+ { ending: "idos", stem: "er", confidence: 0.85, type: "participle" },
884
+ { ending: "idas", stem: "er", confidence: 0.85, type: "participle" },
885
+ // Present indicative
886
+ { ending: "o", stem: "er", confidence: 0.72, type: "present" },
887
+ // yo
888
+ { ending: "es", stem: "er", confidence: 0.78, type: "present" },
889
+ // tú
890
+ { ending: "e", stem: "er", confidence: 0.72, type: "present" },
891
+ // él/ella
892
+ { ending: "emos", stem: "er", confidence: 0.85, type: "present" },
893
+ // nosotros
894
+ { ending: "\xE9is", stem: "er", confidence: 0.85, type: "present" },
895
+ // vosotros
896
+ { ending: "eis", stem: "er", confidence: 0.82, type: "present" },
897
+ // vosotros (no accent)
898
+ { ending: "en", stem: "er", confidence: 0.78, type: "present" },
899
+ // ellos
900
+ // Preterite
901
+ { ending: "\xED", stem: "er", confidence: 0.85, type: "past" },
902
+ // yo
903
+ { ending: "iste", stem: "er", confidence: 0.88, type: "past" },
904
+ // tú
905
+ { ending: "i\xF3", stem: "er", confidence: 0.85, type: "past" },
906
+ // él/ella
907
+ { ending: "io", stem: "er", confidence: 0.82, type: "past" },
908
+ // él/ella (no accent)
909
+ { ending: "imos", stem: "er", confidence: 0.85, type: "past" },
910
+ // nosotros
911
+ { ending: "isteis", stem: "er", confidence: 0.88, type: "past" },
912
+ // vosotros
913
+ { ending: "ieron", stem: "er", confidence: 0.88, type: "past" },
914
+ // ellos
915
+ // Imperfect
916
+ { ending: "\xEDa", stem: "er", confidence: 0.88, type: "past" },
917
+ // yo/él
918
+ { ending: "ia", stem: "er", confidence: 0.85, type: "past" },
919
+ // yo/él (no accent)
920
+ { ending: "\xEDas", stem: "er", confidence: 0.88, type: "past" },
921
+ // tú
922
+ { ending: "ias", stem: "er", confidence: 0.85, type: "past" },
923
+ // tú (no accent)
924
+ { ending: "\xEDamos", stem: "er", confidence: 0.88, type: "past" },
925
+ // nosotros
926
+ { ending: "iamos", stem: "er", confidence: 0.85, type: "past" },
927
+ // nosotros (no accent)
928
+ { ending: "\xEDais", stem: "er", confidence: 0.88, type: "past" },
929
+ // vosotros
930
+ { ending: "iais", stem: "er", confidence: 0.85, type: "past" },
931
+ // vosotros (no accent)
932
+ { ending: "\xEDan", stem: "er", confidence: 0.88, type: "past" },
933
+ // ellos
934
+ { ending: "ian", stem: "er", confidence: 0.85, type: "past" },
935
+ // ellos (no accent)
936
+ // Infinitive
937
+ { ending: "er", stem: "er", confidence: 0.92, type: "dictionary" }
938
+ ];
939
+ var IR_ENDINGS = [
940
+ // Gerund (-iendo)
941
+ { ending: "iendo", stem: "ir", confidence: 0.88, type: "gerund" },
942
+ // Past participle (-ido)
943
+ { ending: "ido", stem: "ir", confidence: 0.85, type: "participle" },
944
+ { ending: "ida", stem: "ir", confidence: 0.85, type: "participle" },
945
+ { ending: "idos", stem: "ir", confidence: 0.85, type: "participle" },
946
+ { ending: "idas", stem: "ir", confidence: 0.85, type: "participle" },
947
+ // Present indicative
948
+ { ending: "o", stem: "ir", confidence: 0.72, type: "present" },
949
+ // yo
950
+ { ending: "es", stem: "ir", confidence: 0.78, type: "present" },
951
+ // tú
952
+ { ending: "e", stem: "ir", confidence: 0.72, type: "present" },
953
+ // él/ella
954
+ { ending: "imos", stem: "ir", confidence: 0.85, type: "present" },
955
+ // nosotros
956
+ { ending: "\xEDs", stem: "ir", confidence: 0.85, type: "present" },
957
+ // vosotros
958
+ { ending: "is", stem: "ir", confidence: 0.82, type: "present" },
959
+ // vosotros (no accent)
960
+ { ending: "en", stem: "ir", confidence: 0.78, type: "present" },
961
+ // ellos
962
+ // Preterite (same as -er)
963
+ { ending: "\xED", stem: "ir", confidence: 0.85, type: "past" },
964
+ // yo
965
+ { ending: "iste", stem: "ir", confidence: 0.88, type: "past" },
966
+ // tú
967
+ { ending: "i\xF3", stem: "ir", confidence: 0.85, type: "past" },
968
+ // él/ella
969
+ { ending: "io", stem: "ir", confidence: 0.82, type: "past" },
970
+ // él/ella (no accent)
971
+ { ending: "imos", stem: "ir", confidence: 0.85, type: "past" },
972
+ // nosotros
973
+ { ending: "isteis", stem: "ir", confidence: 0.88, type: "past" },
974
+ // vosotros
975
+ { ending: "ieron", stem: "ir", confidence: 0.88, type: "past" },
976
+ // ellos
977
+ // Imperfect (same as -er)
978
+ { ending: "\xEDa", stem: "ir", confidence: 0.88, type: "past" },
979
+ { ending: "ia", stem: "ir", confidence: 0.85, type: "past" },
980
+ { ending: "\xEDas", stem: "ir", confidence: 0.88, type: "past" },
981
+ { ending: "ias", stem: "ir", confidence: 0.85, type: "past" },
982
+ { ending: "\xEDamos", stem: "ir", confidence: 0.88, type: "past" },
983
+ { ending: "iamos", stem: "ir", confidence: 0.85, type: "past" },
984
+ { ending: "\xEDais", stem: "ir", confidence: 0.88, type: "past" },
985
+ { ending: "iais", stem: "ir", confidence: 0.85, type: "past" },
986
+ { ending: "\xEDan", stem: "ir", confidence: 0.88, type: "past" },
987
+ { ending: "ian", stem: "ir", confidence: 0.85, type: "past" },
988
+ // Infinitive
989
+ { ending: "ir", stem: "ir", confidence: 0.92, type: "dictionary" }
990
+ ];
991
+ var ALL_ENDINGS = [...AR_ENDINGS, ...ER_ENDINGS, ...IR_ENDINGS].sort(
992
+ (a, b) => b.ending.length - a.ending.length
993
+ );
994
+ var SpanishMorphologicalNormalizer = class {
995
+ constructor() {
996
+ this.language = "es";
997
+ }
998
+ /**
999
+ * Check if a word might be a Spanish verb that can be normalized.
1000
+ */
1001
+ isNormalizable(word) {
1002
+ if (word.length < 3) return false;
1003
+ return looksLikeSpanishVerb(word);
1004
+ }
1005
+ /**
1006
+ * Normalize a Spanish word to its infinitive form.
1007
+ */
1008
+ normalize(word) {
1009
+ const lower = word.toLowerCase();
1010
+ if (lower.endsWith("ar") || lower.endsWith("er") || lower.endsWith("ir")) {
1011
+ if (!REFLEXIVE_SUFFIXES.some(
1012
+ (s) => lower.endsWith(s + "ar") || lower.endsWith(s + "er") || lower.endsWith(s + "ir")
1013
+ )) {
1014
+ return noChange(word);
1015
+ }
1016
+ }
1017
+ const reflexiveResult = this.tryReflexiveNormalization(lower);
1018
+ if (reflexiveResult) return reflexiveResult;
1019
+ const conjugationResult = this.tryConjugationNormalization(lower);
1020
+ if (conjugationResult) return conjugationResult;
1021
+ return noChange(word);
1022
+ }
1023
+ /**
1024
+ * Try to normalize a reflexive verb.
1025
+ * Reflexive verbs end with -se, -me, -te, -nos, -os attached to infinitive.
1026
+ *
1027
+ * Examples:
1028
+ * mostrarse → mostrar
1029
+ * ocultarse → ocultar
1030
+ * esconderse → esconder
1031
+ */
1032
+ tryReflexiveNormalization(word) {
1033
+ for (const suffix of REFLEXIVE_SUFFIXES) {
1034
+ if (word.endsWith(suffix)) {
1035
+ const withoutReflexive = word.slice(0, -suffix.length);
1036
+ if (withoutReflexive.endsWith("ar") || withoutReflexive.endsWith("er") || withoutReflexive.endsWith("ir")) {
1037
+ return normalized(withoutReflexive, 0.88, {
1038
+ removedSuffixes: [suffix],
1039
+ conjugationType: "reflexive"
1040
+ });
1041
+ }
1042
+ const innerResult = this.tryConjugationNormalization(withoutReflexive);
1043
+ if (innerResult && innerResult.stem !== withoutReflexive) {
1044
+ return normalized(innerResult.stem, innerResult.confidence * 0.95, {
1045
+ removedSuffixes: [suffix, ...innerResult.metadata?.removedSuffixes || []],
1046
+ conjugationType: "reflexive"
1047
+ });
1048
+ }
1049
+ }
1050
+ }
1051
+ return null;
1052
+ }
1053
+ /**
1054
+ * Try to normalize a conjugated verb to its infinitive.
1055
+ */
1056
+ tryConjugationNormalization(word) {
1057
+ for (const rule of ALL_ENDINGS) {
1058
+ if (word.endsWith(rule.ending)) {
1059
+ const stemBase = word.slice(0, -rule.ending.length);
1060
+ if (stemBase.length < 2) continue;
1061
+ const infinitive = stemBase + rule.stem;
1062
+ return normalized(infinitive, rule.confidence, {
1063
+ removedSuffixes: [rule.ending],
1064
+ conjugationType: rule.type
1065
+ });
1066
+ }
1067
+ }
1068
+ return null;
1069
+ }
1070
+ };
1071
+ var spanishMorphologicalNormalizer = new SpanishMorphologicalNormalizer();
1072
+
1073
+ // src/generators/profiles/spanish.ts
1074
+ var spanishProfile = {
1075
+ code: "es",
1076
+ name: "Spanish",
1077
+ nativeName: "Espa\xF1ol",
1078
+ direction: "ltr",
1079
+ wordOrder: "SVO",
1080
+ markingStrategy: "preposition",
1081
+ usesSpaces: true,
1082
+ // Infinitive is standard for Spanish software UI (Guardar, Cancelar, Abrir)
1083
+ // This matches macOS, Windows, and web app conventions
1084
+ defaultVerbForm: "infinitive",
1085
+ verb: {
1086
+ position: "start",
1087
+ subjectDrop: true
1088
+ },
1089
+ references: {
1090
+ me: "yo",
1091
+ // "I/me"
1092
+ it: "ello",
1093
+ // "it"
1094
+ you: "t\xFA",
1095
+ // "you"
1096
+ result: "resultado",
1097
+ event: "evento",
1098
+ target: "objetivo",
1099
+ body: "cuerpo"
1100
+ },
1101
+ possessive: {
1102
+ marker: "de",
1103
+ // Spanish uses "de" for general possession
1104
+ markerPosition: "before-property",
1105
+ usePossessiveAdjectives: true,
1106
+ specialForms: {
1107
+ me: "mi",
1108
+ // "my" (possessive adjective)
1109
+ it: "su",
1110
+ // "its"
1111
+ you: "tu"
1112
+ // "your"
1113
+ },
1114
+ keywords: {
1115
+ mi: "me",
1116
+ tu: "you",
1117
+ su: "it"
1118
+ }
1119
+ },
1120
+ roleMarkers: {
1121
+ destination: { primary: "en", alternatives: ["sobre", "a"], position: "before" },
1122
+ source: { primary: "de", alternatives: ["desde"], position: "before" },
1123
+ patient: { primary: "", position: "before" },
1124
+ style: { primary: "con", position: "before" }
1125
+ },
1126
+ keywords: {
1127
+ // Class/Attribute operations
1128
+ toggle: { primary: "alternar", alternatives: ["cambiar", "conmutar"], normalized: "toggle" },
1129
+ add: { primary: "agregar", alternatives: ["a\xF1adir"], normalized: "add" },
1130
+ remove: {
1131
+ primary: "quitar",
1132
+ alternatives: ["eliminar", "remover", "sacar"],
1133
+ normalized: "remove"
1134
+ },
1135
+ // Content operations
1136
+ put: { primary: "poner", alternatives: ["colocar"], normalized: "put" },
1137
+ append: { primary: "a\xF1adir", normalized: "append" },
1138
+ prepend: { primary: "anteponer", normalized: "prepend" },
1139
+ take: { primary: "tomar", normalized: "take" },
1140
+ make: { primary: "hacer", alternatives: ["crear"], normalized: "make" },
1141
+ clone: { primary: "clonar", alternatives: ["copiar"], normalized: "clone" },
1142
+ swap: { primary: "intercambiar", alternatives: ["cambiar"], normalized: "swap" },
1143
+ morph: { primary: "transformar", alternatives: ["convertir"], normalized: "morph" },
1144
+ // Variable operations
1145
+ set: { primary: "establecer", alternatives: ["fijar", "definir"], normalized: "set" },
1146
+ get: { primary: "obtener", alternatives: ["conseguir"], normalized: "get" },
1147
+ increment: { primary: "incrementar", alternatives: ["aumentar"], normalized: "increment" },
1148
+ decrement: { primary: "decrementar", alternatives: ["disminuir"], normalized: "decrement" },
1149
+ log: { primary: "registrar", alternatives: ["imprimir"], normalized: "log" },
1150
+ // Visibility
1151
+ show: { primary: "mostrar", alternatives: ["ense\xF1ar"], normalized: "show" },
1152
+ hide: { primary: "ocultar", alternatives: ["esconder"], normalized: "hide" },
1153
+ transition: { primary: "transici\xF3n", alternatives: ["animar"], normalized: "transition" },
1154
+ // Events
1155
+ on: { primary: "en", alternatives: ["cuando", "al"], normalized: "on" },
1156
+ trigger: { primary: "disparar", alternatives: ["activar"], normalized: "trigger" },
1157
+ send: { primary: "enviar", normalized: "send" },
1158
+ // DOM focus
1159
+ focus: { primary: "enfocar", normalized: "focus" },
1160
+ blur: { primary: "desenfocar", normalized: "blur" },
1161
+ // Navigation
1162
+ go: { primary: "ir", alternatives: ["navegar"], normalized: "go" },
1163
+ // Async
1164
+ wait: { primary: "esperar", normalized: "wait" },
1165
+ fetch: { primary: "buscar", alternatives: ["obtener"], normalized: "fetch" },
1166
+ settle: { primary: "estabilizar", normalized: "settle" },
1167
+ // Control flow
1168
+ if: { primary: "si", normalized: "if" },
1169
+ when: { primary: "cuando", normalized: "when" },
1170
+ where: { primary: "donde", normalized: "where" },
1171
+ else: { primary: "sino", alternatives: ["de lo contrario"], normalized: "else" },
1172
+ repeat: { primary: "repetir", normalized: "repeat" },
1173
+ for: { primary: "para", normalized: "for" },
1174
+ while: { primary: "mientras", normalized: "while" },
1175
+ continue: { primary: "continuar", normalized: "continue" },
1176
+ halt: { primary: "detener", alternatives: ["parar"], normalized: "halt" },
1177
+ throw: { primary: "lanzar", alternatives: ["arrojar"], normalized: "throw" },
1178
+ call: { primary: "llamar", normalized: "call" },
1179
+ return: { primary: "retornar", alternatives: ["devolver"], normalized: "return" },
1180
+ then: { primary: "entonces", alternatives: ["luego", "despu\xE9s"], normalized: "then" },
1181
+ and: { primary: "y", alternatives: ["adem\xE1s", "tambi\xE9n"], normalized: "and" },
1182
+ end: { primary: "fin", alternatives: ["final", "terminar"], normalized: "end" },
1183
+ // Advanced
1184
+ js: { primary: "js", normalized: "js" },
1185
+ async: { primary: "as\xEDncrono", normalized: "async" },
1186
+ tell: { primary: "decir", normalized: "tell" },
1187
+ default: { primary: "predeterminar", alternatives: ["por defecto"], normalized: "default" },
1188
+ init: { primary: "iniciar", alternatives: ["inicializar"], normalized: "init" },
1189
+ behavior: { primary: "comportamiento", normalized: "behavior" },
1190
+ install: { primary: "instalar", normalized: "install" },
1191
+ measure: { primary: "medir", normalized: "measure" },
1192
+ // Modifiers
1193
+ into: { primary: "en", alternatives: ["dentro de"], normalized: "into" },
1194
+ before: { primary: "antes", normalized: "before" },
1195
+ after: { primary: "despu\xE9s", normalized: "after" },
1196
+ // Event modifiers (for repeat until event)
1197
+ until: { primary: "hasta", normalized: "until" },
1198
+ event: { primary: "evento", normalized: "event" },
1199
+ from: { primary: "de", alternatives: ["desde"], normalized: "from" }
1200
+ }
1201
+ };
1202
+
1203
+ // src/tokenizers/spanish.ts
1204
+ var { isLetter: isSpanishLetter, isIdentifierChar: isSpanishIdentifierChar } = createLatinCharClassifiers(/[a-zA-ZáéíóúüñÁÉÍÓÚÜÑ]/);
1205
+ var SPANISH_TIME_UNITS = [
1206
+ { pattern: "milisegundos", suffix: "ms", length: 12, caseInsensitive: true },
1207
+ { pattern: "milisegundo", suffix: "ms", length: 11, caseInsensitive: true },
1208
+ { pattern: "segundos", suffix: "s", length: 8, caseInsensitive: true },
1209
+ { pattern: "segundo", suffix: "s", length: 7, caseInsensitive: true },
1210
+ { pattern: "minutos", suffix: "m", length: 7, caseInsensitive: true },
1211
+ { pattern: "minuto", suffix: "m", length: 6, caseInsensitive: true },
1212
+ { pattern: "horas", suffix: "h", length: 5, caseInsensitive: true },
1213
+ { pattern: "hora", suffix: "h", length: 4, caseInsensitive: true }
1214
+ ];
1215
+ var PREPOSITIONS = /* @__PURE__ */ new Set([
1216
+ "en",
1217
+ // in, on
1218
+ "a",
1219
+ // to
1220
+ "de",
1221
+ // of, from
1222
+ "desde",
1223
+ // from
1224
+ "hasta",
1225
+ // until, to
1226
+ "con",
1227
+ // with
1228
+ "sin",
1229
+ // without
1230
+ "por",
1231
+ // by, for
1232
+ "para",
1233
+ // for
1234
+ "sobre",
1235
+ // on, about
1236
+ "entre",
1237
+ // between
1238
+ "antes",
1239
+ // before
1240
+ "despu\xE9s",
1241
+ // after
1242
+ "despues",
1243
+ // after (no accent)
1244
+ "dentro",
1245
+ // inside
1246
+ "fuera",
1247
+ // outside
1248
+ "al",
1249
+ // a + el (contraction)
1250
+ "del"
1251
+ // de + el (contraction)
1252
+ ]);
1253
+ var SPANISH_EXTRAS = [
1254
+ // Values/Literals
1255
+ { native: "verdadero", normalized: "true" },
1256
+ { native: "falso", normalized: "false" },
1257
+ { native: "nulo", normalized: "null" },
1258
+ { native: "indefinido", normalized: "undefined" },
1259
+ // Positional
1260
+ { native: "primero", normalized: "first" },
1261
+ { native: "primera", normalized: "first" },
1262
+ { native: "\xFAltimo", normalized: "last" },
1263
+ { native: "ultima", normalized: "last" },
1264
+ { native: "siguiente", normalized: "next" },
1265
+ { native: "anterior", normalized: "previous" },
1266
+ { native: "cercano", normalized: "closest" },
1267
+ { native: "padre", normalized: "parent" },
1268
+ // Events
1269
+ { native: "clic", normalized: "click" },
1270
+ { native: "click", normalized: "click" },
1271
+ { native: "hacer clic", normalized: "click" },
1272
+ { native: "entrada", normalized: "input" },
1273
+ { native: "cambio", normalized: "change" },
1274
+ { native: "env\xEDo", normalized: "submit" },
1275
+ { native: "envio", normalized: "submit" },
1276
+ { native: "tecla abajo", normalized: "keydown" },
1277
+ { native: "tecla arriba", normalized: "keyup" },
1278
+ { native: "rat\xF3n encima", normalized: "mouseover" },
1279
+ { native: "raton encima", normalized: "mouseover" },
1280
+ { native: "rat\xF3n fuera", normalized: "mouseout" },
1281
+ { native: "raton fuera", normalized: "mouseout" },
1282
+ { native: "enfoque", normalized: "focus" },
1283
+ { native: "desenfoque", normalized: "blur" },
1284
+ { native: "carga", normalized: "load" },
1285
+ { native: "desplazamiento", normalized: "scroll" },
1286
+ // References
1287
+ { native: "yo", normalized: "me" },
1288
+ { native: "m\xED", normalized: "me" },
1289
+ { native: "mi", normalized: "me" },
1290
+ { native: "ello", normalized: "it" },
1291
+ { native: "resultado", normalized: "result" },
1292
+ { native: "objetivo", normalized: "target" },
1293
+ { native: "destino", normalized: "target" },
1294
+ // Time units
1295
+ { native: "segundo", normalized: "s" },
1296
+ { native: "segundos", normalized: "s" },
1297
+ { native: "milisegundo", normalized: "ms" },
1298
+ { native: "milisegundos", normalized: "ms" },
1299
+ { native: "minuto", normalized: "m" },
1300
+ { native: "minutos", normalized: "m" },
1301
+ { native: "hora", normalized: "h" },
1302
+ { native: "horas", normalized: "h" },
1303
+ // Multi-word phrases
1304
+ { native: "de lo contrario", normalized: "else" },
1305
+ { native: "hasta que", normalized: "until" },
1306
+ { native: "antes de", normalized: "before" },
1307
+ { native: "despu\xE9s de", normalized: "after" },
1308
+ { native: "despues de", normalized: "after" },
1309
+ { native: "dentro de", normalized: "into" },
1310
+ { native: "fuera de", normalized: "out" },
1311
+ // Accent variations not in profile
1312
+ { native: "asincrono", normalized: "async" },
1313
+ { native: "despues", normalized: "after" },
1314
+ // Command overrides (ensure correct mapping when profile has multiple meanings)
1315
+ { native: "a\xF1adir", normalized: "add" },
1316
+ // Profile may have this as 'append'
1317
+ // Synonyms not in profile
1318
+ { native: "toggle", normalized: "toggle" },
1319
+ { native: "borrar", normalized: "remove" },
1320
+ { native: "pon", normalized: "put" },
1321
+ { native: "crear", normalized: "make" },
1322
+ // Logical/conditional
1323
+ { native: "y", normalized: "and" },
1324
+ { native: "o", normalized: "or" },
1325
+ { native: "no", normalized: "not" },
1326
+ { native: "es", normalized: "is" },
1327
+ { native: "existe", normalized: "exists" },
1328
+ { native: "vac\xEDo", normalized: "empty" },
1329
+ { native: "vacio", normalized: "empty" }
1330
+ ];
1331
+ var SpanishTokenizer = class extends BaseTokenizer {
1332
+ constructor() {
1333
+ super();
1334
+ this.language = "es";
1335
+ this.direction = "ltr";
1336
+ this.initializeKeywordsFromProfile(spanishProfile, SPANISH_EXTRAS);
1337
+ this.normalizer = new SpanishMorphologicalNormalizer();
1338
+ }
1339
+ tokenize(input) {
1340
+ const tokens = [];
1341
+ let pos = 0;
1342
+ while (pos < input.length) {
1343
+ if (isWhitespace(input[pos])) {
1344
+ pos++;
1345
+ continue;
1346
+ }
1347
+ if (isSelectorStart(input[pos])) {
1348
+ const modifierToken = this.tryEventModifier(input, pos);
1349
+ if (modifierToken) {
1350
+ tokens.push(modifierToken);
1351
+ pos = modifierToken.position.end;
1352
+ continue;
1353
+ }
1354
+ const selectorToken = this.trySelector(input, pos);
1355
+ if (selectorToken) {
1356
+ tokens.push(selectorToken);
1357
+ pos = selectorToken.position.end;
1358
+ continue;
1359
+ }
1360
+ }
1361
+ if (isQuote(input[pos])) {
1362
+ const stringToken = this.tryString(input, pos);
1363
+ if (stringToken) {
1364
+ tokens.push(stringToken);
1365
+ pos = stringToken.position.end;
1366
+ continue;
1367
+ }
1368
+ }
1369
+ if (isUrlStart(input, pos)) {
1370
+ const urlToken = this.tryUrl(input, pos);
1371
+ if (urlToken) {
1372
+ tokens.push(urlToken);
1373
+ pos = urlToken.position.end;
1374
+ continue;
1375
+ }
1376
+ }
1377
+ if (isDigit(input[pos]) || input[pos] === "-" && pos + 1 < input.length && isDigit(input[pos + 1])) {
1378
+ const numberToken = this.extractSpanishNumber(input, pos);
1379
+ if (numberToken) {
1380
+ tokens.push(numberToken);
1381
+ pos = numberToken.position.end;
1382
+ continue;
1383
+ }
1384
+ }
1385
+ const varToken = this.tryVariableRef(input, pos);
1386
+ if (varToken) {
1387
+ tokens.push(varToken);
1388
+ pos = varToken.position.end;
1389
+ continue;
1390
+ }
1391
+ const phraseToken = this.tryMultiWordPhrase(input, pos);
1392
+ if (phraseToken) {
1393
+ tokens.push(phraseToken);
1394
+ pos = phraseToken.position.end;
1395
+ continue;
1396
+ }
1397
+ if (isSpanishLetter(input[pos])) {
1398
+ const wordToken = this.extractSpanishWord(input, pos);
1399
+ if (wordToken) {
1400
+ tokens.push(wordToken);
1401
+ pos = wordToken.position.end;
1402
+ continue;
1403
+ }
1404
+ }
1405
+ const operatorToken = this.tryOperator(input, pos);
1406
+ if (operatorToken) {
1407
+ tokens.push(operatorToken);
1408
+ pos = operatorToken.position.end;
1409
+ continue;
1410
+ }
1411
+ pos++;
1412
+ }
1413
+ return new TokenStreamImpl(tokens, "es");
1414
+ }
1415
+ classifyToken(token) {
1416
+ const lower = token.toLowerCase();
1417
+ if (PREPOSITIONS.has(lower)) return "particle";
1418
+ if (this.isKeyword(lower)) return "keyword";
1419
+ if (token.startsWith("#") || token.startsWith(".") || token.startsWith("[")) return "selector";
1420
+ if (token.startsWith('"') || token.startsWith("'")) return "literal";
1421
+ if (/^\d/.test(token)) return "literal";
1422
+ if (["==", "!=", "<=", ">=", "<", ">", "&&", "||", "!"].includes(token)) return "operator";
1423
+ return "identifier";
1424
+ }
1425
+ /**
1426
+ * Try to match multi-word phrases that function as single units.
1427
+ * Multi-word phrases are included in profileKeywords and sorted longest-first,
1428
+ * so they'll be matched before their constituent words.
1429
+ */
1430
+ tryMultiWordPhrase(input, pos) {
1431
+ for (const entry of this.profileKeywords) {
1432
+ if (!entry.native.includes(" ")) continue;
1433
+ const phrase = entry.native;
1434
+ const candidate = input.slice(pos, pos + phrase.length).toLowerCase();
1435
+ if (candidate === phrase.toLowerCase()) {
1436
+ const nextPos = pos + phrase.length;
1437
+ if (nextPos >= input.length || isWhitespace(input[nextPos]) || !isSpanishLetter(input[nextPos])) {
1438
+ return createToken(
1439
+ input.slice(pos, pos + phrase.length),
1440
+ "keyword",
1441
+ createPosition(pos, nextPos),
1442
+ entry.normalized
1443
+ );
1444
+ }
1445
+ }
1446
+ }
1447
+ return null;
1448
+ }
1449
+ /**
1450
+ * Extract a Spanish word.
1451
+ *
1452
+ * Uses morphological normalization to handle:
1453
+ * - Reflexive verbs (mostrarse → mostrar)
1454
+ * - Verb conjugations (alternando → alternar)
1455
+ */
1456
+ extractSpanishWord(input, startPos) {
1457
+ let pos = startPos;
1458
+ let word = "";
1459
+ while (pos < input.length && isSpanishIdentifierChar(input[pos])) {
1460
+ word += input[pos++];
1461
+ }
1462
+ if (!word) return null;
1463
+ const lower = word.toLowerCase();
1464
+ if (PREPOSITIONS.has(lower)) {
1465
+ return createToken(word, "particle", createPosition(startPos, pos));
1466
+ }
1467
+ const keywordEntry = this.lookupKeyword(lower);
1468
+ if (keywordEntry) {
1469
+ return createToken(word, "keyword", createPosition(startPos, pos), keywordEntry.normalized);
1470
+ }
1471
+ const morphToken = this.tryMorphKeywordMatch(lower, startPos, pos);
1472
+ if (morphToken) return morphToken;
1473
+ return createToken(word, "identifier", createPosition(startPos, pos));
1474
+ }
1475
+ /**
1476
+ * Extract a number, including Spanish time unit suffixes.
1477
+ */
1478
+ extractSpanishNumber(input, startPos) {
1479
+ return this.tryNumberWithTimeUnits(input, startPos, SPANISH_TIME_UNITS, {
1480
+ allowSign: true,
1481
+ skipWhitespace: true
1482
+ });
1483
+ }
1484
+ };
1485
+ var spanishTokenizer = new SpanishTokenizer();
1486
+
1487
+ // src/languages/es.ts
1488
+ registerLanguage("es", spanishTokenizer, spanishProfile);
1489
+ export {
1490
+ spanishProfile,
1491
+ spanishTokenizer
1492
+ };
1493
+ //# sourceMappingURL=es.js.map