limn-hl 0.1.1 → 0.2.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 (73) hide show
  1. package/README.md +105 -174
  2. package/dist/detect.d.ts +7 -1
  3. package/dist/detect.js +592 -502
  4. package/dist/engine.js +45 -1
  5. package/dist/generated/detect.d.ts +11 -0
  6. package/dist/generated/detect.js +2434 -0
  7. package/dist/generated/grammars.d.ts +119 -0
  8. package/dist/generated/grammars.js +613 -0
  9. package/dist/generated/lang.d.ts +6 -0
  10. package/dist/{lang/index.js → generated/lang.js} +82 -56
  11. package/dist/{theme/generated.d.ts → generated/themes.d.ts} +1 -1
  12. package/dist/lang.d.ts +1 -0
  13. package/dist/lang.js +1 -0
  14. package/dist/render/ansi.d.ts +1 -1
  15. package/dist/render/html.d.ts +1 -1
  16. package/dist/{theme/index.d.ts → theme.d.ts} +1 -1
  17. package/dist/theme.js +1 -0
  18. package/dist/vm/compile.d.ts +4 -0
  19. package/dist/vm/compile.js +390 -0
  20. package/dist/vm/exec.d.ts +3 -0
  21. package/dist/vm/exec.js +218 -0
  22. package/dist/vm/format.d.ts +255 -0
  23. package/dist/vm/format.js +248 -0
  24. package/dist/vm/index.d.ts +2 -0
  25. package/dist/vm/index.js +2 -0
  26. package/dist/vm/pat.d.ts +4 -0
  27. package/dist/vm/pat.js +701 -0
  28. package/dist/vm/quoted.d.ts +8 -0
  29. package/dist/vm/quoted.js +190 -0
  30. package/dist/vm/scan.d.ts +3 -0
  31. package/dist/vm/scan.js +499 -0
  32. package/dist/wordtable.d.ts +8 -4
  33. package/dist/wordtable.js +107 -30
  34. package/package.json +6 -6
  35. package/dist/lang/clike.d.ts +0 -15
  36. package/dist/lang/clike.js +0 -35
  37. package/dist/lang/clike_helpers.d.ts +0 -8
  38. package/dist/lang/clike_helpers.js +0 -220
  39. package/dist/lang/code.d.ts +0 -45
  40. package/dist/lang/code.js +0 -779
  41. package/dist/lang/config.d.ts +0 -5
  42. package/dist/lang/config.js +0 -164
  43. package/dist/lang/css.d.ts +0 -5
  44. package/dist/lang/css.js +0 -125
  45. package/dist/lang/docs.d.ts +0 -12
  46. package/dist/lang/docs.js +0 -462
  47. package/dist/lang/formats.d.ts +0 -10
  48. package/dist/lang/formats.js +0 -295
  49. package/dist/lang/html.d.ts +0 -11
  50. package/dist/lang/html.js +0 -298
  51. package/dist/lang/index.d.ts +0 -20
  52. package/dist/lang/js.d.ts +0 -9
  53. package/dist/lang/js.js +0 -532
  54. package/dist/lang/js_helpers.d.ts +0 -7
  55. package/dist/lang/js_helpers.js +0 -308
  56. package/dist/lang/json.d.ts +0 -3
  57. package/dist/lang/json.js +0 -136
  58. package/dist/lang/markdown.d.ts +0 -3
  59. package/dist/lang/markdown.js +0 -249
  60. package/dist/lang/python.d.ts +0 -3
  61. package/dist/lang/python.js +0 -335
  62. package/dist/lang/scripting.d.ts +0 -7
  63. package/dist/lang/scripting.js +0 -216
  64. package/dist/lang/shell.d.ts +0 -7
  65. package/dist/lang/shell.js +0 -404
  66. package/dist/lang/specs_gen.d.ts +0 -66
  67. package/dist/lang/specs_gen.js +0 -381
  68. package/dist/lang/terminal.d.ts +0 -9
  69. package/dist/lang/terminal.js +0 -550
  70. package/dist/lang/yaml.d.ts +0 -4
  71. package/dist/lang/yaml.js +0 -176
  72. package/dist/theme/index.js +0 -1
  73. /package/dist/{theme/generated.js → generated/themes.js} +0 -0
