@lokascript/semantic 1.2.0 → 1.3.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 (43) hide show
  1. package/dist/core.d.ts +1246 -0
  2. package/dist/core.js +3073 -0
  3. package/dist/core.js.map +1 -0
  4. package/dist/languages/bn.d.ts +33 -0
  5. package/dist/languages/bn.js +1101 -0
  6. package/dist/languages/bn.js.map +1 -0
  7. package/dist/languages/es-MX.d.ts +23 -0
  8. package/dist/languages/es-MX.js +1676 -0
  9. package/dist/languages/es-MX.js.map +1 -0
  10. package/dist/languages/es.d.ts +3 -42
  11. package/dist/languages/he.d.ts +70 -0
  12. package/dist/languages/he.js +1331 -0
  13. package/dist/languages/he.js.map +1 -0
  14. package/dist/languages/hi.d.ts +36 -0
  15. package/dist/languages/hi.js +1162 -0
  16. package/dist/languages/hi.js.map +1 -0
  17. package/dist/languages/it.d.ts +53 -0
  18. package/dist/languages/it.js +1600 -0
  19. package/dist/languages/it.js.map +1 -0
  20. package/dist/languages/ms.d.ts +32 -0
  21. package/dist/languages/ms.js +1043 -0
  22. package/dist/languages/ms.js.map +1 -0
  23. package/dist/languages/pl.d.ts +37 -0
  24. package/dist/languages/pl.js +1331 -0
  25. package/dist/languages/pl.js.map +1 -0
  26. package/dist/languages/ru.d.ts +37 -0
  27. package/dist/languages/ru.js +1356 -0
  28. package/dist/languages/ru.js.map +1 -0
  29. package/dist/languages/th.d.ts +35 -0
  30. package/dist/languages/th.js +1076 -0
  31. package/dist/languages/th.js.map +1 -0
  32. package/dist/languages/tl.d.ts +32 -0
  33. package/dist/languages/tl.js +1034 -0
  34. package/dist/languages/tl.js.map +1 -0
  35. package/dist/languages/uk.d.ts +37 -0
  36. package/dist/languages/uk.js +1356 -0
  37. package/dist/languages/uk.js.map +1 -0
  38. package/dist/languages/vi.d.ts +59 -0
  39. package/dist/languages/vi.js +1220 -0
  40. package/dist/languages/vi.js.map +1 -0
  41. package/dist/spanish-BedpM-NU.d.ts +43 -0
  42. package/package.json +53 -1
  43. package/src/core.ts +155 -0
