limn-hl 0.0.0 → 0.1.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 (62) hide show
  1. package/README.md +306 -0
  2. package/dist/cursor.d.ts +32 -0
  3. package/dist/cursor.js +322 -0
  4. package/dist/detect.d.ts +5 -0
  5. package/dist/detect.js +565 -0
  6. package/dist/engine.d.ts +78 -0
  7. package/dist/engine.js +268 -0
  8. package/dist/index.d.ts +3 -0
  9. package/dist/index.js +17 -0
  10. package/dist/lang/clike.d.ts +15 -0
  11. package/dist/lang/clike.js +35 -0
  12. package/dist/lang/clike_helpers.d.ts +8 -0
  13. package/dist/lang/clike_helpers.js +220 -0
  14. package/dist/lang/code.d.ts +45 -0
  15. package/dist/lang/code.js +779 -0
  16. package/dist/lang/config.d.ts +5 -0
  17. package/dist/lang/config.js +164 -0
  18. package/dist/lang/css.d.ts +5 -0
  19. package/dist/lang/css.js +125 -0
  20. package/dist/lang/docs.d.ts +12 -0
  21. package/dist/lang/docs.js +462 -0
  22. package/dist/lang/formats.d.ts +10 -0
  23. package/dist/lang/formats.js +295 -0
  24. package/dist/lang/html.d.ts +11 -0
  25. package/dist/lang/html.js +298 -0
  26. package/dist/lang/index.d.ts +20 -0
  27. package/dist/lang/index.js +167 -0
  28. package/dist/lang/js.d.ts +9 -0
  29. package/dist/lang/js.js +532 -0
  30. package/dist/lang/js_helpers.d.ts +7 -0
  31. package/dist/lang/js_helpers.js +308 -0
  32. package/dist/lang/json.d.ts +3 -0
  33. package/dist/lang/json.js +136 -0
  34. package/dist/lang/markdown.d.ts +3 -0
  35. package/dist/lang/markdown.js +249 -0
  36. package/dist/lang/python.d.ts +3 -0
  37. package/dist/lang/python.js +335 -0
  38. package/dist/lang/scripting.d.ts +7 -0
  39. package/dist/lang/scripting.js +216 -0
  40. package/dist/lang/shell.d.ts +7 -0
  41. package/dist/lang/shell.js +278 -0
  42. package/dist/lang/specs_gen.d.ts +66 -0
  43. package/dist/lang/specs_gen.js +381 -0
  44. package/dist/lang/terminal.d.ts +9 -0
  45. package/dist/lang/terminal.js +550 -0
  46. package/dist/lang/yaml.d.ts +4 -0
  47. package/dist/lang/yaml.js +176 -0
  48. package/dist/render/ansi.d.ts +7 -0
  49. package/dist/render/ansi.js +70 -0
  50. package/dist/render/html.d.ts +20 -0
  51. package/dist/render/html.js +212 -0
  52. package/dist/render/index.d.ts +2 -0
  53. package/dist/render/index.js +2 -0
  54. package/dist/theme/generated.d.ts +57 -0
  55. package/dist/theme/generated.js +736 -0
  56. package/dist/theme/index.d.ts +12 -0
  57. package/dist/theme/index.js +1 -0
  58. package/dist/token.d.ts +38 -0
  59. package/dist/token.js +67 -0
  60. package/dist/wordtable.d.ts +23 -0
  61. package/dist/wordtable.js +65 -0
  62. package/package.json +44 -9
