@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,1034 @@
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 extractCssSelector(input, startPos) {
110
+ if (startPos >= input.length) return null;
111
+ const char = input[startPos];
112
+ if (!isSelectorStart(char)) return null;
113
+ let pos = startPos;
114
+ let selector = "";
115
+ if (char === "#" || char === ".") {
116
+ selector += input[pos++];
117
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
118
+ selector += input[pos++];
119
+ }
120
+ if (selector.length <= 1) return null;
121
+ if (pos < input.length && input[pos] === "." && char === "#") {
122
+ const methodStart = pos + 1;
123
+ let methodEnd = methodStart;
124
+ while (methodEnd < input.length && isAsciiIdentifierChar(input[methodEnd])) {
125
+ methodEnd++;
126
+ }
127
+ if (methodEnd < input.length && input[methodEnd] === "(") {
128
+ return selector;
129
+ }
130
+ }
131
+ } else if (char === "[") {
132
+ let depth = 1;
133
+ let inQuote = false;
134
+ let quoteChar = null;
135
+ let escaped = false;
136
+ selector += input[pos++];
137
+ while (pos < input.length && depth > 0) {
138
+ const c = input[pos];
139
+ selector += c;
140
+ if (escaped) {
141
+ escaped = false;
142
+ } else if (c === "\\") {
143
+ escaped = true;
144
+ } else if (inQuote) {
145
+ if (c === quoteChar) {
146
+ inQuote = false;
147
+ quoteChar = null;
148
+ }
149
+ } else {
150
+ if (c === '"' || c === "'" || c === "`") {
151
+ inQuote = true;
152
+ quoteChar = c;
153
+ } else if (c === "[") {
154
+ depth++;
155
+ } else if (c === "]") {
156
+ depth--;
157
+ }
158
+ }
159
+ pos++;
160
+ }
161
+ if (depth !== 0) return null;
162
+ } else if (char === "@") {
163
+ selector += input[pos++];
164
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
165
+ selector += input[pos++];
166
+ }
167
+ if (selector.length <= 1) return null;
168
+ } else if (char === "*") {
169
+ selector += input[pos++];
170
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
171
+ selector += input[pos++];
172
+ }
173
+ if (selector.length <= 1) return null;
174
+ } else if (char === "<") {
175
+ selector += input[pos++];
176
+ if (pos >= input.length || !isAsciiLetter(input[pos])) return null;
177
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
178
+ selector += input[pos++];
179
+ }
180
+ while (pos < input.length) {
181
+ const modChar = input[pos];
182
+ if (modChar === ".") {
183
+ selector += input[pos++];
184
+ if (pos >= input.length || !isAsciiIdentifierChar(input[pos])) {
185
+ return null;
186
+ }
187
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
188
+ selector += input[pos++];
189
+ }
190
+ } else if (modChar === "#") {
191
+ selector += input[pos++];
192
+ if (pos >= input.length || !isAsciiIdentifierChar(input[pos])) {
193
+ return null;
194
+ }
195
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
196
+ selector += input[pos++];
197
+ }
198
+ } else if (modChar === "[") {
199
+ let depth = 1;
200
+ let inQuote = false;
201
+ let quoteChar = null;
202
+ let escaped = false;
203
+ selector += input[pos++];
204
+ while (pos < input.length && depth > 0) {
205
+ const c = input[pos];
206
+ selector += c;
207
+ if (escaped) {
208
+ escaped = false;
209
+ } else if (c === "\\") {
210
+ escaped = true;
211
+ } else if (inQuote) {
212
+ if (c === quoteChar) {
213
+ inQuote = false;
214
+ quoteChar = null;
215
+ }
216
+ } else {
217
+ if (c === '"' || c === "'" || c === "`") {
218
+ inQuote = true;
219
+ quoteChar = c;
220
+ } else if (c === "[") {
221
+ depth++;
222
+ } else if (c === "]") {
223
+ depth--;
224
+ }
225
+ }
226
+ pos++;
227
+ }
228
+ if (depth !== 0) return null;
229
+ } else {
230
+ break;
231
+ }
232
+ }
233
+ while (pos < input.length && isWhitespace(input[pos])) {
234
+ selector += input[pos++];
235
+ }
236
+ if (pos < input.length && input[pos] === "/") {
237
+ selector += input[pos++];
238
+ while (pos < input.length && isWhitespace(input[pos])) {
239
+ selector += input[pos++];
240
+ }
241
+ }
242
+ if (pos >= input.length || input[pos] !== ">") return null;
243
+ selector += input[pos++];
244
+ }
245
+ return selector || null;
246
+ }
247
+ function isPossessiveMarker(input, pos) {
248
+ if (pos >= input.length || input[pos] !== "'") return false;
249
+ if (pos + 1 >= input.length) return false;
250
+ const nextChar = input[pos + 1].toLowerCase();
251
+ if (nextChar !== "s") return false;
252
+ if (pos + 2 >= input.length) return true;
253
+ const afterS = input[pos + 2];
254
+ return isWhitespace(afterS) || afterS === "*" || !isAsciiIdentifierChar(afterS);
255
+ }
256
+ function extractStringLiteral(input, startPos) {
257
+ if (startPos >= input.length) return null;
258
+ const openQuote = input[startPos];
259
+ if (!isQuote(openQuote)) return null;
260
+ if (openQuote === "'" && isPossessiveMarker(input, startPos)) {
261
+ return null;
262
+ }
263
+ const closeQuoteMap = {
264
+ '"': '"',
265
+ "'": "'",
266
+ "`": "`",
267
+ "\u300C": "\u300D"
268
+ };
269
+ const closeQuote = closeQuoteMap[openQuote];
270
+ if (!closeQuote) return null;
271
+ let pos = startPos + 1;
272
+ let literal = openQuote;
273
+ let escaped = false;
274
+ while (pos < input.length) {
275
+ const char = input[pos];
276
+ literal += char;
277
+ if (escaped) {
278
+ escaped = false;
279
+ } else if (char === "\\") {
280
+ escaped = true;
281
+ } else if (char === closeQuote) {
282
+ return literal;
283
+ }
284
+ pos++;
285
+ }
286
+ return literal;
287
+ }
288
+ function isUrlStart(input, pos) {
289
+ if (pos >= input.length) return false;
290
+ const char = input[pos];
291
+ const next = input[pos + 1] || "";
292
+ const third = input[pos + 2] || "";
293
+ if (char === "/" && next !== "/" && /[a-zA-Z0-9._-]/.test(next)) {
294
+ return true;
295
+ }
296
+ if (char === "/" && next === "/" && /[a-zA-Z]/.test(third)) {
297
+ return true;
298
+ }
299
+ if (char === "." && (next === "/" || next === "." && third === "/")) {
300
+ return true;
301
+ }
302
+ const slice = input.slice(pos, pos + 8).toLowerCase();
303
+ if (slice.startsWith("http://") || slice.startsWith("https://")) {
304
+ return true;
305
+ }
306
+ return false;
307
+ }
308
+ function extractUrl(input, startPos) {
309
+ if (!isUrlStart(input, startPos)) return null;
310
+ let pos = startPos;
311
+ let url = "";
312
+ const urlChars = /[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;
313
+ while (pos < input.length) {
314
+ const char = input[pos];
315
+ if (char === "#") {
316
+ if (url.length > 0 && /[a-zA-Z0-9/.]$/.test(url)) {
317
+ url += char;
318
+ pos++;
319
+ while (pos < input.length && /[a-zA-Z0-9_-]/.test(input[pos])) {
320
+ url += input[pos++];
321
+ }
322
+ }
323
+ break;
324
+ }
325
+ if (urlChars.test(char)) {
326
+ url += char;
327
+ pos++;
328
+ } else {
329
+ break;
330
+ }
331
+ }
332
+ if (url.length < 2) return null;
333
+ return url;
334
+ }
335
+ function extractNumber(input, startPos) {
336
+ if (startPos >= input.length) return null;
337
+ const char = input[startPos];
338
+ if (!isDigit(char) && char !== "-" && char !== "+") return null;
339
+ let pos = startPos;
340
+ let number = "";
341
+ if (input[pos] === "-" || input[pos] === "+") {
342
+ number += input[pos++];
343
+ }
344
+ if (pos >= input.length || !isDigit(input[pos])) {
345
+ return null;
346
+ }
347
+ while (pos < input.length && isDigit(input[pos])) {
348
+ number += input[pos++];
349
+ }
350
+ if (pos < input.length && input[pos] === ".") {
351
+ number += input[pos++];
352
+ while (pos < input.length && isDigit(input[pos])) {
353
+ number += input[pos++];
354
+ }
355
+ }
356
+ if (pos < input.length) {
357
+ const suffix = input.slice(pos, pos + 2);
358
+ if (suffix === "ms") {
359
+ number += "ms";
360
+ } else if (input[pos] === "s" || input[pos] === "m" || input[pos] === "h") {
361
+ number += input[pos];
362
+ }
363
+ }
364
+ return number;
365
+ }
366
+ var _BaseTokenizer = class _BaseTokenizer {
367
+ constructor() {
368
+ /** Keywords derived from profile, sorted longest-first for greedy matching */
369
+ this.profileKeywords = [];
370
+ /** Map for O(1) keyword lookups by lowercase native word */
371
+ this.profileKeywordMap = /* @__PURE__ */ new Map();
372
+ }
373
+ /**
374
+ * Initialize keyword mappings from a language profile.
375
+ * Builds a list of native→english mappings from:
376
+ * - profile.keywords (primary + alternatives)
377
+ * - profile.references (me, it, you, etc.)
378
+ * - profile.roleMarkers (into, from, with, etc.)
379
+ *
380
+ * Results are sorted longest-first for greedy matching (important for non-space languages).
381
+ * Extras take precedence over profile entries when there are duplicates.
382
+ *
383
+ * @param profile - Language profile containing keyword translations
384
+ * @param extras - Additional keyword entries to include (literals, positional, events)
385
+ */
386
+ initializeKeywordsFromProfile(profile, extras = []) {
387
+ const keywordMap = /* @__PURE__ */ new Map();
388
+ if (profile.keywords) {
389
+ for (const [normalized, translation] of Object.entries(profile.keywords)) {
390
+ keywordMap.set(translation.primary, {
391
+ native: translation.primary,
392
+ normalized: translation.normalized || normalized
393
+ });
394
+ if (translation.alternatives) {
395
+ for (const alt of translation.alternatives) {
396
+ keywordMap.set(alt, {
397
+ native: alt,
398
+ normalized: translation.normalized || normalized
399
+ });
400
+ }
401
+ }
402
+ }
403
+ }
404
+ if (profile.references) {
405
+ for (const [normalized, native] of Object.entries(profile.references)) {
406
+ keywordMap.set(native, { native, normalized });
407
+ }
408
+ }
409
+ if (profile.roleMarkers) {
410
+ for (const [role, marker] of Object.entries(profile.roleMarkers)) {
411
+ if (marker.primary) {
412
+ keywordMap.set(marker.primary, { native: marker.primary, normalized: role });
413
+ }
414
+ if (marker.alternatives) {
415
+ for (const alt of marker.alternatives) {
416
+ keywordMap.set(alt, { native: alt, normalized: role });
417
+ }
418
+ }
419
+ }
420
+ }
421
+ for (const extra of extras) {
422
+ keywordMap.set(extra.native, extra);
423
+ }
424
+ this.profileKeywords = Array.from(keywordMap.values()).sort(
425
+ (a, b) => b.native.length - a.native.length
426
+ );
427
+ this.profileKeywordMap = /* @__PURE__ */ new Map();
428
+ for (const keyword of this.profileKeywords) {
429
+ this.profileKeywordMap.set(keyword.native.toLowerCase(), keyword);
430
+ const normalized = this.removeDiacritics(keyword.native);
431
+ if (normalized !== keyword.native && !this.profileKeywordMap.has(normalized.toLowerCase())) {
432
+ this.profileKeywordMap.set(normalized.toLowerCase(), keyword);
433
+ }
434
+ }
435
+ }
436
+ /**
437
+ * Remove diacritical marks from a word for normalization.
438
+ * Primarily for Arabic (shadda, fatha, kasra, damma, sukun, etc.)
439
+ * but could be extended for other languages.
440
+ *
441
+ * @param word - Word to normalize
442
+ * @returns Word without diacritics
443
+ */
444
+ removeDiacritics(word) {
445
+ return word.replace(/[\u064B-\u0652\u0670]/g, "");
446
+ }
447
+ /**
448
+ * Try to match a keyword from profile at the current position.
449
+ * Uses longest-first greedy matching (important for non-space languages).
450
+ *
451
+ * @param input - Input string
452
+ * @param pos - Current position
453
+ * @returns Token if matched, null otherwise
454
+ */
455
+ tryProfileKeyword(input, pos) {
456
+ for (const entry of this.profileKeywords) {
457
+ if (input.slice(pos).startsWith(entry.native)) {
458
+ return createToken(
459
+ entry.native,
460
+ "keyword",
461
+ createPosition(pos, pos + entry.native.length),
462
+ entry.normalized
463
+ );
464
+ }
465
+ }
466
+ return null;
467
+ }
468
+ /**
469
+ * Check if the remaining input starts with any known keyword.
470
+ * Useful for non-space languages to detect word boundaries.
471
+ *
472
+ * @param input - Input string
473
+ * @param pos - Current position
474
+ * @returns true if a keyword starts at this position
475
+ */
476
+ isKeywordStart(input, pos) {
477
+ const remaining = input.slice(pos);
478
+ return this.profileKeywords.some((entry) => remaining.startsWith(entry.native));
479
+ }
480
+ /**
481
+ * Look up a keyword by native word (case-insensitive).
482
+ * O(1) lookup using the keyword map.
483
+ *
484
+ * @param native - Native word to look up
485
+ * @returns KeywordEntry if found, undefined otherwise
486
+ */
487
+ lookupKeyword(native) {
488
+ return this.profileKeywordMap.get(native.toLowerCase());
489
+ }
490
+ /**
491
+ * Check if a word is a known keyword (case-insensitive).
492
+ * O(1) lookup using the keyword map.
493
+ *
494
+ * @param native - Native word to check
495
+ * @returns true if the word is a keyword
496
+ */
497
+ isKeyword(native) {
498
+ return this.profileKeywordMap.has(native.toLowerCase());
499
+ }
500
+ /**
501
+ * Set the morphological normalizer for this tokenizer.
502
+ */
503
+ setNormalizer(normalizer) {
504
+ this.normalizer = normalizer;
505
+ }
506
+ /**
507
+ * Try to normalize a word using the morphological normalizer.
508
+ * Returns null if no normalizer is set or normalization fails.
509
+ *
510
+ * Note: We don't check isNormalizable() here because the individual tokenizers
511
+ * historically called normalize() directly without that check. The normalize()
512
+ * method itself handles returning noChange() for words that can't be normalized.
513
+ */
514
+ tryNormalize(word) {
515
+ if (!this.normalizer) return null;
516
+ const result = this.normalizer.normalize(word);
517
+ if (result.stem !== word && result.confidence >= 0.7) {
518
+ return result;
519
+ }
520
+ return null;
521
+ }
522
+ /**
523
+ * Try morphological normalization and keyword lookup.
524
+ *
525
+ * If the word can be normalized to a stem that matches a known keyword,
526
+ * returns a keyword token with morphological metadata (stem, stemConfidence).
527
+ *
528
+ * This is the common pattern for handling conjugated verbs across languages:
529
+ * 1. Normalize the word (e.g., "toggled" → "toggle")
530
+ * 2. Look up the stem in the keyword map
531
+ * 3. Create a token with both the original form and stem metadata
532
+ *
533
+ * @param word - The word to normalize and look up
534
+ * @param startPos - Start position for the token
535
+ * @param endPos - End position for the token
536
+ * @returns Token if stem matches a keyword, null otherwise
537
+ */
538
+ tryMorphKeywordMatch(word, startPos, endPos) {
539
+ const result = this.tryNormalize(word);
540
+ if (!result) return null;
541
+ const stemEntry = this.lookupKeyword(result.stem);
542
+ if (!stemEntry) return null;
543
+ const tokenOptions = {
544
+ normalized: stemEntry.normalized,
545
+ stem: result.stem,
546
+ stemConfidence: result.confidence
547
+ };
548
+ return createToken(word, "keyword", createPosition(startPos, endPos), tokenOptions);
549
+ }
550
+ /**
551
+ * Try to extract a CSS selector at the current position.
552
+ */
553
+ trySelector(input, pos) {
554
+ const selector = extractCssSelector(input, pos);
555
+ if (selector) {
556
+ return createToken(selector, "selector", createPosition(pos, pos + selector.length));
557
+ }
558
+ return null;
559
+ }
560
+ /**
561
+ * Try to extract an event modifier at the current position.
562
+ * Event modifiers are .once, .debounce(N), .throttle(N), .queue(strategy)
563
+ */
564
+ tryEventModifier(input, pos) {
565
+ if (input[pos] !== ".") {
566
+ return null;
567
+ }
568
+ const match = input.slice(pos).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);
569
+ if (!match) {
570
+ return null;
571
+ }
572
+ const fullMatch = match[0].replace(/(\s|\.)$/, "");
573
+ const modifierName = fullMatch.slice(1).split("(")[0];
574
+ const value = match[1];
575
+ const token = createToken(
576
+ fullMatch,
577
+ "event-modifier",
578
+ createPosition(pos, pos + fullMatch.length)
579
+ );
580
+ return {
581
+ ...token,
582
+ metadata: {
583
+ modifierName,
584
+ value: value ? modifierName === "queue" ? value : parseInt(value, 10) : void 0
585
+ }
586
+ };
587
+ }
588
+ /**
589
+ * Try to extract a string literal at the current position.
590
+ */
591
+ tryString(input, pos) {
592
+ const literal = extractStringLiteral(input, pos);
593
+ if (literal) {
594
+ return createToken(literal, "literal", createPosition(pos, pos + literal.length));
595
+ }
596
+ return null;
597
+ }
598
+ /**
599
+ * Try to extract a number at the current position.
600
+ */
601
+ tryNumber(input, pos) {
602
+ const number = extractNumber(input, pos);
603
+ if (number) {
604
+ return createToken(number, "literal", createPosition(pos, pos + number.length));
605
+ }
606
+ return null;
607
+ }
608
+ /**
609
+ * Try to match a time unit from a list of patterns.
610
+ *
611
+ * @param input - Input string
612
+ * @param pos - Position after the number
613
+ * @param timeUnits - Array of time unit mappings (native pattern → standard suffix)
614
+ * @param skipWhitespace - Whether to skip whitespace before time unit (default: false)
615
+ * @returns Object with matched suffix and new position, or null if no match
616
+ */
617
+ tryMatchTimeUnit(input, pos, timeUnits, skipWhitespace = false) {
618
+ let unitPos = pos;
619
+ if (skipWhitespace) {
620
+ while (unitPos < input.length && isWhitespace(input[unitPos])) {
621
+ unitPos++;
622
+ }
623
+ }
624
+ const remaining = input.slice(unitPos);
625
+ for (const unit of timeUnits) {
626
+ const candidate = remaining.slice(0, unit.length);
627
+ const matches = unit.caseInsensitive ? candidate.toLowerCase() === unit.pattern.toLowerCase() : candidate === unit.pattern;
628
+ if (matches) {
629
+ if (unit.notFollowedBy) {
630
+ const nextChar = remaining[unit.length] || "";
631
+ if (nextChar === unit.notFollowedBy) continue;
632
+ }
633
+ if (unit.checkBoundary) {
634
+ const nextChar = remaining[unit.length] || "";
635
+ if (isAsciiIdentifierChar(nextChar)) continue;
636
+ }
637
+ return { suffix: unit.suffix, endPos: unitPos + unit.length };
638
+ }
639
+ }
640
+ return null;
641
+ }
642
+ /**
643
+ * Parse a base number (sign, integer, decimal) without time units.
644
+ * Returns the number string and end position.
645
+ *
646
+ * @param input - Input string
647
+ * @param startPos - Start position
648
+ * @param allowSign - Whether to allow +/- sign (default: true)
649
+ * @returns Object with number string and end position, or null
650
+ */
651
+ parseBaseNumber(input, startPos, allowSign = true) {
652
+ let pos = startPos;
653
+ let number = "";
654
+ if (allowSign && (input[pos] === "-" || input[pos] === "+")) {
655
+ number += input[pos++];
656
+ }
657
+ if (pos >= input.length || !isDigit(input[pos])) {
658
+ return null;
659
+ }
660
+ while (pos < input.length && isDigit(input[pos])) {
661
+ number += input[pos++];
662
+ }
663
+ if (pos < input.length && input[pos] === ".") {
664
+ number += input[pos++];
665
+ while (pos < input.length && isDigit(input[pos])) {
666
+ number += input[pos++];
667
+ }
668
+ }
669
+ if (!number || number === "-" || number === "+") return null;
670
+ return { number, endPos: pos };
671
+ }
672
+ /**
673
+ * Try to extract a number with native language time units.
674
+ *
675
+ * This is a template method that handles the common pattern:
676
+ * 1. Parse the base number (sign, integer, decimal)
677
+ * 2. Try to match native language time units
678
+ * 3. Fall back to standard time units (ms, s, m, h)
679
+ *
680
+ * @param input - Input string
681
+ * @param pos - Start position
682
+ * @param nativeTimeUnits - Language-specific time unit mappings
683
+ * @param options - Configuration options
684
+ * @returns Token if number found, null otherwise
685
+ */
686
+ tryNumberWithTimeUnits(input, pos, nativeTimeUnits, options = {}) {
687
+ const { allowSign = true, skipWhitespace = false } = options;
688
+ const baseResult = this.parseBaseNumber(input, pos, allowSign);
689
+ if (!baseResult) return null;
690
+ let { number, endPos } = baseResult;
691
+ const allUnits = [...nativeTimeUnits, ..._BaseTokenizer.STANDARD_TIME_UNITS];
692
+ const timeMatch = this.tryMatchTimeUnit(input, endPos, allUnits, skipWhitespace);
693
+ if (timeMatch) {
694
+ number += timeMatch.suffix;
695
+ endPos = timeMatch.endPos;
696
+ }
697
+ return createToken(number, "literal", createPosition(pos, endPos));
698
+ }
699
+ /**
700
+ * Try to extract a URL at the current position.
701
+ * Handles /path, ./path, ../path, //domain.com, http://, https://
702
+ */
703
+ tryUrl(input, pos) {
704
+ const url = extractUrl(input, pos);
705
+ if (url) {
706
+ return createToken(url, "url", createPosition(pos, pos + url.length));
707
+ }
708
+ return null;
709
+ }
710
+ /**
711
+ * Try to extract a variable reference (:varname) at the current position.
712
+ * In hyperscript, :x refers to a local variable named x.
713
+ */
714
+ tryVariableRef(input, pos) {
715
+ if (input[pos] !== ":") return null;
716
+ if (pos + 1 >= input.length) return null;
717
+ if (!isAsciiIdentifierChar(input[pos + 1])) return null;
718
+ let endPos = pos + 1;
719
+ while (endPos < input.length && isAsciiIdentifierChar(input[endPos])) {
720
+ endPos++;
721
+ }
722
+ const varRef = input.slice(pos, endPos);
723
+ return createToken(varRef, "identifier", createPosition(pos, endPos));
724
+ }
725
+ /**
726
+ * Try to extract an operator or punctuation token at the current position.
727
+ * Handles two-character operators (==, !=, etc.) and single-character operators.
728
+ */
729
+ tryOperator(input, pos) {
730
+ const twoChar = input.slice(pos, pos + 2);
731
+ if (["==", "!=", "<=", ">=", "&&", "||", "->"].includes(twoChar)) {
732
+ return createToken(twoChar, "operator", createPosition(pos, pos + 2));
733
+ }
734
+ const oneChar = input[pos];
735
+ if (["<", ">", "!", "+", "-", "*", "/", "="].includes(oneChar)) {
736
+ return createToken(oneChar, "operator", createPosition(pos, pos + 1));
737
+ }
738
+ if (["(", ")", "{", "}", ",", ";", ":"].includes(oneChar)) {
739
+ return createToken(oneChar, "punctuation", createPosition(pos, pos + 1));
740
+ }
741
+ return null;
742
+ }
743
+ /**
744
+ * Try to match a multi-character particle from a list.
745
+ *
746
+ * Used by languages like Japanese, Korean, and Chinese that have
747
+ * multi-character particles (e.g., Japanese から, まで, より).
748
+ *
749
+ * @param input - Input string
750
+ * @param pos - Current position
751
+ * @param particles - Array of multi-character particles to match
752
+ * @returns Token if matched, null otherwise
753
+ */
754
+ tryMultiCharParticle(input, pos, particles) {
755
+ for (const particle of particles) {
756
+ if (input.slice(pos, pos + particle.length) === particle) {
757
+ return createToken(particle, "particle", createPosition(pos, pos + particle.length));
758
+ }
759
+ }
760
+ return null;
761
+ }
762
+ };
763
+ /**
764
+ * Configuration for native language time units.
765
+ * Maps patterns to their standard suffix (ms, s, m, h).
766
+ */
767
+ _BaseTokenizer.STANDARD_TIME_UNITS = [
768
+ { pattern: "ms", suffix: "ms", length: 2 },
769
+ { pattern: "s", suffix: "s", length: 1, checkBoundary: true },
770
+ { pattern: "m", suffix: "m", length: 1, checkBoundary: true, notFollowedBy: "s" },
771
+ { pattern: "h", suffix: "h", length: 1, checkBoundary: true }
772
+ ];
773
+ var BaseTokenizer = _BaseTokenizer;
774
+
775
+ // src/generators/profiles/tl.ts
776
+ var tagalogProfile = {
777
+ code: "tl",
778
+ name: "Tagalog",
779
+ nativeName: "Tagalog",
780
+ direction: "ltr",
781
+ wordOrder: "VSO",
782
+ markingStrategy: "preposition",
783
+ usesSpaces: true,
784
+ defaultVerbForm: "base",
785
+ verb: {
786
+ position: "start",
787
+ subjectDrop: true
788
+ },
789
+ references: {
790
+ me: "ako",
791
+ // "I/me"
792
+ it: "ito",
793
+ // "it"
794
+ you: "ikaw",
795
+ // "you"
796
+ result: "resulta",
797
+ // "result"
798
+ event: "pangyayari",
799
+ // "event"
800
+ target: "target",
801
+ // "target"
802
+ body: "body"
803
+ },
804
+ possessive: {
805
+ marker: "ng",
806
+ // Linker used in possessive constructions
807
+ markerPosition: "between",
808
+ keywords: {
809
+ // Tagalog uses postposed possessive pronouns
810
+ // "my" - ko (clitic), akin (emphatic)
811
+ ko: "me",
812
+ akin: "me",
813
+ // "your" - mo (clitic), iyo (emphatic)
814
+ mo: "you",
815
+ iyo: "you",
816
+ // "its/his/her" - niya (clitic), kaniya (emphatic)
817
+ niya: "it",
818
+ kaniya: "it"
819
+ }
820
+ },
821
+ roleMarkers: {
822
+ destination: { primary: "sa", position: "before" },
823
+ // "to/into"
824
+ source: { primary: "mula_sa", position: "before" },
825
+ // "from"
826
+ patient: { primary: "", position: "before" },
827
+ style: { primary: "nang", position: "before" }
828
+ // manner marker
829
+ },
830
+ keywords: {
831
+ // Class/Attribute operations
832
+ toggle: { primary: "palitan", alternatives: ["itoggle"], normalized: "toggle" },
833
+ add: { primary: "idagdag", alternatives: ["magdagdag"], normalized: "add" },
834
+ remove: { primary: "alisin", alternatives: ["tanggalin"], normalized: "remove" },
835
+ // Content operations
836
+ put: { primary: "ilagay", alternatives: ["maglagay"], normalized: "put" },
837
+ append: { primary: "idagdag_sa_dulo", normalized: "append" },
838
+ prepend: { primary: "idagdag_sa_simula", normalized: "prepend" },
839
+ take: { primary: "kumuha", normalized: "take" },
840
+ make: { primary: "gumawa", alternatives: ["lumikha"], normalized: "make" },
841
+ clone: { primary: "kopyahin", normalized: "clone" },
842
+ swap: { primary: "magpalit", normalized: "swap" },
843
+ morph: { primary: "baguhin", normalized: "morph" },
844
+ // Variable operations
845
+ set: { primary: "itakda", alternatives: ["magtakda"], normalized: "set" },
846
+ get: { primary: "kumuha", alternatives: ["kunin"], normalized: "get" },
847
+ increment: { primary: "dagdagan", alternatives: ["taasan"], normalized: "increment" },
848
+ decrement: { primary: "bawasan", alternatives: ["ibaba"], normalized: "decrement" },
849
+ log: { primary: "itala", normalized: "log" },
850
+ // Visibility
851
+ show: { primary: "ipakita", alternatives: ["magpakita"], normalized: "show" },
852
+ hide: { primary: "itago", alternatives: ["magtago"], normalized: "hide" },
853
+ transition: { primary: "lumipat", normalized: "transition" },
854
+ // Events
855
+ on: { primary: "kapag", alternatives: ["kung", "sa"], normalized: "on" },
856
+ trigger: { primary: "magpatugtog", normalized: "trigger" },
857
+ send: { primary: "ipadala", alternatives: ["magpadala"], normalized: "send" },
858
+ // DOM focus
859
+ focus: { primary: "ituon", normalized: "focus" },
860
+ blur: { primary: "alisin_tuon", normalized: "blur" },
861
+ // Navigation
862
+ go: { primary: "pumunta", alternatives: ["punta"], normalized: "go" },
863
+ // Async
864
+ wait: { primary: "maghintay", alternatives: ["hintay"], normalized: "wait" },
865
+ fetch: { primary: "kunin", normalized: "fetch" },
866
+ settle: { primary: "magpatahimik", normalized: "settle" },
867
+ // Control flow
868
+ if: { primary: "kung", alternatives: ["kapag"], normalized: "if" },
869
+ when: { primary: "kapag", normalized: "when" },
870
+ where: { primary: "kung_saan", normalized: "where" },
871
+ else: { primary: "kung_hindi", alternatives: ["kundi"], normalized: "else" },
872
+ repeat: { primary: "ulitin", alternatives: ["paulit-ulit"], normalized: "repeat" },
873
+ for: { primary: "para_sa", normalized: "for" },
874
+ while: { primary: "habang", normalized: "while" },
875
+ continue: { primary: "magpatuloy", normalized: "continue" },
876
+ halt: { primary: "itigil", alternatives: ["huminto"], normalized: "halt" },
877
+ throw: { primary: "ihagis", alternatives: ["itapon"], normalized: "throw" },
878
+ call: { primary: "tawagan", alternatives: ["tumawag"], normalized: "call" },
879
+ return: { primary: "ibalik", alternatives: ["bumalik"], normalized: "return" },
880
+ then: { primary: "pagkatapos", alternatives: ["saka"], normalized: "then" },
881
+ and: { primary: "at", normalized: "and" },
882
+ end: { primary: "wakas", alternatives: ["tapos"], normalized: "end" },
883
+ // Advanced
884
+ js: { primary: "js", normalized: "js" },
885
+ async: { primary: "async", normalized: "async" },
886
+ tell: { primary: "sabihin", alternatives: ["magsabi"], normalized: "tell" },
887
+ default: { primary: "default", alternatives: ["unang_halaga"], normalized: "default" },
888
+ init: { primary: "simulan", alternatives: ["magsimula"], normalized: "init" },
889
+ behavior: { primary: "ugali", alternatives: ["kilos"], normalized: "behavior" },
890
+ install: { primary: "ikabit", alternatives: ["mag-install"], normalized: "install" },
891
+ measure: { primary: "sukatin", normalized: "measure" },
892
+ // Modifiers
893
+ into: { primary: "sa", normalized: "into" },
894
+ before: { primary: "bago", normalized: "before" },
895
+ after: { primary: "matapos", alternatives: ["pagkatapos"], normalized: "after" },
896
+ // Event modifiers
897
+ until: { primary: "hanggang", normalized: "until" },
898
+ event: { primary: "pangyayari", normalized: "event" },
899
+ from: { primary: "mula", alternatives: ["galing"], normalized: "from" }
900
+ },
901
+ eventHandler: {
902
+ keyword: { primary: "kapag", normalized: "on" },
903
+ sourceMarker: { primary: "mula_sa", alternatives: ["galing_sa"], position: "before" }
904
+ }
905
+ };
906
+
907
+ // src/tokenizers/tl.ts
908
+ var TAGALOG_EXTRAS = [
909
+ // Values/Literals
910
+ { native: "totoo", normalized: "true" },
911
+ { native: "mali", normalized: "false" },
912
+ { native: "wala", normalized: "null" },
913
+ { native: "hindi_tinukoy", normalized: "undefined" },
914
+ // Positional
915
+ { native: "una", normalized: "first" },
916
+ { native: "huli", normalized: "last" },
917
+ { native: "susunod", normalized: "next" },
918
+ { native: "nakaraan", normalized: "previous" },
919
+ { native: "pinakamalapit", normalized: "closest" },
920
+ { native: "magulang", normalized: "parent" },
921
+ // Events
922
+ { native: "pindot", normalized: "click" },
923
+ { native: "pagbabago", normalized: "change" },
924
+ { native: "isumite", normalized: "submit" },
925
+ { native: "input", normalized: "input" },
926
+ { native: "karga", normalized: "load" },
927
+ { native: "mag_scroll", normalized: "scroll" }
928
+ ];
929
+ var TagalogTokenizer = class extends BaseTokenizer {
930
+ constructor() {
931
+ super();
932
+ this.language = "tl";
933
+ this.direction = "ltr";
934
+ this.initializeKeywordsFromProfile(tagalogProfile, TAGALOG_EXTRAS);
935
+ }
936
+ tokenize(input) {
937
+ const tokens = [];
938
+ let pos = 0;
939
+ while (pos < input.length) {
940
+ if (isWhitespace(input[pos])) {
941
+ pos++;
942
+ continue;
943
+ }
944
+ if (isSelectorStart(input[pos])) {
945
+ const modifierToken = this.tryEventModifier(input, pos);
946
+ if (modifierToken) {
947
+ tokens.push(modifierToken);
948
+ pos = modifierToken.position.end;
949
+ continue;
950
+ }
951
+ const selectorToken = this.trySelector(input, pos);
952
+ if (selectorToken) {
953
+ tokens.push(selectorToken);
954
+ pos = selectorToken.position.end;
955
+ continue;
956
+ }
957
+ }
958
+ if (isQuote(input[pos])) {
959
+ const stringToken = this.tryString(input, pos);
960
+ if (stringToken) {
961
+ tokens.push(stringToken);
962
+ pos = stringToken.position.end;
963
+ continue;
964
+ }
965
+ }
966
+ if (isDigit(input[pos]) || input[pos] === "-" && pos + 1 < input.length && isDigit(input[pos + 1])) {
967
+ const numberToken = this.tryNumber(input, pos);
968
+ if (numberToken) {
969
+ tokens.push(numberToken);
970
+ pos = numberToken.position.end;
971
+ continue;
972
+ }
973
+ }
974
+ if (isUrlStart(input, pos)) {
975
+ const urlToken = this.tryUrl(input, pos);
976
+ if (urlToken) {
977
+ tokens.push(urlToken);
978
+ pos = urlToken.position.end;
979
+ continue;
980
+ }
981
+ }
982
+ if (input[pos] === ":") {
983
+ const varToken = this.tryVariableRef(input, pos);
984
+ if (varToken) {
985
+ tokens.push(varToken);
986
+ pos = varToken.position.end;
987
+ continue;
988
+ }
989
+ }
990
+ if ("()[]{}:,;".includes(input[pos])) {
991
+ tokens.push(createToken(input[pos], "operator", createPosition(pos, pos + 1)));
992
+ pos++;
993
+ continue;
994
+ }
995
+ if (isAsciiIdentifierChar(input[pos])) {
996
+ const startPos = pos;
997
+ const keywordToken = this.tryProfileKeyword(input, pos);
998
+ if (keywordToken) {
999
+ tokens.push(keywordToken);
1000
+ pos = keywordToken.position.end;
1001
+ continue;
1002
+ }
1003
+ let word = "";
1004
+ while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
1005
+ word += input[pos];
1006
+ pos++;
1007
+ }
1008
+ if (word) {
1009
+ tokens.push(createToken(word, "identifier", createPosition(startPos, pos)));
1010
+ }
1011
+ continue;
1012
+ }
1013
+ pos++;
1014
+ }
1015
+ return new TokenStreamImpl(tokens, "tl");
1016
+ }
1017
+ classifyToken(token) {
1018
+ if (this.isKeyword(token)) return "keyword";
1019
+ if (token.startsWith(".") || token.startsWith("#") || token.startsWith("[")) return "selector";
1020
+ if (token.startsWith(":")) return "identifier";
1021
+ if (token.startsWith('"') || token.startsWith("'")) return "literal";
1022
+ if (/^-?\d/.test(token)) return "literal";
1023
+ return "identifier";
1024
+ }
1025
+ };
1026
+ var tagalogTokenizer = new TagalogTokenizer();
1027
+
1028
+ // src/languages/tl.ts
1029
+ registerLanguage("tl", tagalogTokenizer, tagalogProfile);
1030
+ export {
1031
+ tagalogProfile,
1032
+ tagalogTokenizer
1033
+ };
1034
+ //# sourceMappingURL=tl.js.map