@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.
- package/LICENSE +21 -0
- package/README.md +686 -0
- package/dist/browser-ar.ar.global.js +2 -0
- package/dist/browser-core.core.global.js +2 -0
- package/dist/browser-de.de.global.js +2 -0
- package/dist/browser-east-asian.east-asian.global.js +2 -0
- package/dist/browser-en-tr.en-tr.global.js +2 -0
- package/dist/browser-en.en.global.js +2 -0
- package/dist/browser-es-en.es-en.global.js +2 -0
- package/dist/browser-es.es.global.js +2 -0
- package/dist/browser-fr.fr.global.js +2 -0
- package/dist/browser-id.id.global.js +2 -0
- package/dist/browser-ja.ja.global.js +2 -0
- package/dist/browser-ko.ko.global.js +2 -0
- package/dist/browser-lazy.lazy.global.js +2 -0
- package/dist/browser-priority.priority.global.js +2 -0
- package/dist/browser-pt.pt.global.js +2 -0
- package/dist/browser-qu.qu.global.js +2 -0
- package/dist/browser-sw.sw.global.js +2 -0
- package/dist/browser-tr.tr.global.js +2 -0
- package/dist/browser-western.western.global.js +2 -0
- package/dist/browser-zh.zh.global.js +2 -0
- package/dist/browser.global.js +3 -0
- package/dist/browser.global.js.map +1 -0
- package/dist/index.cjs +35051 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +3426 -0
- package/dist/index.d.ts +3426 -0
- package/dist/index.js +34890 -0
- package/dist/index.js.map +1 -0
- package/dist/languages/ar.d.ts +78 -0
- package/dist/languages/ar.js +1622 -0
- package/dist/languages/ar.js.map +1 -0
- package/dist/languages/de.d.ts +38 -0
- package/dist/languages/de.js +1168 -0
- package/dist/languages/de.js.map +1 -0
- package/dist/languages/en.d.ts +44 -0
- package/dist/languages/en.js +3491 -0
- package/dist/languages/en.js.map +1 -0
- package/dist/languages/es.d.ts +52 -0
- package/dist/languages/es.js +1493 -0
- package/dist/languages/es.js.map +1 -0
- package/dist/languages/fr.d.ts +37 -0
- package/dist/languages/fr.js +1159 -0
- package/dist/languages/fr.js.map +1 -0
- package/dist/languages/id.d.ts +35 -0
- package/dist/languages/id.js +1152 -0
- package/dist/languages/id.js.map +1 -0
- package/dist/languages/ja.d.ts +53 -0
- package/dist/languages/ja.js +1430 -0
- package/dist/languages/ja.js.map +1 -0
- package/dist/languages/ko.d.ts +51 -0
- package/dist/languages/ko.js +1729 -0
- package/dist/languages/ko.js.map +1 -0
- package/dist/languages/pt.d.ts +37 -0
- package/dist/languages/pt.js +1127 -0
- package/dist/languages/pt.js.map +1 -0
- package/dist/languages/qu.d.ts +36 -0
- package/dist/languages/qu.js +1143 -0
- package/dist/languages/qu.js.map +1 -0
- package/dist/languages/sw.d.ts +35 -0
- package/dist/languages/sw.js +1147 -0
- package/dist/languages/sw.js.map +1 -0
- package/dist/languages/tr.d.ts +45 -0
- package/dist/languages/tr.js +1529 -0
- package/dist/languages/tr.js.map +1 -0
- package/dist/languages/zh.d.ts +58 -0
- package/dist/languages/zh.js +1257 -0
- package/dist/languages/zh.js.map +1 -0
- package/dist/types-C4dcj53L.d.ts +600 -0
- package/package.json +202 -0
- package/src/__test-utils__/index.ts +7 -0
- package/src/__test-utils__/test-helpers.ts +8 -0
- package/src/__types__/test-helpers.ts +122 -0
- package/src/analysis/index.ts +479 -0
- package/src/ast-builder/command-mappers.ts +1133 -0
- package/src/ast-builder/expression-parser/index.ts +41 -0
- package/src/ast-builder/expression-parser/parser.ts +563 -0
- package/src/ast-builder/expression-parser/tokenizer.ts +394 -0
- package/src/ast-builder/expression-parser/types.ts +208 -0
- package/src/ast-builder/index.ts +536 -0
- package/src/ast-builder/value-converters.ts +172 -0
- package/src/bridge.ts +275 -0
- package/src/browser-ar.ts +162 -0
- package/src/browser-core.ts +231 -0
- package/src/browser-de.ts +162 -0
- package/src/browser-east-asian.ts +173 -0
- package/src/browser-en-tr.ts +165 -0
- package/src/browser-en.ts +157 -0
- package/src/browser-es-en.ts +200 -0
- package/src/browser-es.ts +170 -0
- package/src/browser-fr.ts +162 -0
- package/src/browser-id.ts +162 -0
- package/src/browser-ja.ts +162 -0
- package/src/browser-ko.ts +162 -0
- package/src/browser-lazy.ts +189 -0
- package/src/browser-priority.ts +214 -0
- package/src/browser-pt.ts +162 -0
- package/src/browser-qu.ts +162 -0
- package/src/browser-sw.ts +162 -0
- package/src/browser-tr.ts +162 -0
- package/src/browser-western.ts +181 -0
- package/src/browser-zh.ts +162 -0
- package/src/browser.ts +268 -0
- package/src/cache/index.ts +14 -0
- package/src/cache/semantic-cache.ts +344 -0
- package/src/core-bridge.ts +372 -0
- package/src/explicit/converter.ts +258 -0
- package/src/explicit/index.ts +18 -0
- package/src/explicit/parser.ts +236 -0
- package/src/explicit/renderer.ts +424 -0
- package/src/generators/command-schemas.ts +1636 -0
- package/src/generators/event-handler-generator.ts +109 -0
- package/src/generators/index.ts +117 -0
- package/src/generators/language-profiles.ts +139 -0
- package/src/generators/pattern-generator.ts +537 -0
- package/src/generators/profiles/arabic.ts +131 -0
- package/src/generators/profiles/bengali.ts +132 -0
- package/src/generators/profiles/chinese.ts +124 -0
- package/src/generators/profiles/english.ts +113 -0
- package/src/generators/profiles/french.ts +125 -0
- package/src/generators/profiles/german.ts +126 -0
- package/src/generators/profiles/hindi.ts +146 -0
- package/src/generators/profiles/index.ts +46 -0
- package/src/generators/profiles/indonesian.ts +125 -0
- package/src/generators/profiles/italian.ts +139 -0
- package/src/generators/profiles/japanese.ts +149 -0
- package/src/generators/profiles/korean.ts +127 -0
- package/src/generators/profiles/marker-templates.ts +288 -0
- package/src/generators/profiles/ms.ts +130 -0
- package/src/generators/profiles/polish.ts +249 -0
- package/src/generators/profiles/portuguese.ts +115 -0
- package/src/generators/profiles/quechua.ts +113 -0
- package/src/generators/profiles/russian.ts +260 -0
- package/src/generators/profiles/spanish.ts +130 -0
- package/src/generators/profiles/swahili.ts +129 -0
- package/src/generators/profiles/thai.ts +132 -0
- package/src/generators/profiles/tl.ts +128 -0
- package/src/generators/profiles/turkish.ts +124 -0
- package/src/generators/profiles/types.ts +165 -0
- package/src/generators/profiles/ukrainian.ts +270 -0
- package/src/generators/profiles/vietnamese.ts +133 -0
- package/src/generators/schema-error-codes.ts +160 -0
- package/src/generators/schema-validator.ts +391 -0
- package/src/index.ts +429 -0
- package/src/language-building-schema.ts +3170 -0
- package/src/language-loader.ts +394 -0
- package/src/languages/_all.ts +65 -0
- package/src/languages/ar.ts +15 -0
- package/src/languages/bn.ts +16 -0
- package/src/languages/de.ts +15 -0
- package/src/languages/en.ts +29 -0
- package/src/languages/es.ts +15 -0
- package/src/languages/fr.ts +15 -0
- package/src/languages/hi.ts +26 -0
- package/src/languages/id.ts +15 -0
- package/src/languages/index.ts +18 -0
- package/src/languages/it.ts +15 -0
- package/src/languages/ja.ts +15 -0
- package/src/languages/ko.ts +15 -0
- package/src/languages/ms.ts +16 -0
- package/src/languages/pl.ts +18 -0
- package/src/languages/pt.ts +15 -0
- package/src/languages/qu.ts +15 -0
- package/src/languages/ru.ts +26 -0
- package/src/languages/sw.ts +15 -0
- package/src/languages/th.ts +16 -0
- package/src/languages/tl.ts +16 -0
- package/src/languages/tr.ts +15 -0
- package/src/languages/uk.ts +26 -0
- package/src/languages/vi.ts +16 -0
- package/src/languages/zh.ts +15 -0
- package/src/parser/index.ts +15 -0
- package/src/parser/pattern-matcher.ts +1181 -0
- package/src/parser/semantic-parser.ts +573 -0
- package/src/parser/utils/index.ts +35 -0
- package/src/parser/utils/marker-resolution.ts +111 -0
- package/src/parser/utils/possessive-keywords.ts +43 -0
- package/src/parser/utils/role-positioning.ts +70 -0
- package/src/parser/utils/type-validation.ts +134 -0
- package/src/patterns/add/ar.ts +71 -0
- package/src/patterns/add/bn.ts +70 -0
- package/src/patterns/add/hi.ts +69 -0
- package/src/patterns/add/index.ts +87 -0
- package/src/patterns/add/it.ts +61 -0
- package/src/patterns/add/ja.ts +93 -0
- package/src/patterns/add/ko.ts +74 -0
- package/src/patterns/add/ms.ts +30 -0
- package/src/patterns/add/pl.ts +62 -0
- package/src/patterns/add/ru.ts +62 -0
- package/src/patterns/add/th.ts +49 -0
- package/src/patterns/add/tl.ts +30 -0
- package/src/patterns/add/tr.ts +71 -0
- package/src/patterns/add/uk.ts +62 -0
- package/src/patterns/add/vi.ts +61 -0
- package/src/patterns/add/zh.ts +71 -0
- package/src/patterns/builders.ts +207 -0
- package/src/patterns/decrement/bn.ts +70 -0
- package/src/patterns/decrement/de.ts +42 -0
- package/src/patterns/decrement/hi.ts +68 -0
- package/src/patterns/decrement/index.ts +79 -0
- package/src/patterns/decrement/it.ts +69 -0
- package/src/patterns/decrement/ms.ts +30 -0
- package/src/patterns/decrement/pl.ts +58 -0
- package/src/patterns/decrement/ru.ts +58 -0
- package/src/patterns/decrement/th.ts +49 -0
- package/src/patterns/decrement/tl.ts +30 -0
- package/src/patterns/decrement/tr.ts +48 -0
- package/src/patterns/decrement/uk.ts +58 -0
- package/src/patterns/decrement/vi.ts +61 -0
- package/src/patterns/decrement/zh.ts +32 -0
- package/src/patterns/en.ts +302 -0
- package/src/patterns/event-handler/ar.ts +151 -0
- package/src/patterns/event-handler/bn.ts +72 -0
- package/src/patterns/event-handler/de.ts +117 -0
- package/src/patterns/event-handler/en.ts +117 -0
- package/src/patterns/event-handler/es.ts +136 -0
- package/src/patterns/event-handler/fr.ts +117 -0
- package/src/patterns/event-handler/hi.ts +64 -0
- package/src/patterns/event-handler/id.ts +117 -0
- package/src/patterns/event-handler/index.ts +119 -0
- package/src/patterns/event-handler/it.ts +54 -0
- package/src/patterns/event-handler/ja.ts +118 -0
- package/src/patterns/event-handler/ko.ts +133 -0
- package/src/patterns/event-handler/ms.ts +30 -0
- package/src/patterns/event-handler/pl.ts +62 -0
- package/src/patterns/event-handler/pt.ts +117 -0
- package/src/patterns/event-handler/qu.ts +66 -0
- package/src/patterns/event-handler/ru.ts +62 -0
- package/src/patterns/event-handler/shared.ts +270 -0
- package/src/patterns/event-handler/sw.ts +117 -0
- package/src/patterns/event-handler/th.ts +53 -0
- package/src/patterns/event-handler/tl.ts +30 -0
- package/src/patterns/event-handler/tr.ts +170 -0
- package/src/patterns/event-handler/uk.ts +62 -0
- package/src/patterns/event-handler/vi.ts +61 -0
- package/src/patterns/event-handler/zh.ts +150 -0
- package/src/patterns/get/ar.ts +49 -0
- package/src/patterns/get/bn.ts +47 -0
- package/src/patterns/get/de.ts +32 -0
- package/src/patterns/get/hi.ts +52 -0
- package/src/patterns/get/index.ts +83 -0
- package/src/patterns/get/it.ts +56 -0
- package/src/patterns/get/ja.ts +53 -0
- package/src/patterns/get/ko.ts +53 -0
- package/src/patterns/get/ms.ts +30 -0
- package/src/patterns/get/pl.ts +57 -0
- package/src/patterns/get/ru.ts +57 -0
- package/src/patterns/get/th.ts +29 -0
- package/src/patterns/get/tl.ts +30 -0
- package/src/patterns/get/uk.ts +57 -0
- package/src/patterns/get/vi.ts +48 -0
- package/src/patterns/grammar-transformed/index.ts +39 -0
- package/src/patterns/grammar-transformed/ja.ts +1713 -0
- package/src/patterns/grammar-transformed/ko.ts +1311 -0
- package/src/patterns/grammar-transformed/tr.ts +1067 -0
- package/src/patterns/hide/ar.ts +67 -0
- package/src/patterns/hide/bn.ts +47 -0
- package/src/patterns/hide/de.ts +36 -0
- package/src/patterns/hide/hi.ts +61 -0
- package/src/patterns/hide/index.ts +91 -0
- package/src/patterns/hide/it.ts +56 -0
- package/src/patterns/hide/ja.ts +69 -0
- package/src/patterns/hide/ko.ts +69 -0
- package/src/patterns/hide/ms.ts +30 -0
- package/src/patterns/hide/pl.ts +57 -0
- package/src/patterns/hide/ru.ts +57 -0
- package/src/patterns/hide/th.ts +29 -0
- package/src/patterns/hide/tl.ts +30 -0
- package/src/patterns/hide/tr.ts +65 -0
- package/src/patterns/hide/uk.ts +57 -0
- package/src/patterns/hide/vi.ts +56 -0
- package/src/patterns/hide/zh.ts +68 -0
- package/src/patterns/increment/bn.ts +70 -0
- package/src/patterns/increment/de.ts +36 -0
- package/src/patterns/increment/hi.ts +68 -0
- package/src/patterns/increment/index.ts +79 -0
- package/src/patterns/increment/it.ts +69 -0
- package/src/patterns/increment/ms.ts +30 -0
- package/src/patterns/increment/pl.ts +58 -0
- package/src/patterns/increment/ru.ts +58 -0
- package/src/patterns/increment/th.ts +49 -0
- package/src/patterns/increment/tl.ts +30 -0
- package/src/patterns/increment/tr.ts +52 -0
- package/src/patterns/increment/uk.ts +58 -0
- package/src/patterns/increment/vi.ts +61 -0
- package/src/patterns/increment/zh.ts +32 -0
- package/src/patterns/index.ts +84 -0
- package/src/patterns/languages/en/control-flow.ts +93 -0
- package/src/patterns/languages/en/fetch.ts +62 -0
- package/src/patterns/languages/en/index.ts +42 -0
- package/src/patterns/languages/en/repeat.ts +67 -0
- package/src/patterns/languages/en/set.ts +48 -0
- package/src/patterns/languages/en/swap.ts +38 -0
- package/src/patterns/languages/en/temporal.ts +57 -0
- package/src/patterns/put/ar.ts +74 -0
- package/src/patterns/put/bn.ts +53 -0
- package/src/patterns/put/en.ts +74 -0
- package/src/patterns/put/es.ts +74 -0
- package/src/patterns/put/hi.ts +69 -0
- package/src/patterns/put/id.ts +96 -0
- package/src/patterns/put/index.ts +99 -0
- package/src/patterns/put/it.ts +56 -0
- package/src/patterns/put/ja.ts +75 -0
- package/src/patterns/put/ko.ts +67 -0
- package/src/patterns/put/ms.ts +30 -0
- package/src/patterns/put/pl.ts +81 -0
- package/src/patterns/put/ru.ts +85 -0
- package/src/patterns/put/th.ts +32 -0
- package/src/patterns/put/tl.ts +30 -0
- package/src/patterns/put/tr.ts +67 -0
- package/src/patterns/put/uk.ts +85 -0
- package/src/patterns/put/vi.ts +72 -0
- package/src/patterns/put/zh.ts +62 -0
- package/src/patterns/registry.ts +163 -0
- package/src/patterns/remove/ar.ts +71 -0
- package/src/patterns/remove/bn.ts +68 -0
- package/src/patterns/remove/hi.ts +69 -0
- package/src/patterns/remove/index.ts +87 -0
- package/src/patterns/remove/it.ts +69 -0
- package/src/patterns/remove/ja.ts +74 -0
- package/src/patterns/remove/ko.ts +78 -0
- package/src/patterns/remove/ms.ts +30 -0
- package/src/patterns/remove/pl.ts +62 -0
- package/src/patterns/remove/ru.ts +62 -0
- package/src/patterns/remove/th.ts +49 -0
- package/src/patterns/remove/tl.ts +30 -0
- package/src/patterns/remove/tr.ts +78 -0
- package/src/patterns/remove/uk.ts +62 -0
- package/src/patterns/remove/vi.ts +61 -0
- package/src/patterns/remove/zh.ts +72 -0
- package/src/patterns/set/ar.ts +84 -0
- package/src/patterns/set/bn.ts +53 -0
- package/src/patterns/set/de.ts +84 -0
- package/src/patterns/set/es.ts +92 -0
- package/src/patterns/set/fr.ts +88 -0
- package/src/patterns/set/hi.ts +56 -0
- package/src/patterns/set/id.ts +84 -0
- package/src/patterns/set/index.ts +107 -0
- package/src/patterns/set/it.ts +56 -0
- package/src/patterns/set/ja.ts +86 -0
- package/src/patterns/set/ko.ts +85 -0
- package/src/patterns/set/ms.ts +30 -0
- package/src/patterns/set/pl.ts +57 -0
- package/src/patterns/set/pt.ts +84 -0
- package/src/patterns/set/ru.ts +57 -0
- package/src/patterns/set/th.ts +31 -0
- package/src/patterns/set/tl.ts +30 -0
- package/src/patterns/set/tr.ts +107 -0
- package/src/patterns/set/uk.ts +57 -0
- package/src/patterns/set/vi.ts +53 -0
- package/src/patterns/set/zh.ts +84 -0
- package/src/patterns/show/ar.ts +67 -0
- package/src/patterns/show/bn.ts +47 -0
- package/src/patterns/show/de.ts +32 -0
- package/src/patterns/show/fr.ts +32 -0
- package/src/patterns/show/hi.ts +61 -0
- package/src/patterns/show/index.ts +95 -0
- package/src/patterns/show/it.ts +56 -0
- package/src/patterns/show/ja.ts +69 -0
- package/src/patterns/show/ko.ts +73 -0
- package/src/patterns/show/ms.ts +30 -0
- package/src/patterns/show/pl.ts +57 -0
- package/src/patterns/show/ru.ts +57 -0
- package/src/patterns/show/th.ts +29 -0
- package/src/patterns/show/tl.ts +30 -0
- package/src/patterns/show/tr.ts +65 -0
- package/src/patterns/show/uk.ts +57 -0
- package/src/patterns/show/vi.ts +56 -0
- package/src/patterns/show/zh.ts +68 -0
- package/src/patterns/take/ar.ts +51 -0
- package/src/patterns/take/index.ts +31 -0
- package/src/patterns/toggle/ar.ts +61 -0
- package/src/patterns/toggle/bn.ts +70 -0
- package/src/patterns/toggle/en.ts +61 -0
- package/src/patterns/toggle/es.ts +61 -0
- package/src/patterns/toggle/hi.ts +80 -0
- package/src/patterns/toggle/index.ts +95 -0
- package/src/patterns/toggle/it.ts +69 -0
- package/src/patterns/toggle/ja.ts +156 -0
- package/src/patterns/toggle/ko.ts +113 -0
- package/src/patterns/toggle/ms.ts +30 -0
- package/src/patterns/toggle/pl.ts +62 -0
- package/src/patterns/toggle/ru.ts +62 -0
- package/src/patterns/toggle/th.ts +50 -0
- package/src/patterns/toggle/tl.ts +30 -0
- package/src/patterns/toggle/tr.ts +88 -0
- package/src/patterns/toggle/uk.ts +62 -0
- package/src/patterns/toggle/vi.ts +61 -0
- package/src/patterns/toggle/zh.ts +99 -0
- package/src/public-api.ts +286 -0
- package/src/registry.ts +441 -0
- package/src/tokenizers/arabic.ts +723 -0
- package/src/tokenizers/base.ts +1300 -0
- package/src/tokenizers/bengali.ts +289 -0
- package/src/tokenizers/chinese.ts +481 -0
- package/src/tokenizers/english.ts +416 -0
- package/src/tokenizers/french.ts +326 -0
- package/src/tokenizers/german.ts +324 -0
- package/src/tokenizers/hindi.ts +319 -0
- package/src/tokenizers/index.ts +127 -0
- package/src/tokenizers/indonesian.ts +306 -0
- package/src/tokenizers/italian.ts +458 -0
- package/src/tokenizers/japanese.ts +447 -0
- package/src/tokenizers/korean.ts +642 -0
- package/src/tokenizers/morphology/arabic-normalizer.ts +242 -0
- package/src/tokenizers/morphology/french-normalizer.ts +268 -0
- package/src/tokenizers/morphology/german-normalizer.ts +256 -0
- package/src/tokenizers/morphology/index.ts +46 -0
- package/src/tokenizers/morphology/italian-normalizer.ts +329 -0
- package/src/tokenizers/morphology/japanese-normalizer.ts +288 -0
- package/src/tokenizers/morphology/korean-normalizer.ts +428 -0
- package/src/tokenizers/morphology/polish-normalizer.ts +264 -0
- package/src/tokenizers/morphology/portuguese-normalizer.ts +310 -0
- package/src/tokenizers/morphology/spanish-normalizer.ts +327 -0
- package/src/tokenizers/morphology/turkish-normalizer.ts +412 -0
- package/src/tokenizers/morphology/types.ts +211 -0
- package/src/tokenizers/ms.ts +198 -0
- package/src/tokenizers/polish.ts +354 -0
- package/src/tokenizers/portuguese.ts +304 -0
- package/src/tokenizers/quechua.ts +339 -0
- package/src/tokenizers/russian.ts +375 -0
- package/src/tokenizers/spanish.ts +403 -0
- package/src/tokenizers/swahili.ts +303 -0
- package/src/tokenizers/thai.ts +236 -0
- package/src/tokenizers/tl.ts +198 -0
- package/src/tokenizers/turkish.ts +411 -0
- package/src/tokenizers/ukrainian.ts +369 -0
- package/src/tokenizers/vietnamese.ts +410 -0
- package/src/types/grammar-types.ts +617 -0
- package/src/types/unified-profile.ts +267 -0
- package/src/types.ts +709 -0
- package/src/utils/confidence-calculator.ts +147 -0
- package/src/validators/command-validator.ts +380 -0
- package/src/validators/index.ts +15 -0
|
@@ -0,0 +1,1168 @@
|
|
|
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/german.ts
|
|
781
|
+
var germanProfile = {
|
|
782
|
+
code: "de",
|
|
783
|
+
name: "German",
|
|
784
|
+
nativeName: "Deutsch",
|
|
785
|
+
direction: "ltr",
|
|
786
|
+
wordOrder: "SVO",
|
|
787
|
+
markingStrategy: "preposition",
|
|
788
|
+
usesSpaces: true,
|
|
789
|
+
// Infinitive is standard for German software UI (Speichern, Öffnen, Schließen)
|
|
790
|
+
// Also used in written instructions ("Bitte nicht stören")
|
|
791
|
+
defaultVerbForm: "infinitive",
|
|
792
|
+
verb: {
|
|
793
|
+
position: "start",
|
|
794
|
+
subjectDrop: false
|
|
795
|
+
},
|
|
796
|
+
references: {
|
|
797
|
+
me: "ich",
|
|
798
|
+
// "I"
|
|
799
|
+
it: "es",
|
|
800
|
+
// "it"
|
|
801
|
+
you: "du",
|
|
802
|
+
// "you"
|
|
803
|
+
result: "Ergebnis",
|
|
804
|
+
event: "Ereignis",
|
|
805
|
+
target: "Ziel",
|
|
806
|
+
body: "K\xF6rper"
|
|
807
|
+
},
|
|
808
|
+
possessive: {
|
|
809
|
+
marker: "",
|
|
810
|
+
// German uses possessive pronouns directly
|
|
811
|
+
markerPosition: "before-property",
|
|
812
|
+
usePossessiveAdjectives: true,
|
|
813
|
+
specialForms: {
|
|
814
|
+
me: "mein",
|
|
815
|
+
// "my"
|
|
816
|
+
it: "sein",
|
|
817
|
+
// "its"
|
|
818
|
+
you: "dein"
|
|
819
|
+
// "your"
|
|
820
|
+
},
|
|
821
|
+
keywords: {
|
|
822
|
+
mein: "me",
|
|
823
|
+
meine: "me",
|
|
824
|
+
meinen: "me",
|
|
825
|
+
dein: "you",
|
|
826
|
+
deine: "you",
|
|
827
|
+
deinen: "you",
|
|
828
|
+
sein: "it",
|
|
829
|
+
seine: "it",
|
|
830
|
+
seinen: "it"
|
|
831
|
+
}
|
|
832
|
+
},
|
|
833
|
+
roleMarkers: {
|
|
834
|
+
destination: { primary: "auf", alternatives: ["zu", "in"], position: "before" },
|
|
835
|
+
source: { primary: "von", alternatives: ["aus"], position: "before" },
|
|
836
|
+
patient: { primary: "", position: "before" },
|
|
837
|
+
style: { primary: "mit", position: "before" }
|
|
838
|
+
},
|
|
839
|
+
keywords: {
|
|
840
|
+
toggle: { primary: "umschalten", alternatives: ["wechseln"], normalized: "toggle" },
|
|
841
|
+
add: { primary: "hinzuf\xFCgen", normalized: "add" },
|
|
842
|
+
remove: { primary: "entfernen", alternatives: ["l\xF6schen"], normalized: "remove" },
|
|
843
|
+
put: { primary: "setzen", alternatives: ["stellen", "platzieren"], normalized: "put" },
|
|
844
|
+
append: { primary: "anh\xE4ngen", normalized: "append" },
|
|
845
|
+
prepend: { primary: "voranstellen", normalized: "prepend" },
|
|
846
|
+
take: { primary: "nehmen", normalized: "take" },
|
|
847
|
+
make: { primary: "machen", alternatives: ["erstellen", "erzeugen"], normalized: "make" },
|
|
848
|
+
clone: { primary: "klonen", alternatives: ["kopieren"], normalized: "clone" },
|
|
849
|
+
swap: { primary: "austauschen", alternatives: ["tauschen", "wechseln"], normalized: "swap" },
|
|
850
|
+
morph: { primary: "verwandeln", alternatives: ["transformieren"], normalized: "morph" },
|
|
851
|
+
set: { primary: "festlegen", alternatives: ["definieren"], normalized: "set" },
|
|
852
|
+
get: { primary: "holen", alternatives: ["bekommen"], normalized: "get" },
|
|
853
|
+
increment: { primary: "erh\xF6hen", normalized: "increment" },
|
|
854
|
+
decrement: { primary: "verringern", alternatives: ["vermindern"], normalized: "decrement" },
|
|
855
|
+
log: { primary: "protokollieren", alternatives: ["ausgeben"], normalized: "log" },
|
|
856
|
+
show: { primary: "zeigen", alternatives: ["anzeigen"], normalized: "show" },
|
|
857
|
+
hide: { primary: "verbergen", alternatives: ["verstecken"], normalized: "hide" },
|
|
858
|
+
transition: { primary: "\xFCbergang", alternatives: ["animieren"], normalized: "transition" },
|
|
859
|
+
on: { primary: "bei", alternatives: ["wenn", "auf"], normalized: "on" },
|
|
860
|
+
trigger: { primary: "ausl\xF6sen", normalized: "trigger" },
|
|
861
|
+
send: { primary: "senden", alternatives: ["schicken"], normalized: "send" },
|
|
862
|
+
focus: { primary: "fokussieren", normalized: "focus" },
|
|
863
|
+
blur: { primary: "defokussieren", alternatives: ["entfokussieren"], normalized: "blur" },
|
|
864
|
+
go: { primary: "gehen", alternatives: ["navigieren"], normalized: "go" },
|
|
865
|
+
wait: { primary: "warten", normalized: "wait" },
|
|
866
|
+
fetch: { primary: "abrufen", alternatives: ["laden"], normalized: "fetch" },
|
|
867
|
+
settle: { primary: "stabilisieren", normalized: "settle" },
|
|
868
|
+
if: { primary: "wenn", alternatives: ["falls"], normalized: "if" },
|
|
869
|
+
when: { primary: "wenn", normalized: "when" },
|
|
870
|
+
where: { primary: "wo", normalized: "where" },
|
|
871
|
+
else: { primary: "sonst", alternatives: ["ansonsten"], normalized: "else" },
|
|
872
|
+
repeat: { primary: "wiederholen", normalized: "repeat" },
|
|
873
|
+
for: { primary: "f\xFCr", normalized: "for" },
|
|
874
|
+
while: { primary: "solange", alternatives: ["w\xE4hrend"], normalized: "while" },
|
|
875
|
+
continue: { primary: "fortfahren", alternatives: ["weiter"], normalized: "continue" },
|
|
876
|
+
halt: { primary: "anhalten", alternatives: ["stoppen"], normalized: "halt" },
|
|
877
|
+
throw: { primary: "werfen", normalized: "throw" },
|
|
878
|
+
call: { primary: "aufrufen", normalized: "call" },
|
|
879
|
+
return: { primary: "zur\xFCckgeben", normalized: "return" },
|
|
880
|
+
then: { primary: "dann", alternatives: ["danach", "anschlie\xDFend"], normalized: "then" },
|
|
881
|
+
and: { primary: "und", alternatives: ["sowie", "auch"], normalized: "and" },
|
|
882
|
+
end: { primary: "ende", alternatives: ["beenden", "fertig"], normalized: "end" },
|
|
883
|
+
js: { primary: "js", alternatives: ["javascript"], normalized: "js" },
|
|
884
|
+
async: { primary: "asynchron", normalized: "async" },
|
|
885
|
+
tell: { primary: "sagen", normalized: "tell" },
|
|
886
|
+
default: { primary: "standard", normalized: "default" },
|
|
887
|
+
init: { primary: "initialisieren", normalized: "init" },
|
|
888
|
+
behavior: { primary: "verhalten", normalized: "behavior" },
|
|
889
|
+
install: { primary: "installieren", normalized: "install" },
|
|
890
|
+
measure: { primary: "messen", normalized: "measure" },
|
|
891
|
+
into: { primary: "hinein", normalized: "into" },
|
|
892
|
+
before: { primary: "vor", normalized: "before" },
|
|
893
|
+
after: { primary: "nach", normalized: "after" },
|
|
894
|
+
// Event modifiers (for repeat until event)
|
|
895
|
+
until: { primary: "bis", normalized: "until" },
|
|
896
|
+
event: { primary: "Ereignis", alternatives: ["Event"], normalized: "event" },
|
|
897
|
+
from: { primary: "von", alternatives: ["aus"], normalized: "from" }
|
|
898
|
+
},
|
|
899
|
+
eventHandler: {
|
|
900
|
+
keyword: { primary: "bei", alternatives: ["auf"] },
|
|
901
|
+
sourceMarker: { primary: "von", alternatives: ["aus"], position: "before" },
|
|
902
|
+
conditionalKeyword: { primary: "wenn", alternatives: ["falls"] }
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
|
|
906
|
+
// src/tokenizers/german.ts
|
|
907
|
+
var { isLetter: isGermanLetter, isIdentifierChar: isGermanIdentifierChar } = createLatinCharClassifiers(/[a-zA-ZäöüÄÖÜß]/);
|
|
908
|
+
var PREPOSITIONS = /* @__PURE__ */ new Set([
|
|
909
|
+
"an",
|
|
910
|
+
// at, on
|
|
911
|
+
"auf",
|
|
912
|
+
// on
|
|
913
|
+
"aus",
|
|
914
|
+
// from, out of
|
|
915
|
+
"bei",
|
|
916
|
+
// at, near
|
|
917
|
+
"durch",
|
|
918
|
+
// through
|
|
919
|
+
"f\xFCr",
|
|
920
|
+
// for
|
|
921
|
+
"fur",
|
|
922
|
+
// for (no umlaut)
|
|
923
|
+
"gegen",
|
|
924
|
+
// against
|
|
925
|
+
"in",
|
|
926
|
+
// in
|
|
927
|
+
"mit",
|
|
928
|
+
// with
|
|
929
|
+
"nach",
|
|
930
|
+
// after, to
|
|
931
|
+
"ohne",
|
|
932
|
+
// without
|
|
933
|
+
"seit",
|
|
934
|
+
// since
|
|
935
|
+
"\xFCber",
|
|
936
|
+
// over, about
|
|
937
|
+
"uber",
|
|
938
|
+
// over (no umlaut)
|
|
939
|
+
"um",
|
|
940
|
+
// around, at
|
|
941
|
+
"unter",
|
|
942
|
+
// under
|
|
943
|
+
"von",
|
|
944
|
+
// from, of
|
|
945
|
+
"vor",
|
|
946
|
+
// before, in front of
|
|
947
|
+
"zu",
|
|
948
|
+
// to
|
|
949
|
+
"zwischen",
|
|
950
|
+
// between
|
|
951
|
+
"bis",
|
|
952
|
+
// until
|
|
953
|
+
"gegen\xFCber",
|
|
954
|
+
// opposite
|
|
955
|
+
"gegenuber",
|
|
956
|
+
// opposite (no umlaut)
|
|
957
|
+
"w\xE4hrend",
|
|
958
|
+
// during
|
|
959
|
+
"wahrend",
|
|
960
|
+
// during (no umlaut)
|
|
961
|
+
"wegen",
|
|
962
|
+
// because of
|
|
963
|
+
"trotz",
|
|
964
|
+
// despite
|
|
965
|
+
"statt",
|
|
966
|
+
// instead of
|
|
967
|
+
"innerhalb",
|
|
968
|
+
// inside
|
|
969
|
+
"au\xDFerhalb",
|
|
970
|
+
// outside
|
|
971
|
+
"ausserhalb"
|
|
972
|
+
// outside (no umlaut)
|
|
973
|
+
]);
|
|
974
|
+
var GERMAN_EXTRAS = [
|
|
975
|
+
// Values/Literals
|
|
976
|
+
{ native: "wahr", normalized: "true" },
|
|
977
|
+
{ native: "falsch", normalized: "false" },
|
|
978
|
+
{ native: "null", normalized: "null" },
|
|
979
|
+
{ native: "undefiniert", normalized: "undefined" },
|
|
980
|
+
// Positional
|
|
981
|
+
{ native: "erste", normalized: "first" },
|
|
982
|
+
{ native: "erster", normalized: "first" },
|
|
983
|
+
{ native: "erstes", normalized: "first" },
|
|
984
|
+
{ native: "letzte", normalized: "last" },
|
|
985
|
+
{ native: "letzter", normalized: "last" },
|
|
986
|
+
{ native: "letztes", normalized: "last" },
|
|
987
|
+
{ native: "n\xE4chste", normalized: "next" },
|
|
988
|
+
{ native: "nachste", normalized: "next" },
|
|
989
|
+
{ native: "vorherige", normalized: "previous" },
|
|
990
|
+
{ native: "n\xE4chste", normalized: "closest" },
|
|
991
|
+
{ native: "eltern", normalized: "parent" },
|
|
992
|
+
// Events
|
|
993
|
+
{ native: "klick", normalized: "click" },
|
|
994
|
+
{ native: "click", normalized: "click" },
|
|
995
|
+
{ native: "eingabe", normalized: "input" },
|
|
996
|
+
{ native: "\xE4nderung", normalized: "change" },
|
|
997
|
+
{ native: "anderung", normalized: "change" },
|
|
998
|
+
{ native: "absenden", normalized: "submit" },
|
|
999
|
+
{ native: "taste unten", normalized: "keydown" },
|
|
1000
|
+
{ native: "taste oben", normalized: "keyup" },
|
|
1001
|
+
{ native: "maus dr\xFCber", normalized: "mouseover" },
|
|
1002
|
+
{ native: "maus druber", normalized: "mouseover" },
|
|
1003
|
+
{ native: "maus weg", normalized: "mouseout" },
|
|
1004
|
+
{ native: "fokus", normalized: "focus" },
|
|
1005
|
+
{ native: "unsch\xE4rfe", normalized: "blur" },
|
|
1006
|
+
{ native: "unscharfe", normalized: "blur" },
|
|
1007
|
+
{ native: "scrollen", normalized: "scroll" },
|
|
1008
|
+
// Additional references
|
|
1009
|
+
{ native: "meine", normalized: "my" },
|
|
1010
|
+
{ native: "meinen", normalized: "my" },
|
|
1011
|
+
{ native: "ergebnis", normalized: "result" },
|
|
1012
|
+
{ native: "ziel", normalized: "target" },
|
|
1013
|
+
// Time units
|
|
1014
|
+
{ native: "sekunde", normalized: "s" },
|
|
1015
|
+
{ native: "sekunden", normalized: "s" },
|
|
1016
|
+
{ native: "millisekunde", normalized: "ms" },
|
|
1017
|
+
{ native: "millisekunden", normalized: "ms" },
|
|
1018
|
+
{ native: "minute", normalized: "m" },
|
|
1019
|
+
{ native: "minuten", normalized: "m" },
|
|
1020
|
+
{ native: "stunde", normalized: "h" },
|
|
1021
|
+
{ native: "stunden", normalized: "h" },
|
|
1022
|
+
// Umlaut-free variants (for user convenience)
|
|
1023
|
+
{ native: "hinzufugen", normalized: "add" },
|
|
1024
|
+
{ native: "hinzufgen", normalized: "add" },
|
|
1025
|
+
{ native: "loschen", normalized: "remove" },
|
|
1026
|
+
{ native: "anhangen", normalized: "append" },
|
|
1027
|
+
{ native: "erhohen", normalized: "increment" },
|
|
1028
|
+
{ native: "ubergang", normalized: "transition" },
|
|
1029
|
+
{ native: "auslosen", normalized: "trigger" },
|
|
1030
|
+
{ native: "zuruckgeben", normalized: "return" },
|
|
1031
|
+
{ native: "anschliessend", normalized: "then" },
|
|
1032
|
+
// Verb conjugation variants (imperatives for test cases)
|
|
1033
|
+
{ native: "erh\xF6he", normalized: "increment" },
|
|
1034
|
+
{ native: "erhohe", normalized: "increment" },
|
|
1035
|
+
{ native: "verringere", normalized: "decrement" }
|
|
1036
|
+
];
|
|
1037
|
+
var GERMAN_TIME_UNITS = [
|
|
1038
|
+
{ pattern: "millisekunden", suffix: "ms", length: 13, caseInsensitive: true },
|
|
1039
|
+
{ pattern: "millisekunde", suffix: "ms", length: 12, caseInsensitive: true },
|
|
1040
|
+
{ pattern: "sekunden", suffix: "s", length: 8, caseInsensitive: true },
|
|
1041
|
+
{ pattern: "sekunde", suffix: "s", length: 7, caseInsensitive: true },
|
|
1042
|
+
{ pattern: "minuten", suffix: "m", length: 7, caseInsensitive: true },
|
|
1043
|
+
{ pattern: "minute", suffix: "m", length: 6, caseInsensitive: true },
|
|
1044
|
+
{ pattern: "stunden", suffix: "h", length: 7, caseInsensitive: true },
|
|
1045
|
+
{ pattern: "stunde", suffix: "h", length: 6, caseInsensitive: true }
|
|
1046
|
+
];
|
|
1047
|
+
var GermanTokenizer = class extends BaseTokenizer {
|
|
1048
|
+
constructor() {
|
|
1049
|
+
super();
|
|
1050
|
+
this.language = "de";
|
|
1051
|
+
this.direction = "ltr";
|
|
1052
|
+
this.initializeKeywordsFromProfile(germanProfile, GERMAN_EXTRAS);
|
|
1053
|
+
}
|
|
1054
|
+
tokenize(input) {
|
|
1055
|
+
const tokens = [];
|
|
1056
|
+
let pos = 0;
|
|
1057
|
+
while (pos < input.length) {
|
|
1058
|
+
if (isWhitespace(input[pos])) {
|
|
1059
|
+
pos++;
|
|
1060
|
+
continue;
|
|
1061
|
+
}
|
|
1062
|
+
if (isSelectorStart(input[pos])) {
|
|
1063
|
+
const modifierToken = this.tryEventModifier(input, pos);
|
|
1064
|
+
if (modifierToken) {
|
|
1065
|
+
tokens.push(modifierToken);
|
|
1066
|
+
pos = modifierToken.position.end;
|
|
1067
|
+
continue;
|
|
1068
|
+
}
|
|
1069
|
+
const selectorToken = this.trySelector(input, pos);
|
|
1070
|
+
if (selectorToken) {
|
|
1071
|
+
tokens.push(selectorToken);
|
|
1072
|
+
pos = selectorToken.position.end;
|
|
1073
|
+
continue;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
if (isQuote(input[pos])) {
|
|
1077
|
+
const stringToken = this.tryString(input, pos);
|
|
1078
|
+
if (stringToken) {
|
|
1079
|
+
tokens.push(stringToken);
|
|
1080
|
+
pos = stringToken.position.end;
|
|
1081
|
+
continue;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
if (isUrlStart(input, pos)) {
|
|
1085
|
+
const urlToken = this.tryUrl(input, pos);
|
|
1086
|
+
if (urlToken) {
|
|
1087
|
+
tokens.push(urlToken);
|
|
1088
|
+
pos = urlToken.position.end;
|
|
1089
|
+
continue;
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
if (isDigit(input[pos]) || input[pos] === "-" && pos + 1 < input.length && isDigit(input[pos + 1])) {
|
|
1093
|
+
const numberToken = this.extractNumber(input, pos);
|
|
1094
|
+
if (numberToken) {
|
|
1095
|
+
tokens.push(numberToken);
|
|
1096
|
+
pos = numberToken.position.end;
|
|
1097
|
+
continue;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
const varToken = this.tryVariableRef(input, pos);
|
|
1101
|
+
if (varToken) {
|
|
1102
|
+
tokens.push(varToken);
|
|
1103
|
+
pos = varToken.position.end;
|
|
1104
|
+
continue;
|
|
1105
|
+
}
|
|
1106
|
+
if (isGermanLetter(input[pos])) {
|
|
1107
|
+
const wordToken = this.extractWord(input, pos);
|
|
1108
|
+
if (wordToken) {
|
|
1109
|
+
tokens.push(wordToken);
|
|
1110
|
+
pos = wordToken.position.end;
|
|
1111
|
+
continue;
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
const operatorToken = this.tryOperator(input, pos);
|
|
1115
|
+
if (operatorToken) {
|
|
1116
|
+
tokens.push(operatorToken);
|
|
1117
|
+
pos = operatorToken.position.end;
|
|
1118
|
+
continue;
|
|
1119
|
+
}
|
|
1120
|
+
pos++;
|
|
1121
|
+
}
|
|
1122
|
+
return new TokenStreamImpl(tokens, "de");
|
|
1123
|
+
}
|
|
1124
|
+
classifyToken(token) {
|
|
1125
|
+
const lower = token.toLowerCase();
|
|
1126
|
+
if (PREPOSITIONS.has(lower)) return "particle";
|
|
1127
|
+
if (this.isKeyword(lower)) return "keyword";
|
|
1128
|
+
if (token.startsWith("#") || token.startsWith(".") || token.startsWith("[")) return "selector";
|
|
1129
|
+
if (token.startsWith('"') || token.startsWith("'")) return "literal";
|
|
1130
|
+
if (/^\d/.test(token)) return "literal";
|
|
1131
|
+
return "identifier";
|
|
1132
|
+
}
|
|
1133
|
+
extractWord(input, startPos) {
|
|
1134
|
+
let pos = startPos;
|
|
1135
|
+
let word = "";
|
|
1136
|
+
while (pos < input.length && isGermanIdentifierChar(input[pos])) {
|
|
1137
|
+
word += input[pos++];
|
|
1138
|
+
}
|
|
1139
|
+
if (!word) return null;
|
|
1140
|
+
const lower = word.toLowerCase();
|
|
1141
|
+
const keywordEntry = this.lookupKeyword(lower);
|
|
1142
|
+
if (keywordEntry) {
|
|
1143
|
+
return createToken(word, "keyword", createPosition(startPos, pos), keywordEntry.normalized);
|
|
1144
|
+
}
|
|
1145
|
+
if (PREPOSITIONS.has(lower)) {
|
|
1146
|
+
return createToken(word, "particle", createPosition(startPos, pos));
|
|
1147
|
+
}
|
|
1148
|
+
return createToken(word, "identifier", createPosition(startPos, pos));
|
|
1149
|
+
}
|
|
1150
|
+
/**
|
|
1151
|
+
* Extract a number, including German time unit suffixes.
|
|
1152
|
+
*/
|
|
1153
|
+
extractNumber(input, startPos) {
|
|
1154
|
+
return this.tryNumberWithTimeUnits(input, startPos, GERMAN_TIME_UNITS, {
|
|
1155
|
+
allowSign: true,
|
|
1156
|
+
skipWhitespace: true
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1159
|
+
};
|
|
1160
|
+
var germanTokenizer = new GermanTokenizer();
|
|
1161
|
+
|
|
1162
|
+
// src/languages/de.ts
|
|
1163
|
+
registerLanguage("de", germanTokenizer, germanProfile);
|
|
1164
|
+
export {
|
|
1165
|
+
germanProfile,
|
|
1166
|
+
germanTokenizer
|
|
1167
|
+
};
|
|
1168
|
+
//# sourceMappingURL=de.js.map
|