@@ -1,295 +0,0 @@
1
- import { isDigit, isHexDigit, isIdentCont, isIdentStart } from "../cursor.js";
2
- import { Grammar } from "../engine.js";
3
- import { TokenKind } from "../token.js";
4
- import { onceGrammar } from "./code.js";
5
- function scanDiff(src, e) {
6
- const n = src.length;
7
- let pos = 0;
8
- while (pos < n && !e.stopped()) {
9
- const nl = src.indexOf(`
10
- `, pos);
11
- const end = nl >= 0 ? nl : n;
12
- if (src.startsWith("diff ", pos) || src.startsWith("index ", pos) || src.startsWith("--- ", pos) || src.startsWith("+++ ", pos)) {
13
- e.emit(pos, end, TokenKind.Section);
14
- } else if (src.startsWith("@@ ", pos)) {
15
- const at = src.indexOf(" @@", pos + 3);
16
- if (at >= 0 && at + 3 <= end) {
17
- const markerEnd = at + 3;
18
- e.emit(pos, markerEnd, TokenKind.Keyword);
19
- if (markerEnd < end)
20
- e.emit(markerEnd, end, TokenKind.Comment);
21
- } else {
22
- e.emit(pos, end, TokenKind.Keyword);
23
- }
24
- } else if (pos < end && src.charCodeAt(pos) === 43) {
25
- e.emit(pos, end, TokenKind.Inserted);
26
- } else if (pos < end && src.charCodeAt(pos) === 45) {
27
- e.emit(pos, end, TokenKind.Deleted);
28
- }
29
- if (nl < 0)
30
- break;
31
- pos = end + 1;
32
- }
33
- }
34
- function scanHTTP(src, e) {
35
- const n = src.length;
36
- let pos = 0;
37
- let firstLine = true;
38
- while (pos < n && !e.stopped()) {
39
- const nl = src.indexOf(`
40
- `, pos);
41
- const end = nl >= 0 ? nl : n;
42
- const lineEmpty = end === pos || end === pos + 1 && src.charCodeAt(pos) === 13;
43
- if (lineEmpty && !firstLine) {
44
- if (nl >= 0 && end + 1 < n) {
45
- const bodyStart = end + 1;
46
- const trimmed = src.slice(bodyStart).trim();
47
- if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
48
- e.embed(src, bodyStart, n, e.lookup("json"), TokenKind.Plain);
49
- } else if (trimmed.startsWith("<!DOCTYPE") || trimmed.startsWith("<html")) {
50
- e.embed(src, bodyStart, n, e.lookup("html"), TokenKind.Plain);
51
- } else if (trimmed.startsWith("<")) {
52
- e.embed(src, bodyStart, n, e.lookup("xml"), TokenKind.Plain);
53
- }
54
- }
55
- return;
56
- }
57
- if (firstLine) {
58
- firstLine = false;
59
- const sp = src.indexOf(" ", pos);
60
- if (sp > pos && sp < end) {
61
- e.emit(pos, sp, TokenKind.Keyword);
62
- const rest = sp + 1;
63
- const sp2 = src.indexOf(" ", rest);
64
- if (sp2 > rest && sp2 < end) {
65
- e.emit(rest, sp2, TokenKind.String);
66
- e.emit(sp2 + 1, end, TokenKind.Constant);
67
- } else if (rest < end) {
68
- e.emit(rest, end, TokenKind.String);
69
- }
70
- }
71
- } else {
72
- const colon = src.indexOf(":", pos);
73
- if (colon > pos && colon < end) {
74
- e.emit(pos, colon, TokenKind.Property);
75
- e.emit(colon, colon + 1, TokenKind.Operator);
76
- let v = colon + 1;
77
- while (v < end && (src.charCodeAt(v) === 32 || src.charCodeAt(v) === 9))
78
- v++;
79
- if (v < end)
80
- e.emit(v, end, TokenKind.String);
81
- }
82
- }
83
- if (nl < 0)
84
- break;
85
- pos = end + 1;
86
- }
87
- }
88
- function isASCIIAlpha(c) {
89
- return c >= 97 && c <= 122 || c >= 65 && c <= 90;
90
- }
91
- function skipUTF16Char(src, pos) {
92
- const c = src.charCodeAt(pos);
93
- if (c >= 55296 && c <= 56319 && pos + 1 < src.length && src.charCodeAt(pos + 1) >= 56320 && src.charCodeAt(pos + 1) <= 57343) {
94
- return pos + 2;
95
- }
96
- return pos + 1;
97
- }
98
- function scanDelimitedEnd(src, start, open, close) {
99
- const n = src.length;
100
- let j = start + 1;
101
- while (j < n) {
102
- const c = src.charCodeAt(j);
103
- if (c === close || c === 10 || c === open)
104
- break;
105
- j++;
106
- }
107
- return j > start + 1 && j < n && src.charCodeAt(j) === close ? j + 1 : 0;
108
- }
109
- function regexEscapeEnd(src, i) {
110
- const n = src.length;
111
- const next = src.charCodeAt(i + 1);
112
- if ((next === 112 || next === 80) && i + 2 < n && src.charCodeAt(i + 2) === 123) {
113
- const end = scanDelimitedEnd(src, i + 2, 123, 125);
114
- if (end > 0)
115
- return end;
116
- } else if (next === 107 && i + 2 < n && src.charCodeAt(i + 2) === 60) {
117
- const end = scanDelimitedEnd(src, i + 2, 60, 62);
118
- if (end > 0)
119
- return end;
120
- } else if (next === 117) {
121
- if (i + 2 < n && src.charCodeAt(i + 2) === 123) {
122
- let j = i + 3;
123
- while (j < n && isHexDigit(src.charCodeAt(j)))
124
- j++;
125
- if (j > i + 3 && j < n && src.charCodeAt(j) === 125)
126
- return j + 1;
127
- }
128
- if (i + 5 < n && isHexDigit(src.charCodeAt(i + 2)) && isHexDigit(src.charCodeAt(i + 3)) && isHexDigit(src.charCodeAt(i + 4)) && isHexDigit(src.charCodeAt(i + 5))) {
129
- return i + 6;
130
- }
131
- } else if (next === 120 && i + 3 < n && isHexDigit(src.charCodeAt(i + 2)) && isHexDigit(src.charCodeAt(i + 3))) {
132
- return i + 4;
133
- } else if (next === 99 && i + 2 < n && isASCIIAlpha(src.charCodeAt(i + 2))) {
134
- return i + 3;
135
- }
136
- return skipUTF16Char(src, i + 1);
137
- }
138
- function scanRegexGroupIntro(src, i, e) {
139
- const n = src.length;
140
- if (i >= n || src.charCodeAt(i) !== 63)
141
- return i;
142
- if (i + 2 < n && src.charCodeAt(i + 1) === 60 && (src.charCodeAt(i + 2) === 61 || src.charCodeAt(i + 2) === 33)) {
143
- e.emit(i, i + 3, TokenKind.Operator);
144
- return i + 3;
145
- }
146
- let nameStart = -1;
147
- if (i + 1 < n && src.charCodeAt(i + 1) === 60) {
148
- nameStart = i + 2;
149
- } else if (i + 2 < n && src.charCodeAt(i + 1) === 80 && src.charCodeAt(i + 2) === 60) {
150
- nameStart = i + 3;
151
- }
152
- if (nameStart >= 0 && nameStart < n && isIdentStart(src.charCodeAt(nameStart))) {
153
- let nameEnd = nameStart + 1;
154
- while (nameEnd < n && isIdentCont(src.charCodeAt(nameEnd)))
155
- nameEnd++;
156
- if (nameEnd < n && src.charCodeAt(nameEnd) === 62) {
157
- e.emit(i, nameStart, TokenKind.Operator);
158
- e.emit(nameStart, nameEnd, TokenKind.Variable);
159
- e.emit(nameEnd, nameEnd + 1, TokenKind.Operator);
160
- return nameEnd + 1;
161
- }
162
- }
163
- if (i + 1 < n) {
164
- const c1 = src.charCodeAt(i + 1);
165
- if (c1 === 58 || c1 === 61 || c1 === 33 || c1 === 62) {
166
- e.emit(i, i + 2, TokenKind.Operator);
167
- return i + 2;
168
- }
169
- }
170
- let j = i + 1;
171
- while (j < n && (isASCIIAlpha(src.charCodeAt(j)) || src.charCodeAt(j) === 45)) {
172
- j++;
173
- }
174
- if (j > i + 1 && j < n && (src.charCodeAt(j) === 58 || src.charCodeAt(j) === 41)) {
175
- e.emit(i, i + 1, TokenKind.Operator);
176
- e.emit(i + 1, j, TokenKind.Keyword);
177
- if (src.charCodeAt(j) === 58) {
178
- e.emit(j, j + 1, TokenKind.Operator);
179
- return j + 1;
180
- }
181
- return j;
182
- }
183
- return i;
184
- }
185
- function scanRegex(src, e) {
186
- const n = src.length;
187
- let i = 0;
188
- while (i < n && !e.stopped()) {
189
- const ch = src.charCodeAt(i);
190
- if (ch === 92) {
191
- if (i + 1 < n) {
192
- const end = regexEscapeEnd(src, i);
193
- e.emit(i, end, TokenKind.Escape);
194
- i = end;
195
- } else {
196
- i++;
197
- }
198
- } else if (ch === 91) {
199
- const s = i;
200
- i++;
201
- if (i < n && src.charCodeAt(i) === 94)
202
- i++;
203
- if (i < n && src.charCodeAt(i) === 93)
204
- i++;
205
- while (i < n && src.charCodeAt(i) !== 93) {
206
- if (src.charCodeAt(i) === 92 && i + 1 < n) {
207
- i = skipUTF16Char(src, i + 1);
208
- continue;
209
- }
210
- i++;
211
- }
212
- if (i < n && src.charCodeAt(i) === 93)
213
- i++;
214
- e.emit(s, i, TokenKind.Type);
215
- } else if (ch === 40) {
216
- e.emit(i, i + 1, TokenKind.Punctuation);
217
- i = scanRegexGroupIntro(src, i + 1, e);
218
- } else if (ch === 41 || ch === 124) {
219
- e.emit(i, i + 1, TokenKind.Punctuation);
220
- i++;
221
- } else if (ch === 42 || ch === 43 || ch === 63 || ch === 94 || ch === 36) {
222
- e.emit(i, i + 1, TokenKind.Operator);
223
- i++;
224
- } else if (ch === 123) {
225
- const s = i;
226
- i++;
227
- let hasDigit = false;
228
- while (i < n && (isDigit(src.charCodeAt(i)) || src.charCodeAt(i) === 44)) {
229
- if (isDigit(src.charCodeAt(i)))
230
- hasDigit = true;
231
- i++;
232
- }
233
- if (hasDigit && i < n && src.charCodeAt(i) === 125) {
234
- e.emit(s, i + 1, TokenKind.Operator);
235
- i++;
236
- }
237
- } else {
238
- i++;
239
- }
240
- }
241
- }
242
- export function trySlashRegex(src, pos, allowDoubleSlash, flags, e) {
243
- const n = src.length;
244
- let i = pos + 1;
245
- if (i >= n)
246
- return 0;
247
- const first = src.charCodeAt(i);
248
- if (first === 10)
249
- return 0;
250
- if (!allowDoubleSlash && (first === 47 || first === 42))
251
- return 0;
252
- let inClass = false;
253
- while (i < n) {
254
- const ch = src.charCodeAt(i);
255
- if (ch === 10)
256
- return 0;
257
- if (ch === 92) {
258
- if (i + 1 >= n)
259
- return 0;
260
- i = skipUTF16Char(src, i + 1);
261
- continue;
262
- }
263
- if (ch === 91) {
264
- inClass = true;
265
- i++;
266
- continue;
267
- }
268
- if (ch === 93) {
269
- inClass = false;
270
- i++;
271
- continue;
272
- }
273
- if (ch === 47 && !inClass) {
274
- const closeSlash = i;
275
- let end = closeSlash + 1;
276
- while (end < n && flags.includes(src[end]))
277
- end++;
278
- e.emit(pos, pos + 1, TokenKind.Punctuation);
279
- if (closeSlash > pos + 1) {
280
- e.embed(src, pos + 1, closeSlash, e.lookup("regex") ?? regex(), TokenKind.String);
281
- }
282
- e.emit(closeSlash, closeSlash + 1, TokenKind.Punctuation);
283
- if (end > closeSlash + 1) {
284
- e.emit(closeSlash + 1, end, TokenKind.Keyword);
285
- }
286
- return end;
287
- }
288
- i++;
289
- }
290
- return 0;
291
- }
292
- export const diff = /* @__PURE__ */ onceGrammar(() => new Grammar("diff", scanDiff, "patch"));
293
- export const http = /* @__PURE__ */ onceGrammar(() => new Grammar("http", scanHTTP));
294
- export const regex = /* @__PURE__ */ onceGrammar(() => new Grammar("regex", scanRegex, "regexp"));
295
- export const plain = /* @__PURE__ */ onceGrammar(() => new Grammar("plain", () => {}, "text", "txt"));
@@ -1,11 +0,0 @@
1
- import { Grammar } from "../engine.js";
2
- /** Returns the HTML grammar. */
3
- export declare const html: () => Grammar;
4
- /** Returns the XML / SVG / plist grammar. */
5
- export declare const xml: () => Grammar;
6
- /** Returns the Vue SFC grammar. */
7
- export declare const vue: () => Grammar;
8
- /** Returns the Svelte component grammar. */
9
- export declare const svelte: () => Grammar;
10
- /** Returns the Astro component grammar. */
11
- export declare const astro: () => Grammar;
package/dist/lang/html.js DELETED
@@ -1,298 +0,0 @@
1
- import { Cursor, emitCommentWithTodo, isIdentCont } from "../cursor.js";
2
- import { Grammar } from "../engine.js";
3
- import { TokenKind } from "../token.js";
4
- import { onceGrammar } from "./code.js";
5
- function hasFoldPrefix(s, pos, p) {
6
- if (s.length - pos < p.length)
7
- return false;
8
- for (let i = 0;i < p.length; i++) {
9
- let a = s.charCodeAt(pos + i);
10
- let b = p.charCodeAt(i);
11
- if (a >= 65 && a <= 90)
12
- a += 32;
13
- if (b >= 65 && b <= 90)
14
- b += 32;
15
- if (a !== b)
16
- return false;
17
- }
18
- return true;
19
- }
20
- function findClosingTagFold(src, start, closePrefix) {
21
- const limit = src.length - closePrefix.length;
22
- for (let i = start;i < limit; i++) {
23
- if (src.charCodeAt(i) === 60 && src.charCodeAt(i + 1) === 47 && hasFoldPrefix(src, i, closePrefix)) {
24
- const after = i + closePrefix.length;
25
- if (after < src.length) {
26
- const ch = src.charCodeAt(after);
27
- if (ch === 62 || ch === 32 || ch === 9 || ch === 10)
28
- return i;
29
- }
30
- }
31
- }
32
- return -1;
33
- }
34
- function isMarkupNameStart(c) {
35
- return c >= 97 && c <= 122 || c >= 65 && c <= 90 || c === 95;
36
- }
37
- function isMarkupNameCont(c) {
38
- return isMarkupNameStart(c) || c >= 48 && c <= 57 || c === 45 || c === 58 || c === 46;
39
- }
40
- function isAttrStop(c) {
41
- return c === 32 || c === 9 || c === 10 || c === 13 || c === 61 || c === 62 || c === 47 || c === 123;
42
- }
43
- function isDirectiveAttr(name) {
44
- if (name.startsWith("v-") || name.startsWith("on:") || name.startsWith("bind:") || name.startsWith("use:") || name.startsWith("class:") || name.startsWith("client:") || name.startsWith("set:") || name.startsWith("is:")) {
45
- return true;
46
- }
47
- const c0 = name.charCodeAt(0);
48
- return c0 === 58 || c0 === 64 || c0 === 35;
49
- }
50
- function scanHTMLTag(src, pos, cfg, e) {
51
- const n = src.length;
52
- if (pos + 1 >= n)
53
- return pos + 1;
54
- const cur = new Cursor(src, pos);
55
- const isClose = src.charCodeAt(pos + 1) === 47;
56
- if (isClose) {
57
- if (pos + 2 >= n || !isMarkupNameStart(src.charCodeAt(pos + 2)))
58
- return pos + 1;
59
- e.emit(pos, pos + 2, TokenKind.Punctuation);
60
- cur.pos += 2;
61
- } else {
62
- if (!isMarkupNameStart(src.charCodeAt(pos + 1)))
63
- return pos + 1;
64
- e.emit(pos, pos + 1, TokenKind.Punctuation);
65
- cur.pos++;
66
- }
67
- const tagStart = cur.pos;
68
- while (cur.pos < n && isMarkupNameCont(src.charCodeAt(cur.pos)))
69
- cur.pos++;
70
- const tagName = src.slice(tagStart, cur.pos);
71
- const tagC0 = tagName.charCodeAt(0);
72
- e.emit(tagStart, cur.pos, tagC0 >= 65 && tagC0 <= 90 ? TokenKind.Type : TokenKind.Keyword);
73
- let langAttr = "";
74
- let selfClosing = false;
75
- while (cur.pos < n) {
76
- cur.skipWhitespace();
77
- if (cur.eof())
78
- return cur.pos;
79
- if (cur.hasPrefix("/>")) {
80
- e.emit(cur.pos, cur.pos + 2, TokenKind.Punctuation);
81
- cur.pos += 2;
82
- selfClosing = true;
83
- break;
84
- }
85
- if (cur.peek() === 62) {
86
- e.emit(cur.pos, cur.pos + 1, TokenKind.Punctuation);
87
- cur.pos++;
88
- break;
89
- }
90
- if (cfg.braceExprJS && cur.peek() === 123) {
91
- const openPos = cur.pos;
92
- e.emit(openPos, openPos + 1, TokenKind.Punctuation);
93
- cur.pos++;
94
- const closed = cur.scanBalanced(123, 125, true);
95
- const exprEnd = closed ? cur.pos - 1 : cur.pos;
96
- e.embed(src, openPos + 1, exprEnd, e.lookup("js"), TokenKind.Plain);
97
- if (closed)
98
- e.emit(exprEnd, cur.pos, TokenKind.Punctuation);
99
- continue;
100
- }
101
- const attrStart = cur.pos;
102
- while (cur.pos < n && !isAttrStop(src.charCodeAt(cur.pos)))
103
- cur.pos++;
104
- if (cur.pos === attrStart) {
105
- cur.pos++;
106
- continue;
107
- }
108
- const attrName = src.slice(attrStart, cur.pos);
109
- e.emit(attrStart, cur.pos, cfg.directives && isDirectiveAttr(attrName) ? TokenKind.Keyword : TokenKind.Property);
110
- cur.skipWhitespace();
111
- if (cur.peek() !== 61)
112
- continue;
113
- e.emit(cur.pos, cur.pos + 1, TokenKind.Operator);
114
- cur.pos++;
115
- cur.skipWhitespace();
116
- const q = cur.peek();
117
- if (q === 34 || q === 39) {
118
- const vs = cur.pos;
119
- cur.scanQuoted(q, false, false);
120
- e.emit(vs, cur.pos, TokenKind.String);
121
- if (attrName.toLowerCase() === "lang" && cur.pos - vs >= 2) {
122
- langAttr = src.slice(vs + 1, cur.pos - 1).trim();
123
- }
124
- } else if (q === 123) {
125
- if (cfg.braceExprJS || cfg.directives) {
126
- const openPos = cur.pos;
127
- e.emit(openPos, openPos + 1, TokenKind.Punctuation);
128
- cur.pos++;
129
- const closed = cur.scanBalanced(123, 125, true);
130
- const exprEnd = closed ? cur.pos - 1 : cur.pos;
131
- e.embed(src, openPos + 1, exprEnd, e.lookup("js"), TokenKind.Plain);
132
- if (closed)
133
- e.emit(exprEnd, cur.pos, TokenKind.Punctuation);
134
- }
135
- } else {
136
- const vs = cur.pos;
137
- while (cur.pos < n) {
138
- const c = src.charCodeAt(cur.pos);
139
- if (c === 32 || c === 9 || c === 10 || c === 62)
140
- break;
141
- cur.pos++;
142
- }
143
- if (cur.pos > vs)
144
- e.emit(vs, cur.pos, TokenKind.String);
145
- }
146
- }
147
- if (cfg.htmlMode && !isClose && !selfClosing) {
148
- let closeTag = "";
149
- let subLang = "";
150
- const tagLower = tagName.toLowerCase();
151
- const attrLower = langAttr.toLowerCase();
152
- if (tagLower === "script") {
153
- closeTag = "</script";
154
- subLang = attrLower === "ts" || attrLower === "typescript" ? "ts" : "js";
155
- } else if (tagLower === "style") {
156
- closeTag = "</style";
157
- subLang = attrLower === "scss" || attrLower === "sass" || attrLower === "less" ? "scss" : "css";
158
- }
159
- if (closeTag !== "") {
160
- const sub = e.lookup(subLang);
161
- const bodyStart = cur.pos;
162
- const closeStart = findClosingTagFold(src, bodyStart, closeTag);
163
- if (closeStart >= bodyStart) {
164
- e.embed(src, bodyStart, closeStart, sub, TokenKind.Plain);
165
- return closeStart;
166
- }
167
- e.embed(src, bodyStart, n, sub, TokenKind.Plain);
168
- return n;
169
- }
170
- }
171
- return cur.pos;
172
- }
173
- function scanMarkup(src, cfg, e) {
174
- const n = src.length;
175
- let i = 0;
176
- if (cfg.frontmatter && src.startsWith("---") && (n === 3 || src.charCodeAt(3) === 10 || src.charCodeAt(3) === 13)) {
177
- e.emit(0, 3, TokenKind.Section);
178
- let bodyStart = 3;
179
- if (bodyStart < n && src.charCodeAt(bodyStart) === 13)
180
- bodyStart++;
181
- if (bodyStart < n && src.charCodeAt(bodyStart) === 10)
182
- bodyStart++;
183
- const closeIdx = src.indexOf(`
184
- ---`, bodyStart);
185
- if (closeIdx >= 0) {
186
- const bodyEnd = closeIdx + 1;
187
- e.embed(src, bodyStart, bodyEnd, e.lookup("ts"), TokenKind.Plain);
188
- e.emit(bodyEnd, bodyEnd + 3, TokenKind.Section);
189
- i = bodyEnd + 3;
190
- } else {
191
- e.embed(src, bodyStart, n, e.lookup("ts"), TokenKind.Plain);
192
- return;
193
- }
194
- }
195
- while (i < n && !e.stopped()) {
196
- const ch = src.charCodeAt(i);
197
- if (cfg.mustacheJS && ch === 123 && i + 1 < n && src.charCodeAt(i + 1) === 123) {
198
- e.emit(i, i + 2, TokenKind.Punctuation);
199
- const exprStart = i + 2;
200
- const closeIdx = src.indexOf("}}", exprStart);
201
- if (closeIdx >= 0) {
202
- e.embed(src, exprStart, closeIdx, e.lookup("js"), TokenKind.Plain);
203
- e.emit(closeIdx, closeIdx + 2, TokenKind.Punctuation);
204
- i = closeIdx + 2;
205
- continue;
206
- }
207
- const tagIdx = src.indexOf("</", exprStart);
208
- const exprEnd = tagIdx >= 0 ? tagIdx : n;
209
- e.embed(src, exprStart, exprEnd, e.lookup("js"), TokenKind.Plain);
210
- i = exprEnd;
211
- continue;
212
- } else if (cfg.braceExprJS && ch === 123) {
213
- const cur = new Cursor(src, i + 1);
214
- const closed = cur.scanBalanced(123, 125, true);
215
- const exprEnd = closed ? cur.pos - 1 : cur.pos;
216
- const b1 = i + 1 < exprEnd ? src.charCodeAt(i + 1) : 0;
217
- if (cfg.svelteBlocks && (b1 === 35 || b1 === 58 || b1 === 47 || b1 === 64)) {
218
- e.emit(i, i + 1, TokenKind.Punctuation);
219
- const kwStart = i + 1;
220
- let kwEnd = kwStart + 1;
221
- while (kwEnd < exprEnd && isIdentCont(src.charCodeAt(kwEnd)))
222
- kwEnd++;
223
- e.emit(kwStart, kwEnd, TokenKind.Keyword);
224
- e.embed(src, kwEnd, exprEnd, e.lookup("js"), TokenKind.Plain);
225
- if (closed)
226
- e.emit(exprEnd, cur.pos, TokenKind.Punctuation);
227
- } else {
228
- e.emit(i, i + 1, TokenKind.Punctuation);
229
- e.embed(src, i + 1, exprEnd, e.lookup("js"), TokenKind.Plain);
230
- if (closed)
231
- e.emit(exprEnd, cur.pos, TokenKind.Punctuation);
232
- }
233
- i = cur.pos;
234
- } else if (ch === 38) {
235
- let end = i + 1;
236
- while (end < n && end < i + 12) {
237
- const b = src.charCodeAt(end);
238
- if (isIdentCont(b) || b === 35)
239
- end++;
240
- else
241
- break;
242
- }
243
- if (end > i + 1 && end < n && src.charCodeAt(end) === 59) {
244
- e.emit(i, end + 1, TokenKind.Escape);
245
- i = end + 1;
246
- } else {
247
- i++;
248
- }
249
- } else if (ch === 60) {
250
- if (src.startsWith("<!--", i)) {
251
- const idx = src.indexOf("-->", i + 4);
252
- const end = idx >= 0 ? idx + 3 : n;
253
- emitCommentWithTodo(src, i, end, e);
254
- i = end;
255
- continue;
256
- }
257
- if (cfg.xmlMode && src.startsWith("<![CDATA[", i)) {
258
- e.emit(i, i + 9, TokenKind.Keyword);
259
- const idx = src.indexOf("]]>", i + 9);
260
- if (idx >= 0) {
261
- e.emit(idx, idx + 3, TokenKind.Keyword);
262
- i = idx + 3;
263
- } else {
264
- i = n;
265
- }
266
- continue;
267
- }
268
- if (src.startsWith("<!", i) || src.startsWith("<?", i)) {
269
- let end = i + 2;
270
- while (end < n && src.charCodeAt(end) !== 62)
271
- end++;
272
- if (end < n)
273
- end++;
274
- e.emit(i, end, TokenKind.Section);
275
- i = end;
276
- continue;
277
- }
278
- i = scanHTMLTag(src, i, cfg, e);
279
- } else {
280
- i++;
281
- }
282
- }
283
- }
284
- export const html = /* @__PURE__ */ onceGrammar(() => new Grammar("html", (src, e) => scanMarkup(src, { htmlMode: true }, e), "htm"));
285
- export const xml = /* @__PURE__ */ onceGrammar(() => new Grammar("xml", (src, e) => scanMarkup(src, { xmlMode: true }, e), "svg", "plist"));
286
- export const vue = /* @__PURE__ */ onceGrammar(() => new Grammar("vue", (src, e) => scanMarkup(src, { htmlMode: true, mustacheJS: true, directives: true }, e)));
287
- export const svelte = /* @__PURE__ */ onceGrammar(() => new Grammar("svelte", (src, e) => scanMarkup(src, {
288
- htmlMode: true,
289
- braceExprJS: true,
290
- svelteBlocks: true,
291
- directives: true
292
- }, e)));
293
- export const astro = /* @__PURE__ */ onceGrammar(() => new Grammar("astro", (src, e) => scanMarkup(src, {
294
- htmlMode: true,
295
- frontmatter: true,
296
- braceExprJS: true,
297
- directives: true
298
- }, e)));
@@ -1,20 +0,0 @@
1
- import { Registry } from "../engine.js";
2
- export { c, cpp, cs, glsl, php, rs, zig, } from "./clike.js";
3
- export { ini, toml } from "./config.js";
4
- export { css, scss } from "./css.js";
5
- export { mermaid, tex, typst } from "./docs.js";
6
- export { diff, http, plain, regex } from "./formats.js";
7
- export { astro, html, svelte, vue, xml, } from "./html.js";
8
- export { js, jsx, ts, tsx } from "./js.js";
9
- export { json } from "./json.js";
10
- export { md } from "./markdown.js";
11
- export { py } from "./python.js";
12
- export { lua, nix, rb } from "./scripting.js";
13
- export { bash, docker, make } from "./shell.js";
14
- export { cmake, dart, gleam, go, graphql, groovy, hcl, java, kt, nginx, prisma, proto, r, scala, solidity, sql, swift, wgsl, } from "./specs_gen.js";
15
- export { asm, bat, log, powershell } from "./terminal.js";
16
- export { yaml } from "./yaml.js";
17
- /** Returns an immutable Registry containing every built-in language and alias. */
18
- export declare function all(): Registry;
19
- /** Returns sorted canonical names of all built-in languages. */
20
- export declare function names(): string[];
package/dist/lang/js.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { Grammar } from "../engine.js";
2
- /** Returns the JavaScript grammar. */
3
- export declare const js: () => Grammar;
4
- /** Returns the TypeScript grammar. */
5
- export declare const ts: () => Grammar;
6
- /** Returns the JSX grammar. */
7
- export declare const jsx: () => Grammar;
8
- /** Returns the TSX grammar. */
9
- export declare const tsx: () => Grammar;