@@ -0,0 +1,1220 @@
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/vietnamese.ts
781
+ var vietnameseProfile = {
782
+ code: "vi",
783
+ name: "Vietnamese",
784
+ nativeName: "Ti\u1EBFng Vi\u1EC7t",
785
+ direction: "ltr",
786
+ wordOrder: "SVO",
787
+ markingStrategy: "preposition",
788
+ usesSpaces: true,
789
+ // Vietnamese uses base/dictionary form for commands
790
+ defaultVerbForm: "base",
791
+ verb: {
792
+ position: "start",
793
+ subjectDrop: true
794
+ },
795
+ references: {
796
+ me: "t\xF4i",
797
+ // "I/me"
798
+ it: "n\xF3",
799
+ // "it"
800
+ you: "b\u1EA1n",
801
+ // "you"
802
+ result: "k\u1EBFt qu\u1EA3",
803
+ event: "s\u1EF1 ki\u1EC7n",
804
+ target: "m\u1EE5c ti\xEAu",
805
+ body: "body"
806
+ },
807
+ possessive: {
808
+ marker: "c\u1EE7a",
809
+ // Vietnamese uses "của" for possession (của tôi = my)
810
+ markerPosition: "between",
811
+ specialForms: {
812
+ me: "c\u1EE7a t\xF4i",
813
+ // "my"
814
+ it: "c\u1EE7a n\xF3",
815
+ // "its"
816
+ you: "c\u1EE7a b\u1EA1n"
817
+ // "your"
818
+ },
819
+ keywords: {
820
+ // Multi-word possessive phrases
821
+ // Note: These may require tokenizer support for multi-word recognition
822
+ "c\u1EE7a t\xF4i": "me",
823
+ // my
824
+ "c\u1EE7a b\u1EA1n": "you",
825
+ // your (informal)
826
+ "c\u1EE7a anh": "you",
827
+ // your (male speaker, formal)
828
+ "c\u1EE7a ch\u1ECB": "you",
829
+ // your (female speaker, formal)
830
+ "c\u1EE7a n\xF3": "it"
831
+ // its
832
+ }
833
+ },
834
+ roleMarkers: {
835
+ destination: { primary: "v\xE0o", alternatives: ["cho", "\u0111\u1EBFn"], position: "before" },
836
+ source: { primary: "t\u1EEB", alternatives: ["kh\u1ECFi"], position: "before" },
837
+ patient: { primary: "", position: "before" },
838
+ style: { primary: "v\u1EDBi", position: "before" }
839
+ },
840
+ keywords: {
841
+ // Class/Attribute operations
842
+ toggle: { primary: "chuy\u1EC3n \u0111\u1ED5i", alternatives: ["b\u1EADt t\u1EAFt", "chuy\u1EC3n"], normalized: "toggle" },
843
+ add: { primary: "th\xEAm", alternatives: ["b\u1ED5 sung"], normalized: "add" },
844
+ remove: { primary: "x\xF3a", alternatives: ["g\u1EE1 b\u1ECF", "lo\u1EA1i b\u1ECF", "b\u1ECF"], normalized: "remove" },
845
+ // Content operations
846
+ put: { primary: "\u0111\u1EB7t", alternatives: ["\u0111\u1EC3", "\u0111\u01B0a"], normalized: "put" },
847
+ append: { primary: "n\u1ED1i", normalized: "append" },
848
+ prepend: { primary: "th\xEAm v\xE0o \u0111\u1EA7u", normalized: "prepend" },
849
+ take: { primary: "l\u1EA5y", normalized: "take" },
850
+ make: { primary: "t\u1EA1o", normalized: "make" },
851
+ clone: { primary: "sao ch\xE9p", normalized: "clone" },
852
+ swap: { primary: "ho\xE1n \u0111\u1ED5i", normalized: "swap" },
853
+ morph: { primary: "bi\u1EBFn \u0111\u1ED5i", normalized: "morph" },
854
+ // Variable operations
855
+ set: { primary: "g\xE1n", alternatives: ["thi\u1EBFt l\u1EADp", "\u0111\u1EB7t"], normalized: "set" },
856
+ get: { primary: "l\u1EA5y gi\xE1 tr\u1ECB", alternatives: ["nh\u1EADn", "l\u1EA5y"], normalized: "get" },
857
+ increment: { primary: "t\u0103ng", alternatives: ["t\u0103ng l\xEAn"], normalized: "increment" },
858
+ decrement: { primary: "gi\u1EA3m", alternatives: ["gi\u1EA3m \u0111i"], normalized: "decrement" },
859
+ log: { primary: "in ra", normalized: "log" },
860
+ // Visibility
861
+ show: { primary: "hi\u1EC3n th\u1ECB", alternatives: ["hi\u1EC7n"], normalized: "show" },
862
+ hide: { primary: "\u1EA9n", alternatives: ["che", "gi\u1EA5u"], normalized: "hide" },
863
+ transition: { primary: "chuy\u1EC3n ti\u1EBFp", normalized: "transition" },
864
+ // Events
865
+ on: { primary: "khi", alternatives: ["l\xFAc", "tr\xEAn"], normalized: "on" },
866
+ trigger: { primary: "k\xEDch ho\u1EA1t", normalized: "trigger" },
867
+ send: { primary: "g\u1EEDi", normalized: "send" },
868
+ // DOM focus
869
+ focus: { primary: "t\u1EADp trung", normalized: "focus" },
870
+ blur: { primary: "m\u1EA5t t\u1EADp trung", normalized: "blur" },
871
+ // Common event names (for event handler patterns)
872
+ click: { primary: "nh\u1EA5p", alternatives: ["b\u1EA5m"], normalized: "click" },
873
+ hover: { primary: "di chu\u1ED9t", alternatives: ["r\xEA chu\u1ED9t"], normalized: "hover" },
874
+ submit: { primary: "g\u1EEDi", alternatives: ["n\u1ED9p"], normalized: "submit" },
875
+ input: { primary: "nh\u1EADp", alternatives: ["nh\u1EADp li\u1EC7u"], normalized: "input" },
876
+ change: { primary: "thay \u0111\u1ED5i", alternatives: ["\u0111\u1ED5i"], normalized: "change" },
877
+ // Navigation
878
+ go: { primary: "\u0111i \u0111\u1EBFn", alternatives: ["\u0111i"], normalized: "go" },
879
+ // Async
880
+ wait: { primary: "ch\u1EDD", alternatives: ["\u0111\u1EE3i"], normalized: "wait" },
881
+ fetch: { primary: "t\u1EA3i", normalized: "fetch" },
882
+ settle: { primary: "\u1ED5n \u0111\u1ECBnh", normalized: "settle" },
883
+ // Control flow
884
+ if: { primary: "n\u1EBFu", normalized: "if" },
885
+ when: { primary: "khi", normalized: "when" },
886
+ where: { primary: "\u1EDF_\u0111\xE2u", normalized: "where" },
887
+ else: { primary: "kh\xF4ng th\xEC", alternatives: ["n\u1EBFu kh\xF4ng"], normalized: "else" },
888
+ repeat: { primary: "l\u1EB7p l\u1EA1i", normalized: "repeat" },
889
+ for: { primary: "v\u1EDBi m\u1ED7i", normalized: "for" },
890
+ while: { primary: "trong khi", normalized: "while" },
891
+ continue: { primary: "ti\u1EBFp t\u1EE5c", normalized: "continue" },
892
+ halt: { primary: "d\u1EEBng", alternatives: ["d\u1EEBng l\u1EA1i"], normalized: "halt" },
893
+ throw: { primary: "n\xE9m", normalized: "throw" },
894
+ call: { primary: "g\u1ECDi", normalized: "call" },
895
+ return: { primary: "tr\u1EA3 v\u1EC1", normalized: "return" },
896
+ then: { primary: "r\u1ED3i", alternatives: ["sau \u0111\xF3", "th\xEC"], normalized: "then" },
897
+ and: { primary: "v\xE0", normalized: "and" },
898
+ end: { primary: "k\u1EBFt th\xFAc", normalized: "end" },
899
+ // Advanced
900
+ js: { primary: "js", normalized: "js" },
901
+ async: { primary: "b\u1EA5t \u0111\u1ED3ng b\u1ED9", normalized: "async" },
902
+ tell: { primary: "n\xF3i v\u1EDBi", normalized: "tell" },
903
+ default: { primary: "m\u1EB7c \u0111\u1ECBnh", normalized: "default" },
904
+ init: { primary: "kh\u1EDFi t\u1EA1o", normalized: "init" },
905
+ behavior: { primary: "h\xE0nh vi", normalized: "behavior" },
906
+ install: { primary: "c\xE0i \u0111\u1EB7t", normalized: "install" },
907
+ measure: { primary: "\u0111o l\u01B0\u1EDDng", normalized: "measure" },
908
+ // Modifiers
909
+ into: { primary: "v\xE0o", alternatives: ["v\xE0o trong"], normalized: "into" },
910
+ before: { primary: "tr\u01B0\u1EDBc", alternatives: ["tr\u01B0\u1EDBc khi"], normalized: "before" },
911
+ after: { primary: "sau", alternatives: ["sau khi"], normalized: "after" },
912
+ // Event modifiers
913
+ until: { primary: "cho \u0111\u1EBFn khi", normalized: "until" },
914
+ event: { primary: "s\u1EF1 ki\u1EC7n", normalized: "event" },
915
+ from: { primary: "t\u1EEB", alternatives: ["kh\u1ECFi"], normalized: "from" }
916
+ },
917
+ eventHandler: {
918
+ keyword: { primary: "khi", alternatives: ["l\xFAc", "tr\xEAn"], normalized: "on" },
919
+ sourceMarker: { primary: "tr\xEAn", alternatives: ["t\u1EA1i"], position: "before" },
920
+ // Event marker: khi (when), used in SVO pattern
921
+ // Pattern: khi [event] [verb] [patient] vào [destination?]
922
+ // Example: khi nhấp chuyển đổi .active vào #button
923
+ eventMarker: { primary: "khi", alternatives: ["l\xFAc"], position: "before" },
924
+ temporalMarkers: ["khi", "l\xFAc"]
925
+ // temporal conjunctions (when)
926
+ }
927
+ };
928
+
929
+ // src/tokenizers/vietnamese.ts
930
+ var { isLetter: isVietnameseLetter, isIdentifierChar: isVietnameseIdentifierChar } = createLatinCharClassifiers(
931
+ /[a-zA-ZàáảãạăằắẳẵặâầấẩẫậèéẻẽẹêềếểễệìíỉĩịòóỏõọôồốổỗộơờớởỡợùúủũụưừứửữựỳýỷỹỵđÀÁẢÃẠĂẰẮẲẴẶÂẦẤẨẪẬÈÉẺẼẸÊỀẾỂỄỆÌÍỈĨỊÒÓỎÕỌÔỒỐỔỖỘƠỜỚỞỠỢÙÚỦŨỤƯỪỨỬỮỰỲÝỶỸỴĐ]/
932
+ );
933
+ var PREPOSITIONS = /* @__PURE__ */ new Set([
934
+ "trong",
935
+ // in, inside
936
+ "ngo\xE0i",
937
+ // outside
938
+ "tr\xEAn",
939
+ // on, above
940
+ "d\u01B0\u1EDBi",
941
+ // under, below
942
+ "v\xE0o",
943
+ // into
944
+ "ra",
945
+ // out
946
+ "\u0111\u1EBFn",
947
+ // to
948
+ "t\u1EEB",
949
+ // from
950
+ "v\u1EDBi",
951
+ // with
952
+ "cho",
953
+ // for, to
954
+ "b\u1EDFi",
955
+ // by
956
+ "qua",
957
+ // through
958
+ "tr\u01B0\u1EDBc",
959
+ // before
960
+ "sau",
961
+ // after
962
+ "gi\u1EEFa",
963
+ // between
964
+ "b\xEAn",
965
+ // beside
966
+ "theo",
967
+ // according to, along
968
+ "v\u1EC1",
969
+ // about, towards
970
+ "t\u1EDBi",
971
+ // to, towards
972
+ "l\xEAn",
973
+ // up
974
+ "xu\u1ED1ng"
975
+ // down
976
+ ]);
977
+ var VIETNAMESE_EXTRAS = [
978
+ // Values/Literals
979
+ { native: "\u0111\xFAng", normalized: "true" },
980
+ { native: "sai", normalized: "false" },
981
+ { native: "null", normalized: "null" },
982
+ { native: "kh\xF4ng x\xE1c \u0111\u1ECBnh", normalized: "undefined" },
983
+ // Positional
984
+ { native: "\u0111\u1EA7u ti\xEAn", normalized: "first" },
985
+ { native: "cu\u1ED1i c\xF9ng", normalized: "last" },
986
+ { native: "ti\u1EBFp theo", normalized: "next" },
987
+ { native: "tr\u01B0\u1EDBc \u0111\xF3", normalized: "previous" },
988
+ { native: "g\u1EA7n nh\u1EA5t", normalized: "closest" },
989
+ { native: "cha", normalized: "parent" },
990
+ // Events
991
+ { native: "nh\u1EA5p", normalized: "click" },
992
+ { native: "nh\u1EA5p chu\u1ED9t", normalized: "click" },
993
+ { native: "click", normalized: "click" },
994
+ { native: "nh\u1EA5p \u0111\xFAp", normalized: "dblclick" },
995
+ { native: "nh\u1EADp", normalized: "input" },
996
+ { native: "thay \u0111\u1ED5i", normalized: "change" },
997
+ { native: "g\u1EEDi bi\u1EC3u m\u1EABu", normalized: "submit" },
998
+ { native: "ph\xEDm xu\u1ED1ng", normalized: "keydown" },
999
+ { native: "ph\xEDm l\xEAn", normalized: "keyup" },
1000
+ { native: "chu\u1ED9t v\xE0o", normalized: "mouseover" },
1001
+ { native: "chu\u1ED9t ra", normalized: "mouseout" },
1002
+ { native: "t\u1EA3i trang", normalized: "load" },
1003
+ { native: "cu\u1ED9n", normalized: "scroll" },
1004
+ // References - possessive forms
1005
+ { native: "c\u1EE7a t\xF4i", normalized: "my" },
1006
+ { native: "c\u1EE7a n\xF3", normalized: "its" },
1007
+ // Time units
1008
+ { native: "gi\xE2y", normalized: "s" },
1009
+ { native: "mili gi\xE2y", normalized: "ms" },
1010
+ { native: "ph\xFAt", normalized: "m" },
1011
+ { native: "gi\u1EDD", normalized: "h" },
1012
+ // Additional multi-word phrases not in profile
1013
+ { native: "th\xEAm v\xE0o cu\u1ED1i", normalized: "append" },
1014
+ { native: "nh\xE2n b\u1EA3n", normalized: "clone" },
1015
+ { native: "t\u1EA1o ra", normalized: "make" },
1016
+ { native: "\u0111\u1EB7t gi\xE1 tr\u1ECB", normalized: "set" },
1017
+ { native: "ghi nh\u1EADt k\xFD", normalized: "log" },
1018
+ { native: "chuy\u1EC3n t\u1EDBi", normalized: "go" },
1019
+ { native: "ng\u01B0\u1EE3c l\u1EA1i", normalized: "else" },
1020
+ { native: "l\u1EB7p", normalized: "repeat" },
1021
+ // Logical/conditional
1022
+ { native: "ho\u1EB7c", normalized: "or" },
1023
+ { native: "kh\xF4ng", normalized: "not" },
1024
+ { native: "l\xE0", normalized: "is" },
1025
+ { native: "t\u1ED3n t\u1EA1i", normalized: "exists" },
1026
+ { native: "r\u1ED7ng", normalized: "empty" },
1027
+ // English synonyms
1028
+ { native: "javascript", normalized: "js" }
1029
+ ];
1030
+ var VietnameseTokenizer = class extends BaseTokenizer {
1031
+ constructor() {
1032
+ super();
1033
+ this.language = "vi";
1034
+ this.direction = "ltr";
1035
+ this.initializeKeywordsFromProfile(vietnameseProfile, VIETNAMESE_EXTRAS);
1036
+ }
1037
+ tokenize(input) {
1038
+ const tokens = [];
1039
+ let pos = 0;
1040
+ while (pos < input.length) {
1041
+ if (isWhitespace(input[pos])) {
1042
+ pos++;
1043
+ continue;
1044
+ }
1045
+ if (isSelectorStart(input[pos])) {
1046
+ const modifierToken = this.tryEventModifier(input, pos);
1047
+ if (modifierToken) {
1048
+ tokens.push(modifierToken);
1049
+ pos = modifierToken.position.end;
1050
+ continue;
1051
+ }
1052
+ const selectorToken = this.trySelector(input, pos);
1053
+ if (selectorToken) {
1054
+ tokens.push(selectorToken);
1055
+ pos = selectorToken.position.end;
1056
+ continue;
1057
+ }
1058
+ }
1059
+ if (isQuote(input[pos])) {
1060
+ const stringToken = this.tryString(input, pos);
1061
+ if (stringToken) {
1062
+ tokens.push(stringToken);
1063
+ pos = stringToken.position.end;
1064
+ continue;
1065
+ }
1066
+ }
1067
+ if (isUrlStart(input, pos)) {
1068
+ const urlToken = this.tryUrl(input, pos);
1069
+ if (urlToken) {
1070
+ tokens.push(urlToken);
1071
+ pos = urlToken.position.end;
1072
+ continue;
1073
+ }
1074
+ }
1075
+ if (isDigit(input[pos])) {
1076
+ const numberToken = this.extractVietnameseNumber(input, pos);
1077
+ if (numberToken) {
1078
+ tokens.push(numberToken);
1079
+ pos = numberToken.position.end;
1080
+ continue;
1081
+ }
1082
+ }
1083
+ const varToken = this.tryVariableRef(input, pos);
1084
+ if (varToken) {
1085
+ tokens.push(varToken);
1086
+ pos = varToken.position.end;
1087
+ continue;
1088
+ }
1089
+ const opToken = this.tryOperator(input, pos);
1090
+ if (opToken) {
1091
+ tokens.push(opToken);
1092
+ pos = opToken.position.end;
1093
+ continue;
1094
+ }
1095
+ const phraseToken = this.tryMultiWordPhrase(input, pos);
1096
+ if (phraseToken) {
1097
+ tokens.push(phraseToken);
1098
+ pos = phraseToken.position.end;
1099
+ continue;
1100
+ }
1101
+ if (isVietnameseLetter(input[pos])) {
1102
+ const wordToken = this.extractVietnameseWord(input, pos);
1103
+ if (wordToken) {
1104
+ tokens.push(wordToken);
1105
+ pos = wordToken.position.end;
1106
+ continue;
1107
+ }
1108
+ }
1109
+ pos++;
1110
+ }
1111
+ return new TokenStreamImpl(tokens, "vi");
1112
+ }
1113
+ classifyToken(token) {
1114
+ const lower = token.toLowerCase();
1115
+ if (PREPOSITIONS.has(lower)) return "particle";
1116
+ if (this.isKeyword(lower)) return "keyword";
1117
+ if (token.startsWith("#") || token.startsWith(".") || token.startsWith("[") || token.startsWith("<"))
1118
+ return "selector";
1119
+ if (token.startsWith('"') || token.startsWith("'")) return "literal";
1120
+ if (/^\d/.test(token)) return "literal";
1121
+ return "identifier";
1122
+ }
1123
+ /**
1124
+ * Try to match a multi-word phrase.
1125
+ * Multi-word phrases are included in profileKeywords and sorted longest-first.
1126
+ */
1127
+ tryMultiWordPhrase(input, pos) {
1128
+ for (const entry of this.profileKeywords) {
1129
+ if (!entry.native.includes(" ")) continue;
1130
+ const phrase = entry.native;
1131
+ const candidate = input.slice(pos, pos + phrase.length).toLowerCase();
1132
+ if (candidate === phrase.toLowerCase()) {
1133
+ const nextChar = input[pos + phrase.length];
1134
+ if (nextChar && isVietnameseLetter(nextChar)) continue;
1135
+ return createToken(
1136
+ input.slice(pos, pos + phrase.length),
1137
+ "keyword",
1138
+ createPosition(pos, pos + phrase.length),
1139
+ entry.normalized
1140
+ );
1141
+ }
1142
+ }
1143
+ return null;
1144
+ }
1145
+ /**
1146
+ * Extract a Vietnamese word (single syllable/word).
1147
+ */
1148
+ extractVietnameseWord(input, startPos) {
1149
+ let pos = startPos;
1150
+ let word = "";
1151
+ while (pos < input.length && isVietnameseIdentifierChar(input[pos])) {
1152
+ word += input[pos++];
1153
+ }
1154
+ if (!word) return null;
1155
+ const lower = word.toLowerCase();
1156
+ if (PREPOSITIONS.has(lower)) {
1157
+ return createToken(word, "particle", createPosition(startPos, pos));
1158
+ }
1159
+ const keywordEntry = this.lookupKeyword(lower);
1160
+ if (keywordEntry) {
1161
+ return createToken(word, "keyword", createPosition(startPos, pos), keywordEntry.normalized);
1162
+ }
1163
+ return createToken(word, "identifier", createPosition(startPos, pos));
1164
+ }
1165
+ /**
1166
+ * Extract a number, including time unit suffixes.
1167
+ */
1168
+ extractVietnameseNumber(input, startPos) {
1169
+ let pos = startPos;
1170
+ let number = "";
1171
+ while (pos < input.length && isDigit(input[pos])) {
1172
+ number += input[pos++];
1173
+ }
1174
+ if (pos < input.length && input[pos] === ".") {
1175
+ number += input[pos++];
1176
+ while (pos < input.length && isDigit(input[pos])) {
1177
+ number += input[pos++];
1178
+ }
1179
+ }
1180
+ if (pos < input.length) {
1181
+ const remaining = input.slice(pos).toLowerCase();
1182
+ if (remaining.startsWith(" mili gi\xE2y") || remaining.startsWith(" miligi\xE2y")) {
1183
+ number += "ms";
1184
+ pos += remaining.startsWith(" mili gi\xE2y") ? 10 : 9;
1185
+ } else if (remaining.startsWith(" gi\xE2y")) {
1186
+ number += "s";
1187
+ pos += 5;
1188
+ } else if (remaining.startsWith(" ph\xFAt")) {
1189
+ number += "m";
1190
+ pos += 5;
1191
+ } else if (remaining.startsWith(" gi\u1EDD")) {
1192
+ number += "h";
1193
+ pos += 4;
1194
+ } else if (remaining.startsWith("ms")) {
1195
+ number += "ms";
1196
+ pos += 2;
1197
+ } else if (remaining[0] === "s" && !isVietnameseLetter(remaining[1] || "")) {
1198
+ number += "s";
1199
+ pos += 1;
1200
+ } else if (remaining[0] === "m" && remaining[1] !== "s" && !isVietnameseLetter(remaining[1] || "")) {
1201
+ number += "m";
1202
+ pos += 1;
1203
+ } else if (remaining[0] === "h" && !isVietnameseLetter(remaining[1] || "")) {
1204
+ number += "h";
1205
+ pos += 1;
1206
+ }
1207
+ }
1208
+ if (!number) return null;
1209
+ return createToken(number, "literal", createPosition(startPos, pos));
1210
+ }
1211
+ };
1212
+ var vietnameseTokenizer = new VietnameseTokenizer();
1213
+
1214
+ // src/languages/vi.ts
1215
+ registerLanguage("vi", vietnameseTokenizer, vietnameseProfile);
1216
+ export {
1217
+ vietnameseProfile,
1218
+ vietnameseTokenizer
1219
+ };
1220
+ //# sourceMappingURL=vi.js.map