package/dist/detect.js ADDED
@@ -0,0 +1,565 @@
1
+ const DETECT_MAX_BYTES = 4096;
2
+ function isIdentStart(c) {
3
+ return c >= 97 && c <= 122 || c >= 65 && c <= 90 || c === 95 || c >= 128;
4
+ }
5
+ function isIdentCont(c) {
6
+ return c >= 97 && c <= 122 || c >= 65 && c <= 90 || c >= 48 && c <= 57 || c === 95 || c >= 128;
7
+ }
8
+ function hasPrefixFold(s, prefix) {
9
+ if (s.length < prefix.length) {
10
+ return false;
11
+ }
12
+ for (let i = 0;i < prefix.length; i++) {
13
+ let a = s.charCodeAt(i);
14
+ let b = prefix.charCodeAt(i);
15
+ if (a >= 65 && a <= 90)
16
+ a += 32;
17
+ if (b >= 65 && b <= 90)
18
+ b += 32;
19
+ if (a !== b) {
20
+ return false;
21
+ }
22
+ }
23
+ return true;
24
+ }
25
+ const HTTP_METHODS = [
26
+ "GET ",
27
+ "POST ",
28
+ "PUT ",
29
+ "DELETE ",
30
+ "PATCH ",
31
+ "HEAD ",
32
+ "OPTIONS ",
33
+ "HTTP/"
34
+ ];
35
+ function startsWithHTTPMethod(s) {
36
+ for (const m of HTTP_METHODS) {
37
+ if (s.startsWith(m)) {
38
+ return true;
39
+ }
40
+ }
41
+ return false;
42
+ }
43
+ function isSimpleKey(s) {
44
+ if (s === "") {
45
+ return false;
46
+ }
47
+ for (let i = 0;i < s.length; i++) {
48
+ const ch = s.charCodeAt(i);
49
+ if (isIdentCont(ch) || ch === 45 || ch === 46) {
50
+ continue;
51
+ }
52
+ return false;
53
+ }
54
+ return true;
55
+ }
56
+ var L;
57
+ ((L) => {
58
+ L[L["Go"] = 0] = "Go";
59
+ L[L["JS"] = 1] = "JS";
60
+ L[L["TS"] = 2] = "TS";
61
+ L[L["JSX"] = 3] = "JSX";
62
+ L[L["TSX"] = 4] = "TSX";
63
+ L[L["Py"] = 5] = "Py";
64
+ L[L["Rs"] = 6] = "Rs";
65
+ L[L["C"] = 7] = "C";
66
+ L[L["CPP"] = 8] = "CPP";
67
+ L[L["CS"] = 9] = "CS";
68
+ L[L["Java"] = 10] = "Java";
69
+ L[L["Kt"] = 11] = "Kt";
70
+ L[L["Swift"] = 12] = "Swift";
71
+ L[L["Zig"] = 13] = "Zig";
72
+ L[L["Dart"] = 14] = "Dart";
73
+ L[L["PHP"] = 15] = "PHP";
74
+ L[L["SQL"] = 16] = "SQL";
75
+ L[L["Rb"] = 17] = "Rb";
76
+ L[L["Lua"] = 18] = "Lua";
77
+ L[L["Nix"] = 19] = "Nix";
78
+ L[L["JSON"] = 20] = "JSON";
79
+ L[L["YAML"] = 21] = "YAML";
80
+ L[L["TOML"] = 22] = "TOML";
81
+ L[L["INI"] = 23] = "INI";
82
+ L[L["HTML"] = 24] = "HTML";
83
+ L[L["XML"] = 25] = "XML";
84
+ L[L["CSS"] = 26] = "CSS";
85
+ L[L["SCSS"] = 27] = "SCSS";
86
+ L[L["Vue"] = 28] = "Vue";
87
+ L[L["Svelte"] = 29] = "Svelte";
88
+ L[L["Astro"] = 30] = "Astro";
89
+ L[L["MD"] = 31] = "MD";
90
+ L[L["Bash"] = 32] = "Bash";
91
+ L[L["Docker"] = 33] = "Docker";
92
+ L[L["Make"] = 34] = "Make";
93
+ L[L["Diff"] = 35] = "Diff";
94
+ L[L["Count"] = 36] = "Count";
95
+ })(L ||= {});
96
+ const NAMES = [
97
+ "go",
98
+ "js",
99
+ "ts",
100
+ "jsx",
101
+ "tsx",
102
+ "py",
103
+ "rs",
104
+ "c",
105
+ "cpp",
106
+ "cs",
107
+ "java",
108
+ "kt",
109
+ "swift",
110
+ "zig",
111
+ "dart",
112
+ "php",
113
+ "sql",
114
+ "rb",
115
+ "lua",
116
+ "nix",
117
+ "json",
118
+ "yaml",
119
+ "toml",
120
+ "ini",
121
+ "html",
122
+ "xml",
123
+ "css",
124
+ "scss",
125
+ "vue",
126
+ "svelte",
127
+ "astro",
128
+ "md",
129
+ "bash",
130
+ "docker",
131
+ "make",
132
+ "diff"
133
+ ];
134
+ export function detect(src) {
135
+ if (src.length > DETECT_MAX_BYTES) {
136
+ src = src.slice(0, DETECT_MAX_BYTES);
137
+ }
138
+ const trimmed = src.trim();
139
+ if (trimmed === "") {
140
+ return "plain";
141
+ }
142
+ if (trimmed.startsWith("#!")) {
143
+ const nl = trimmed.indexOf(`
144
+ `);
145
+ const shebang = nl >= 0 ? trimmed.slice(0, nl) : trimmed;
146
+ if (shebang.includes("bash") || shebang.includes("/sh") || shebang.includes("zsh")) {
147
+ return "bash";
148
+ }
149
+ if (shebang.includes("python"))
150
+ return "py";
151
+ if (shebang.includes("node") || shebang.includes("deno") || shebang.includes("bun")) {
152
+ return "js";
153
+ }
154
+ if (shebang.includes("ruby"))
155
+ return "rb";
156
+ if (shebang.includes("lua"))
157
+ return "lua";
158
+ if (shebang.includes("php"))
159
+ return "php";
160
+ }
161
+ if (trimmed.startsWith("<?php"))
162
+ return "php";
163
+ if (trimmed.startsWith("<?xml"))
164
+ return "xml";
165
+ if (hasPrefixFold(trimmed, "<!doctype html"))
166
+ return "html";
167
+ if (startsWithHTTPMethod(trimmed))
168
+ return "http";
169
+ if (trimmed.startsWith(`---
170
+ `) && trimmed.indexOf(`
171
+ ---`, 4) >= 0) {
172
+ if (trimmed.includes("client:") || trimmed.includes("set:html") || trimmed.includes("<")) {
173
+ return "astro";
174
+ }
175
+ }
176
+ const scores = new Int32Array(36 /* Count */);
177
+ if (trimmed.startsWith("{") && trimmed.endsWith("}") || trimmed.startsWith("[") && trimmed.endsWith("]")) {
178
+ scores[20 /* JSON */] += 25;
179
+ }
180
+ const n = src.length;
181
+ let i = 0;
182
+ let atLineStart = true;
183
+ let hasJSXTag = false;
184
+ while (i < n) {
185
+ if (atLineStart) {
186
+ const lineStartPos = i;
187
+ while (i < n && (src.charCodeAt(i) === 32 || src.charCodeAt(i) === 9)) {
188
+ i++;
189
+ }
190
+ if (i >= n)
191
+ break;
192
+ atLineStart = false;
193
+ const ch = src.charCodeAt(i);
194
+ if (ch === 35) {
195
+ if (src.startsWith("# ", i) || src.startsWith("## ", i) || src.startsWith("### ", i)) {
196
+ scores[31 /* MD */] += 35;
197
+ } else if (src.startsWith("#include ", i)) {
198
+ scores[7 /* C */] += 80;
199
+ scores[8 /* CPP */] += 80;
200
+ }
201
+ } else if (ch === 96) {
202
+ if (src.startsWith("```", i)) {
203
+ scores[31 /* MD */] += 50;
204
+ }
205
+ } else if (ch === 64) {
206
+ if (src.startsWith("@import ", i) || src.startsWith("@media ", i) || src.startsWith("@layer ", i)) {
207
+ scores[26 /* CSS */] += 45;
208
+ scores[27 /* SCSS */] += 45;
209
+ } else if (src.startsWith("@mixin ", i) || src.startsWith("@include ", i) || src.startsWith("@use ", i)) {
210
+ scores[27 /* SCSS */] += 90;
211
+ } else if (src.startsWith("@@ ", i)) {
212
+ scores[35 /* Diff */] += 150;
213
+ }
214
+ } else if (ch === 46) {
215
+ if (src.startsWith(".PHONY:", i)) {
216
+ scores[34 /* Make */] += 120;
217
+ }
218
+ } else if (ch === 43 || ch === 45) {
219
+ if (i === lineStartPos && i + 1 < n && src.charCodeAt(i + 1) !== ch) {
220
+ scores[35 /* Diff */] += 6;
221
+ }
222
+ } else if (ch === 36) {
223
+ scores[27 /* SCSS */] += 35;
224
+ } else if (ch === 91) {
225
+ const nl = src.indexOf(`
226
+ `, i);
227
+ const tl = (nl >= 0 ? src.slice(i, nl) : src.slice(i)).trim();
228
+ if (tl.length > 2 && tl.endsWith("]") && !tl.includes(",") && !tl.includes('"') && !tl.includes("'")) {
229
+ scores[22 /* TOML */] += 25;
230
+ scores[23 /* INI */] += 25;
231
+ }
232
+ } else if (ch === 70 || ch === 82 || ch === 69 || ch === 87) {
233
+ if (src.startsWith("FROM ", i) || src.startsWith("RUN ", i) || src.startsWith("ENTRYPOINT ", i) || src.startsWith("WORKDIR ", i)) {
234
+ scores[33 /* Docker */] += 120;
235
+ }
236
+ } else if (ch === 100) {
237
+ if (src.startsWith("diff --git ", i)) {
238
+ scores[35 /* Diff */] += 150;
239
+ }
240
+ } else if (ch === 105) {
241
+ if (src.startsWith("ifneq ", i) || src.startsWith("ifeq ", i)) {
242
+ scores[34 /* Make */] += 120;
243
+ } else if (src.startsWith("import java.", i) || src.startsWith("import javax.", i)) {
244
+ scores[10 /* Java */] += 200;
245
+ } else if (src.startsWith("import 'package:", i)) {
246
+ scores[14 /* Dart */] += 150;
247
+ }
248
+ } else if (ch === 112) {
249
+ if (src.startsWith("package ", i)) {
250
+ scores[0 /* Go */] += 70;
251
+ scores[10 /* Java */] += 40;
252
+ scores[11 /* Kt */] += 40;
253
+ }
254
+ } else if (ch === 117) {
255
+ if (src.startsWith("using System", i)) {
256
+ scores[9 /* CS */] += 180;
257
+ }
258
+ }
259
+ const nl = src.indexOf(`
260
+ `, i);
261
+ const line = nl >= 0 ? src.slice(i, nl) : src.slice(i);
262
+ const colon = line.indexOf(":");
263
+ if (colon > 0 && isSimpleKey(line.slice(0, colon))) {
264
+ if (colon + 1 === line.length || line.charCodeAt(colon + 1) === 32) {
265
+ scores[21 /* YAML */] += 14;
266
+ }
267
+ }
268
+ const eq = line.indexOf("=");
269
+ if (eq > 0 && isSimpleKey(line.slice(0, eq).trim())) {
270
+ if (line.includes('"') || line.includes("'") || line.includes("[")) {
271
+ scores[22 /* TOML */] += 8;
272
+ } else {
273
+ scores[23 /* INI */] += 8;
274
+ }
275
+ }
276
+ if (line.includes('":')) {
277
+ scores[20 /* JSON */] += 8;
278
+ }
279
+ if (line.includes(";") && line.includes("=") && !line.includes("{")) {
280
+ scores[19 /* Nix */] += 8;
281
+ }
282
+ }
283
+ const ch = src.charCodeAt(i);
284
+ if (ch === 10) {
285
+ atLineStart = true;
286
+ i++;
287
+ continue;
288
+ }
289
+ if (isIdentStart(ch)) {
290
+ const start = i;
291
+ i++;
292
+ while (i < n && isIdentCont(src.charCodeAt(i))) {
293
+ i++;
294
+ }
295
+ const w = src.slice(start, i);
296
+ switch (w) {
297
+ case "func":
298
+ scores[0 /* Go */] += 45;
299
+ scores[12 /* Swift */] += 45;
300
+ break;
301
+ case "fmt":
302
+ if (i < n && src.charCodeAt(i) === 46)
303
+ scores[0 /* Go */] += 80;
304
+ break;
305
+ case "chan":
306
+ case "defer":
307
+ case "fallthrough":
308
+ case "go":
309
+ scores[0 /* Go */] += 40;
310
+ break;
311
+ case "const":
312
+ case "let":
313
+ case "async":
314
+ case "await":
315
+ case "export":
316
+ case "import":
317
+ scores[1 /* JS */] += 10;
318
+ scores[2 /* TS */] += 10;
319
+ break;
320
+ case "function":
321
+ case "typeof":
322
+ case "undefined":
323
+ scores[1 /* JS */] += 25;
324
+ scores[2 /* TS */] += 20;
325
+ break;
326
+ case "console":
327
+ if (src.startsWith(".log", i)) {
328
+ scores[1 /* JS */] += 40;
329
+ scores[2 /* TS */] += 30;
330
+ }
331
+ break;
332
+ case "document":
333
+ if (i < n && src.charCodeAt(i) === 46)
334
+ scores[1 /* JS */] += 25;
335
+ break;
336
+ case "interface":
337
+ scores[2 /* TS */] += 45;
338
+ scores[4 /* TSX */] += 35;
339
+ break;
340
+ case "satisfies":
341
+ scores[2 /* TS */] += 60;
342
+ break;
343
+ case "className":
344
+ if (i < n && src.charCodeAt(i) === 61) {
345
+ scores[3 /* JSX */] += 60;
346
+ scores[4 /* TSX */] += 65;
347
+ }
348
+ break;
349
+ case "def":
350
+ case "None":
351
+ case "True":
352
+ case "False":
353
+ scores[5 /* Py */] += 25;
354
+ break;
355
+ case "__init__":
356
+ scores[5 /* Py */] += 100;
357
+ break;
358
+ case "elif":
359
+ scores[5 /* Py */] += 30;
360
+ scores[32 /* Bash */] += 30;
361
+ break;
362
+ case "self":
363
+ if (i < n && src.charCodeAt(i) === 46)
364
+ scores[5 /* Py */] += 35;
365
+ break;
366
+ case "mut":
367
+ case "pub":
368
+ case "crate":
369
+ case "match":
370
+ scores[6 /* Rs */] += 30;
371
+ break;
372
+ case "println":
373
+ if (i < n && src.charCodeAt(i) === 33)
374
+ scores[6 /* Rs */] += 90;
375
+ break;
376
+ case "impl":
377
+ scores[6 /* Rs */] += 45;
378
+ break;
379
+ case "std":
380
+ if (src.startsWith("::", i))
381
+ scores[8 /* CPP */] += 90;
382
+ break;
383
+ case "iostream":
384
+ case "vector":
385
+ scores[8 /* CPP */] += 80;
386
+ break;
387
+ case "template":
388
+ if (i < n && src.charCodeAt(i) === 60)
389
+ scores[8 /* CPP */] += 70;
390
+ break;
391
+ case "nullptr":
392
+ scores[8 /* CPP */] += 60;
393
+ break;
394
+ case "Console":
395
+ if (i < n && src.charCodeAt(i) === 46)
396
+ scores[9 /* CS */] += 90;
397
+ break;
398
+ case "System":
399
+ if (src.startsWith(".out.", i))
400
+ scores[10 /* Java */] += 100;
401
+ break;
402
+ case "main":
403
+ if (start >= 19 && src.startsWith("public static void ", start - 19)) {
404
+ scores[10 /* Java */] += 150;
405
+ }
406
+ break;
407
+ case "companion":
408
+ if (src.startsWith(" object", i))
409
+ scores[11 /* Kt */] += 120;
410
+ break;
411
+ case "fun":
412
+ scores[11 /* Kt */] += 40;
413
+ break;
414
+ case "val":
415
+ case "when":
416
+ case "object":
417
+ scores[11 /* Kt */] += 25;
418
+ break;
419
+ case "guard":
420
+ if (src.startsWith(" let ", i))
421
+ scores[12 /* Swift */] += 120;
422
+ break;
423
+ case "comptime":
424
+ scores[13 /* Zig */] += 120;
425
+ break;
426
+ case "orelse":
427
+ scores[13 /* Zig */] += 80;
428
+ break;
429
+ case "BuildContext":
430
+ scores[14 /* Dart */] += 120;
431
+ break;
432
+ case "Widget":
433
+ scores[14 /* Dart */] += 90;
434
+ break;
435
+ case "SELECT":
436
+ case "select":
437
+ scores[16 /* SQL */] += 60;
438
+ break;
439
+ case "FROM":
440
+ case "WHERE":
441
+ scores[16 /* SQL */] += 40;
442
+ break;
443
+ case "pkgs":
444
+ scores[19 /* Nix */] += 80;
445
+ break;
446
+ case "mkDerivation":
447
+ scores[19 /* Nix */] += 150;
448
+ break;
449
+ case "nixpkgs":
450
+ scores[19 /* Nix */] += 90;
451
+ break;
452
+ case "local":
453
+ scores[18 /* Lua */] += 35;
454
+ break;
455
+ case "elseif":
456
+ scores[18 /* Lua */] += 60;
457
+ break;
458
+ case "attr_accessor":
459
+ scores[17 /* Rb */] += 120;
460
+ break;
461
+ case "end":
462
+ if (i < n && src.charCodeAt(i) === 10)
463
+ scores[17 /* Rb */] += 25;
464
+ break;
465
+ case "echo":
466
+ scores[32 /* Bash */] += 25;
467
+ break;
468
+ case "then":
469
+ case "fi":
470
+ case "done":
471
+ scores[32 /* Bash */] += 30;
472
+ break;
473
+ case "esac":
474
+ scores[32 /* Bash */] += 80;
475
+ break;
476
+ case "struct":
477
+ case "enum":
478
+ scores[6 /* Rs */] += 10;
479
+ scores[0 /* Go */] += 10;
480
+ scores[13 /* Zig */] += 15;
481
+ scores[12 /* Swift */] += 10;
482
+ break;
483
+ case "nil":
484
+ scores[0 /* Go */] += 15;
485
+ scores[18 /* Lua */] += 15;
486
+ scores[17 /* Rb */] += 15;
487
+ scores[12 /* Swift */] += 15;
488
+ break;
489
+ case "xmlns":
490
+ if (i < n && src.charCodeAt(i) === 61)
491
+ scores[25 /* XML */] += 70;
492
+ break;
493
+ }
494
+ continue;
495
+ }
496
+ if (ch === 58) {
497
+ if (i + 1 < n && src.charCodeAt(i + 1) === 61) {
498
+ scores[0 /* Go */] += 40;
499
+ i += 2;
500
+ continue;
501
+ }
502
+ if (src.startsWith(": string", i) || src.startsWith(": number", i) || src.startsWith(": boolean", i)) {
503
+ scores[2 /* TS */] += 40;
504
+ scores[4 /* TSX */] += 30;
505
+ }
506
+ } else if (ch === 47) {
507
+ if (i + 1 < n && src.charCodeAt(i + 1) === 62) {
508
+ hasJSXTag = true;
509
+ i += 2;
510
+ continue;
511
+ }
512
+ } else if (ch === 60) {
513
+ if (src.startsWith("<template>", i)) {
514
+ scores[28 /* Vue */] += 120;
515
+ } else if (src.startsWith("<script setup", i)) {
516
+ scores[28 /* Vue */] += 150;
517
+ } else if (src.startsWith("<html", i)) {
518
+ scores[24 /* HTML */] += 80;
519
+ } else if (src.startsWith("<div", i) || src.startsWith("<span", i)) {
520
+ scores[24 /* HTML */] += 35;
521
+ } else if (src.startsWith("<svg", i)) {
522
+ scores[25 /* XML */] += 70;
523
+ }
524
+ } else if (ch === 123) {
525
+ if (src.startsWith("{#if ", i) || src.startsWith("{#each ", i)) {
526
+ scores[29 /* Svelte */] += 140;
527
+ }
528
+ } else if (ch === 64) {
529
+ if (src.startsWith("@import(", i)) {
530
+ scores[13 /* Zig */] += 120;
531
+ } else if (src.startsWith("@State ", i)) {
532
+ scores[12 /* Swift */] += 80;
533
+ }
534
+ } else if (ch === 38) {
535
+ if (src.startsWith("&mut ", i)) {
536
+ scores[6 /* Rs */] += 70;
537
+ }
538
+ } else if (ch === 118) {
539
+ if (src.startsWith("v-for=", i) || src.startsWith("v-if=", i)) {
540
+ scores[28 /* Vue */] += 90;
541
+ }
542
+ } else if (ch === 111) {
543
+ if (src.startsWith("on:click", i)) {
544
+ scores[29 /* Svelte */] += 90;
545
+ }
546
+ }
547
+ i++;
548
+ }
549
+ if ((scores[1 /* JS */] > 0 || scores[2 /* TS */] > 0) && hasJSXTag) {
550
+ if (scores[2 /* TS */] > scores[1 /* JS */]) {
551
+ scores[4 /* TSX */] += scores[2 /* TS */] + 30;
552
+ } else {
553
+ scores[3 /* JSX */] += scores[1 /* JS */] + 30;
554
+ }
555
+ }
556
+ let bestIdx = -1;
557
+ let bestScore = 24;
558
+ for (let idx = 0;idx < scores.length; idx++) {
559
+ if (scores[idx] > bestScore) {
560
+ bestScore = scores[idx];
561
+ bestIdx = idx;
562
+ }
563
+ }
564
+ return bestIdx < 0 ? "plain" : NAMES[bestIdx];
565
+ }
@@ -0,0 +1,78 @@
1
+ import { type Token, TokenKind } from "./token.js";
2
+ /** Tokenizes src by calling e.emit for recognized spans. */
3
+ export type ScanFunc = (src: string, e: Emitter) => void;
4
+ /** Immutable language definition pairing a canonical name, aliases, and scanner function. */
5
+ export declare class Grammar {
6
+ readonly name: string;
7
+ readonly aliases: readonly string[];
8
+ /** @internal */
9
+ readonly scan: ScanFunc;
10
+ constructor(name: string, scan: ScanFunc, ...aliases: readonly string[]);
11
+ }
12
+ /** Immutable lookup table of Grammars by canonical name and alias. */
13
+ export declare class Registry {
14
+ private readonly byName;
15
+ private readonly grammars;
16
+ constructor(grammars?: Iterable<Grammar>);
17
+ /** Returns a new Registry containing all grammars from this plus extra (overriding on conflict). */
18
+ with(extra: Iterable<Grammar>): Registry;
19
+ /** Looks up a Grammar by canonical name or alias (ASCII case-insensitive). */
20
+ lookup(name: string): Grammar | undefined;
21
+ /** Returns sorted canonical grammar names in the Registry. */
22
+ names(): string[];
23
+ /** Streams tokens for the named language, falling back to Plain if unknown. */
24
+ eachToken(src: string, lang: string, fn: (tok: Token) => void): void;
25
+ /** Streams tokens while fn returns true for the named language. */
26
+ eachTokenWhile(src: string, lang: string, fn: (tok: Token) => boolean): void;
27
+ /** Appends tokens for the named language onto dst. */
28
+ tokenizeInto(dst: Token[], src: string, lang: string): Token[];
29
+ /** Tokenizes src for the named language. */
30
+ tokenize(src: string, lang: string): Token[];
31
+ }
32
+ declare class Sink {
33
+ readonly reg: Registry | undefined;
34
+ readonly srcLen: number;
35
+ lastEnd: number;
36
+ depth: number;
37
+ defaultKind: TokenKind;
38
+ hasPending: boolean;
39
+ pendingStart: number;
40
+ pendingEnd: number;
41
+ pendingKind: TokenKind;
42
+ stop: boolean;
43
+ private readonly dst;
44
+ private readonly fnEach;
45
+ private readonly fnWhile;
46
+ constructor(reg: Registry | undefined, srcLen: number, dst: Token[] | undefined, fnEach: ((tok: Token) => void) | undefined, fnWhile: ((tok: Token) => boolean) | undefined);
47
+ emitBound(base: number, limit: number, start: number, end: number, kind: TokenKind): void;
48
+ emitRaw(start: number, end: number, kind: TokenKind): void;
49
+ fillGap(upTo: number): void;
50
+ pushToken(start: number, end: number, kind: TokenKind): void;
51
+ private flushPending;
52
+ finish(): void;
53
+ }
54
+ /** Receives non-overlapping tokens from a scanner and forwards them to the engine. */
55
+ export declare class Emitter {
56
+ private readonly s;
57
+ private readonly base;
58
+ private readonly limit;
59
+ /** @internal */
60
+ constructor(s: Sink, base: number, limit: number);
61
+ /** Reports whether the consumer requested early termination (from eachTokenWhile). */
62
+ stopped(): boolean;
63
+ /** Emits a token for range [start, end) relative to the current scanner slice. */
64
+ emit(start: number, end: number, kind: TokenKind): void;
65
+ /** Looks up a Grammar by canonical name or alias in the active Registry. */
66
+ lookup(name: string): Grammar | undefined;
67
+ /** Delegates src.slice(start, end) to grammar with fallbackKind for unmatched gaps or fallback. */
68
+ embed(src: string, start: number, end: number, grammar: Grammar | undefined, fallbackKind: TokenKind): void;
69
+ }
70
+ /** Streams tokens for src using grammar (and reg for embedded sub-languages). */
71
+ export declare function eachToken(src: string, grammar: Grammar | undefined, reg: Registry | undefined, fn: (tok: Token) => void): void;
72
+ /** Streams tokens while fn returns true, stopping early on false. */
73
+ export declare function eachTokenWhile(src: string, grammar: Grammar | undefined, reg: Registry | undefined, fn: (tok: Token) => boolean): void;
74
+ /** Appends tokens for src onto dst and returns dst. */
75
+ export declare function tokenizeInto(dst: Token[], src: string, grammar: Grammar | undefined, reg: Registry | undefined): Token[];
76
+ /** Tokenizes src into a newly allocated array of tokens. */
77
+ export declare function tokenize(src: string, grammar: Grammar | undefined, reg: Registry | undefined): Token[];
78
+ export {};