token-goat 2.9.13 → 2.9.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/dist/token-goat-chunk-2ESBO4IN.mjs +209 -0
- package/dist/token-goat-chunk-3BTK54F3.mjs +1733 -0
- package/dist/{token-goat-chunk-2WC4ZUXN.mjs → token-goat-chunk-3XQPEJMV.mjs} +1 -1
- package/dist/token-goat-chunk-4SDX3QP3.mjs +122 -0
- package/dist/token-goat-chunk-7OGKZ7AP.mjs +142 -0
- package/dist/token-goat-chunk-AH6QILZM.mjs +26 -0
- package/dist/token-goat-chunk-AMYCQJX4.mjs +1548 -0
- package/dist/{token-goat-chunk-6B44WLIF.mjs → token-goat-chunk-ASVVF4JV.mjs} +10 -7
- package/dist/{token-goat-chunk-3ESRORNM.mjs → token-goat-chunk-DAMXYVIW.mjs} +12026 -11796
- package/dist/{token-goat-chunk-YOA4N6WA.mjs → token-goat-chunk-DBNY4RLN.mjs} +2 -2
- package/dist/token-goat-chunk-EG3663UT.mjs +226 -0
- package/dist/token-goat-chunk-EZNVAIR3.mjs +21 -0
- package/dist/token-goat-chunk-GMOUBOX4.mjs +386 -0
- package/dist/{token-goat-chunk-B3CTCQTH.mjs → token-goat-chunk-HF6H7RNK.mjs} +1 -1
- package/dist/{token-goat-chunk-ZZI3IDQZ.mjs → token-goat-chunk-IT6O3PNN.mjs} +2874 -7088
- package/dist/token-goat-chunk-NEI4NC54.mjs +424 -0
- package/dist/token-goat-chunk-O5WAMISC.mjs +167 -0
- package/dist/{token-goat-chunk-RDITECDL.mjs → token-goat-chunk-PGGDW7DZ.mjs} +28 -13
- package/dist/token-goat-chunk-POBYR64E.mjs +1632 -0
- package/dist/{token-goat-chunk-4NXUKV7D.mjs → token-goat-chunk-PRJVGIC5.mjs} +6 -4
- package/dist/{token-goat-chunk-U7X6LQD2.mjs → token-goat-chunk-RUDOKYPJ.mjs} +10160 -10053
- package/dist/token-goat-chunk-SAQ5PG4L.mjs +2634 -0
- package/dist/{token-goat-chunk-UMXJN7DI.mjs → token-goat-chunk-T2IWWTHB.mjs} +288 -2654
- package/dist/{token-goat-chunk-JOXLE672.mjs → token-goat-chunk-VZYD4OZB.mjs} +1164 -92
- package/dist/token-goat-chunk-XEH6KBWW.mjs +23 -0
- package/dist/token-goat-chunk-XQF5J25J.mjs +33 -0
- package/dist/token-goat-chunk-XTQAOTSO.mjs +89 -0
- package/dist/{token-goat-chunk-QWSUZWFP.mjs → token-goat-chunk-XVZ4MNQC.mjs} +587 -587
- package/dist/token-goat-chunk-Y4AFKTHK.mjs +22 -0
- package/dist/token-goat-chunk-YHGTGG6K.mjs +396 -0
- package/dist/{token-goat-chunk-FZU7GMUS.mjs → token-goat-chunk-YTQHZJXW.mjs} +20 -11
- package/dist/token-goat-chunk-Z6UXPYJA.mjs +62 -0
- package/dist/token-goat-chunk-ZD4EM4LR.mjs +30 -0
- package/dist/token-goat-chunk-ZFM4PWXL.mjs +585 -0
- package/dist/{token-goat-chunk-FQCNJV4V.mjs → token-goat-chunk-ZYNNQ36L.mjs} +116 -330
- package/dist/token-goat-hook.mjs +12 -8
- package/dist/token-goat.core.mjs +22 -10
- package/docs/cli.md +1 -0
- package/package.json +4 -2
- package/dist/token-goat-chunk-JVNPCQB7.mjs +0 -31
- package/dist/token-goat-chunk-P2PU4CR5.mjs +0 -26
- package/dist/token-goat-chunk-QKXBGBQR.mjs +0 -3653
- package/dist/token-goat-chunk-UM47DRD3.mjs +0 -242
|
@@ -0,0 +1,1632 @@
|
|
|
1
|
+
import { createRequire as __cjsRequire } from 'node:module';
|
|
2
|
+
const require = __cjsRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
countContentLines,
|
|
5
|
+
escapeRegExp
|
|
6
|
+
} from "./token-goat-chunk-AMYCQJX4.mjs";
|
|
7
|
+
import {
|
|
8
|
+
init_define_import_meta_env
|
|
9
|
+
} from "./token-goat-chunk-A37V4PBF.mjs";
|
|
10
|
+
|
|
11
|
+
// src/languages/common.ts
|
|
12
|
+
init_define_import_meta_env();
|
|
13
|
+
|
|
14
|
+
// src/doc_comment.ts
|
|
15
|
+
init_define_import_meta_env();
|
|
16
|
+
function precedingDocComment(lines, lineStart, style) {
|
|
17
|
+
const aboveIdx = lineStart - 2;
|
|
18
|
+
if (aboveIdx < 0 || aboveIdx >= lines.length) return "";
|
|
19
|
+
const aboveLine = lines[aboveIdx];
|
|
20
|
+
if (aboveLine === void 0) return "";
|
|
21
|
+
const aboveTrimmed = aboveLine.trim();
|
|
22
|
+
if (style === "vb") {
|
|
23
|
+
if (!aboveTrimmed.startsWith("'''")) return "";
|
|
24
|
+
const collected = [];
|
|
25
|
+
for (let i = aboveIdx; i >= 0; i--) {
|
|
26
|
+
const trimmed = (lines[i] ?? "").trim();
|
|
27
|
+
if (!trimmed.startsWith("'''")) break;
|
|
28
|
+
collected.unshift(trimmed.replace(/^'''\s?/, ""));
|
|
29
|
+
}
|
|
30
|
+
return collected.join("\n").trim();
|
|
31
|
+
}
|
|
32
|
+
if (style === "hash") {
|
|
33
|
+
if (!aboveTrimmed.startsWith("#")) return "";
|
|
34
|
+
const collected = [];
|
|
35
|
+
let i = aboveIdx;
|
|
36
|
+
while (i >= 0) {
|
|
37
|
+
const line = lines[i];
|
|
38
|
+
if (line === void 0) break;
|
|
39
|
+
const trimmed = line.trim();
|
|
40
|
+
if (!trimmed.startsWith("#")) break;
|
|
41
|
+
collected.unshift(trimmed.replace(/^#+\s?/, ""));
|
|
42
|
+
i--;
|
|
43
|
+
}
|
|
44
|
+
return collected.join("\n").trim();
|
|
45
|
+
}
|
|
46
|
+
if (aboveTrimmed.endsWith("*/")) {
|
|
47
|
+
let blockStart = aboveIdx;
|
|
48
|
+
while (blockStart >= 0) {
|
|
49
|
+
const l = lines[blockStart];
|
|
50
|
+
if (l === void 0) break;
|
|
51
|
+
if (l.trim().startsWith("/*")) break;
|
|
52
|
+
blockStart--;
|
|
53
|
+
}
|
|
54
|
+
if (blockStart < 0) return "";
|
|
55
|
+
const opener = lines[blockStart];
|
|
56
|
+
if (opener === void 0 || !opener.trim().startsWith("/*")) return "";
|
|
57
|
+
const region = lines.slice(blockStart, aboveIdx + 1);
|
|
58
|
+
const joined = region.join("\n").trimEnd();
|
|
59
|
+
if (joined.indexOf("*/") !== joined.length - 2) return "";
|
|
60
|
+
return region.map(
|
|
61
|
+
(l) => l.trim().replace(/^\/\*+/, "").replace(/\*+\/$/, "").replace(/^\*\s?/, "").trim()
|
|
62
|
+
).filter((l) => l !== "").join("\n");
|
|
63
|
+
}
|
|
64
|
+
if (aboveTrimmed.startsWith("//")) {
|
|
65
|
+
const collected = [];
|
|
66
|
+
let i = aboveIdx;
|
|
67
|
+
while (i >= 0) {
|
|
68
|
+
const line = lines[i];
|
|
69
|
+
if (line === void 0) break;
|
|
70
|
+
const trimmed = line.trim();
|
|
71
|
+
if (!trimmed.startsWith("//")) break;
|
|
72
|
+
collected.unshift(trimmed.replace(/^\/\/[/!]?\s?/, ""));
|
|
73
|
+
i--;
|
|
74
|
+
}
|
|
75
|
+
return collected.join("\n").trim();
|
|
76
|
+
}
|
|
77
|
+
return "";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/languages/common.ts
|
|
81
|
+
function buildLineIndex(text) {
|
|
82
|
+
const idx = [0];
|
|
83
|
+
for (let i = 0; i < text.length; i++) {
|
|
84
|
+
if (text[i] === "\n") idx.push(i + 1);
|
|
85
|
+
}
|
|
86
|
+
return idx;
|
|
87
|
+
}
|
|
88
|
+
function offsetToLine(lineIndex, offset) {
|
|
89
|
+
let lo = 0;
|
|
90
|
+
let hi = lineIndex.length - 1;
|
|
91
|
+
while (lo < hi) {
|
|
92
|
+
const mid = lo + hi + 1 >> 1;
|
|
93
|
+
const lineStart = lineIndex[mid];
|
|
94
|
+
if (lineStart === void 0 || lineStart > offset) {
|
|
95
|
+
hi = mid - 1;
|
|
96
|
+
} else {
|
|
97
|
+
lo = mid;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return lo + 1;
|
|
101
|
+
}
|
|
102
|
+
function stripCstyleComments(text, lineCommentRe) {
|
|
103
|
+
const lines = text.split("\n");
|
|
104
|
+
let inComment = false;
|
|
105
|
+
const outLines = [];
|
|
106
|
+
for (const line of lines) {
|
|
107
|
+
const { code, inComment: nextInComment } = stripBlockCommentSpan(line, inComment);
|
|
108
|
+
outLines.push(code);
|
|
109
|
+
inComment = nextInComment;
|
|
110
|
+
}
|
|
111
|
+
let out = outLines.join("\n");
|
|
112
|
+
if (lineCommentRe !== void 0) {
|
|
113
|
+
out = out.replace(lineCommentRe, (m) => " ".repeat(m.length));
|
|
114
|
+
}
|
|
115
|
+
return out;
|
|
116
|
+
}
|
|
117
|
+
function stripXmlComments(text) {
|
|
118
|
+
const lines = text.split("\n");
|
|
119
|
+
let inComment = false;
|
|
120
|
+
const outLines = [];
|
|
121
|
+
for (const line of lines) {
|
|
122
|
+
let result = "";
|
|
123
|
+
let j = 0;
|
|
124
|
+
while (j < line.length) {
|
|
125
|
+
if (!inComment) {
|
|
126
|
+
const open = line.indexOf("<!--", j);
|
|
127
|
+
if (open === -1) {
|
|
128
|
+
result += line.slice(j);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
result += line.slice(j, open);
|
|
132
|
+
const close = line.indexOf("-->", open + 4);
|
|
133
|
+
if (close === -1) {
|
|
134
|
+
result += " ".repeat(line.length - open);
|
|
135
|
+
inComment = true;
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
result += " ".repeat(close + 3 - open);
|
|
139
|
+
j = close + 3;
|
|
140
|
+
inComment = false;
|
|
141
|
+
} else {
|
|
142
|
+
const close = line.indexOf("-->", j);
|
|
143
|
+
if (close === -1) {
|
|
144
|
+
result += " ".repeat(line.length - j);
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
result += " ".repeat(close + 3 - j);
|
|
148
|
+
j = close + 3;
|
|
149
|
+
inComment = false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
outLines.push(result);
|
|
153
|
+
}
|
|
154
|
+
return outLines.join("\n");
|
|
155
|
+
}
|
|
156
|
+
function scanQuotedStringEnd(content, start) {
|
|
157
|
+
const quote = content[start];
|
|
158
|
+
const n = content.length;
|
|
159
|
+
let j = start + 1;
|
|
160
|
+
while (j < n) {
|
|
161
|
+
if (content[j] === "\\" && j + 1 < n) {
|
|
162
|
+
j += 2;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (content[j] === quote) {
|
|
166
|
+
j++;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
if (quote !== "`" && content[j] === "\n") {
|
|
170
|
+
j++;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
j++;
|
|
174
|
+
}
|
|
175
|
+
return j;
|
|
176
|
+
}
|
|
177
|
+
function stripJsComments(content) {
|
|
178
|
+
let out = "";
|
|
179
|
+
let i = 0;
|
|
180
|
+
const n = content.length;
|
|
181
|
+
while (i < n) {
|
|
182
|
+
const ch = content[i];
|
|
183
|
+
if (ch === "/" && content[i + 1] === "/") {
|
|
184
|
+
let j = i;
|
|
185
|
+
while (j < n && content[j] !== "\n") j++;
|
|
186
|
+
out += " ".repeat(j - i);
|
|
187
|
+
i = j;
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (ch === "/" && content[i + 1] === "*") {
|
|
191
|
+
let j = i + 2;
|
|
192
|
+
while (j < n && !(content[j] === "*" && content[j + 1] === "/")) j++;
|
|
193
|
+
const end = j < n ? j + 2 : n;
|
|
194
|
+
out += content.slice(i, end).replace(/[^\n]/g, " ");
|
|
195
|
+
i = end;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
199
|
+
const j = scanQuotedStringEnd(content, i);
|
|
200
|
+
out += content.slice(i, j);
|
|
201
|
+
i = j;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
out += ch;
|
|
205
|
+
i++;
|
|
206
|
+
}
|
|
207
|
+
return out;
|
|
208
|
+
}
|
|
209
|
+
function stripHashComments(text) {
|
|
210
|
+
return text.split("\n").map((line) => {
|
|
211
|
+
for (let i = 0; i < line.length; i++) {
|
|
212
|
+
if (line[i] === "#" && !isInsideStringLiteral(line, i)) {
|
|
213
|
+
return line.slice(0, i) + " ".repeat(line.length - i);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return line;
|
|
217
|
+
}).join("\n");
|
|
218
|
+
}
|
|
219
|
+
var HTML_COMMENT_RE = /<!--[\s\S]*?-->/g;
|
|
220
|
+
var HTML_SCRIPT_BODY_RE = /(<script\b[^>]*>)([\s\S]*?)(<\/script\s*>)/gi;
|
|
221
|
+
var HTML_CDATA_RE = /<!\[CDATA\[[\s\S]*?\]\]>/g;
|
|
222
|
+
var LIQUID_COMMENT_RE = /{%-?\s*comment\s*-?%}[\s\S]*?{%-?\s*endcomment\s*-?%}/gi;
|
|
223
|
+
function maskHtmlNoise(text) {
|
|
224
|
+
let out = text.replace(
|
|
225
|
+
HTML_SCRIPT_BODY_RE,
|
|
226
|
+
(_m, open, body, close) => open + body.replace(/[^\n]/g, " ") + close
|
|
227
|
+
);
|
|
228
|
+
out = out.replace(HTML_COMMENT_RE, (m) => m.replace(/[^\n]/g, " "));
|
|
229
|
+
out = out.replace(LIQUID_COMMENT_RE, (m) => m.replace(/[^\n]/g, " "));
|
|
230
|
+
out = out.replace(HTML_CDATA_RE, (m) => m.replace(/[^\n]/g, " "));
|
|
231
|
+
return out;
|
|
232
|
+
}
|
|
233
|
+
var HTML_HEADING_RE = /<h([1-6])[^>]*>(.*?)<\/h\1>/gis;
|
|
234
|
+
var HTML_HEADING_TAG_STRIP_RE = /<[^>]+>/g;
|
|
235
|
+
function findHtmlHeadingMatches(content) {
|
|
236
|
+
const masked = maskHtmlNoise(content);
|
|
237
|
+
const matches = [];
|
|
238
|
+
for (const m of masked.matchAll(HTML_HEADING_RE)) {
|
|
239
|
+
const level = parseInt(m[1] ?? "1", 10);
|
|
240
|
+
const raw = m[2] ?? "";
|
|
241
|
+
const heading = raw.replace(HTML_HEADING_TAG_STRIP_RE, "").trim();
|
|
242
|
+
matches.push({ level, heading, offset: m.index ?? 0, tag: m[0] ?? "" });
|
|
243
|
+
}
|
|
244
|
+
return matches;
|
|
245
|
+
}
|
|
246
|
+
function isInsideStringLiteral(line, index, from = 0, opts = {}) {
|
|
247
|
+
let openQuote = null;
|
|
248
|
+
let i = from;
|
|
249
|
+
while (i < index) {
|
|
250
|
+
const ch = line[i];
|
|
251
|
+
if (opts.symbolLiterals === true && openQuote === null && ch === "'") {
|
|
252
|
+
const len = scalaCharLiteralLength(line, i);
|
|
253
|
+
i += len === 0 ? 1 : len;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
if (openQuote !== null && ch === "\\" && i + 1 < line.length) {
|
|
257
|
+
i += 2;
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
if (ch === '"' || ch === "'") {
|
|
261
|
+
if (openQuote === null) {
|
|
262
|
+
openQuote = ch;
|
|
263
|
+
} else if (openQuote === ch) {
|
|
264
|
+
openQuote = null;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
i++;
|
|
268
|
+
}
|
|
269
|
+
return openQuote !== null;
|
|
270
|
+
}
|
|
271
|
+
function nextBlockCommentOpen(line, from) {
|
|
272
|
+
const lineCommentIdx = lineCommentStartIndex(line, ["//"], from);
|
|
273
|
+
let open = line.indexOf("/*", from);
|
|
274
|
+
while (open !== -1 && (isInsideStringLiteral(line, open, from) || lineCommentIdx !== -1 && open >= lineCommentIdx)) {
|
|
275
|
+
open = line.indexOf("/*", open + 1);
|
|
276
|
+
}
|
|
277
|
+
return open;
|
|
278
|
+
}
|
|
279
|
+
function stripBlockCommentSpan(line, inComment) {
|
|
280
|
+
let code = "";
|
|
281
|
+
let j = 0;
|
|
282
|
+
let comment = inComment;
|
|
283
|
+
while (j < line.length) {
|
|
284
|
+
if (!comment) {
|
|
285
|
+
const open = nextBlockCommentOpen(line, j);
|
|
286
|
+
if (open === -1) {
|
|
287
|
+
code += line.slice(j);
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
code += line.slice(j, open);
|
|
291
|
+
const close = line.indexOf("*/", open + 2);
|
|
292
|
+
if (close === -1) {
|
|
293
|
+
code += " ".repeat(line.length - open);
|
|
294
|
+
comment = true;
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
code += " ".repeat(close + 2 - open);
|
|
298
|
+
j = close + 2;
|
|
299
|
+
comment = false;
|
|
300
|
+
} else {
|
|
301
|
+
const close = line.indexOf("*/", j);
|
|
302
|
+
if (close === -1) {
|
|
303
|
+
code += " ".repeat(line.length - j);
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
code += " ".repeat(close + 2 - j);
|
|
307
|
+
j = close + 2;
|
|
308
|
+
comment = false;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return { code, inComment: comment };
|
|
312
|
+
}
|
|
313
|
+
function stripNestedBlockCommentSpan(line, depth) {
|
|
314
|
+
let code = "";
|
|
315
|
+
let j = 0;
|
|
316
|
+
let d = depth;
|
|
317
|
+
while (j < line.length) {
|
|
318
|
+
if (d === 0) {
|
|
319
|
+
const open = nextBlockCommentOpen(line, j);
|
|
320
|
+
if (open === -1) {
|
|
321
|
+
code += line.slice(j);
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
code += line.slice(j, open);
|
|
325
|
+
code += " ";
|
|
326
|
+
j = open + 2;
|
|
327
|
+
d = 1;
|
|
328
|
+
} else {
|
|
329
|
+
const open = line.indexOf("/*", j);
|
|
330
|
+
const close = line.indexOf("*/", j);
|
|
331
|
+
if (close === -1 && open === -1) {
|
|
332
|
+
code += " ".repeat(line.length - j);
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
const next = close === -1 ? open : open === -1 ? close : Math.min(open, close);
|
|
336
|
+
code += " ".repeat(next + 2 - j);
|
|
337
|
+
d = Math.max(0, d + (next === open ? 1 : -1));
|
|
338
|
+
j = next + 2;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return { code, depth: d };
|
|
342
|
+
}
|
|
343
|
+
function stripLineComment(line, markers = ["//"], opts = {}) {
|
|
344
|
+
const cutIdx = lineCommentStartIndex(line, markers, 0, opts);
|
|
345
|
+
return cutIdx === -1 ? line : line.slice(0, cutIdx);
|
|
346
|
+
}
|
|
347
|
+
function lineCommentStartIndex(line, markers, from = 0, opts = {}) {
|
|
348
|
+
let cutIdx = -1;
|
|
349
|
+
for (const marker of markers) {
|
|
350
|
+
let idx = line.indexOf(marker, from);
|
|
351
|
+
while (idx !== -1 && isInsideStringLiteral(line, idx, from, opts)) {
|
|
352
|
+
idx = line.indexOf(marker, idx + 1);
|
|
353
|
+
}
|
|
354
|
+
if (idx !== -1 && (cutIdx === -1 || idx < cutIdx)) cutIdx = idx;
|
|
355
|
+
}
|
|
356
|
+
return cutIdx;
|
|
357
|
+
}
|
|
358
|
+
function scalaCharLiteralLength(line, index) {
|
|
359
|
+
if (line[index] !== "'") return 0;
|
|
360
|
+
if (line[index + 1] === "\\") {
|
|
361
|
+
if (line[index + 2] === "u") {
|
|
362
|
+
let i = index + 3;
|
|
363
|
+
while (line[i] === "u") i++;
|
|
364
|
+
return /^[0-9a-fA-F]{4}$/.test(line.slice(i, i + 4)) && line[i + 4] === "'" ? i + 5 - index : 0;
|
|
365
|
+
}
|
|
366
|
+
return line[index + 2] !== void 0 && line[index + 3] === "'" ? 4 : 0;
|
|
367
|
+
}
|
|
368
|
+
return line[index + 1] !== void 0 && line[index + 1] !== "'" && line[index + 2] === "'" ? 3 : 0;
|
|
369
|
+
}
|
|
370
|
+
function stripStringLiterals(line, opts = {}) {
|
|
371
|
+
const openDelim = (idx) => {
|
|
372
|
+
const q = line[idx];
|
|
373
|
+
if (opts.tripleQuotes && line[idx + 1] === q && line[idx + 2] === q) return q + q + q;
|
|
374
|
+
return q;
|
|
375
|
+
};
|
|
376
|
+
let out = "";
|
|
377
|
+
let i = 0;
|
|
378
|
+
const stack = [];
|
|
379
|
+
while (i < line.length) {
|
|
380
|
+
const ch = line[i];
|
|
381
|
+
if (ch === "\n") {
|
|
382
|
+
out += ch;
|
|
383
|
+
i++;
|
|
384
|
+
stack.length = 0;
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
const top = stack[stack.length - 1];
|
|
388
|
+
if (top === void 0) {
|
|
389
|
+
if (opts.symbolLiterals === true && ch === "'" && scalaCharLiteralLength(line, i) === 0) {
|
|
390
|
+
out += ch;
|
|
391
|
+
i++;
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
if (ch === '"' || ch === "'") {
|
|
395
|
+
const bareBraceHole = ch === '"' && i > 0 && line[i - 1] === "$";
|
|
396
|
+
const delim = openDelim(i);
|
|
397
|
+
stack.push({ kind: "string", quote: delim, bareBraceHole });
|
|
398
|
+
out += delim;
|
|
399
|
+
i += delim.length;
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
out += ch;
|
|
403
|
+
i++;
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (top.kind === "hole") {
|
|
407
|
+
if (opts.symbolLiterals === true && ch === "'" && scalaCharLiteralLength(line, i) === 0) {
|
|
408
|
+
out += ch;
|
|
409
|
+
i++;
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
if (ch === '"' || ch === "'") {
|
|
413
|
+
const bareBraceHole = ch === '"' && i > 0 && line[i - 1] === "$";
|
|
414
|
+
const delim = openDelim(i);
|
|
415
|
+
stack.push({ kind: "string", quote: delim, bareBraceHole });
|
|
416
|
+
out += delim;
|
|
417
|
+
i += delim.length;
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
if (ch === "{") {
|
|
421
|
+
top.depth++;
|
|
422
|
+
out += ch;
|
|
423
|
+
i++;
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
if (ch === "}") {
|
|
427
|
+
if (top.depth > 0) {
|
|
428
|
+
top.depth--;
|
|
429
|
+
} else {
|
|
430
|
+
stack.pop();
|
|
431
|
+
}
|
|
432
|
+
out += ch;
|
|
433
|
+
i++;
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
out += ch;
|
|
437
|
+
i++;
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
if (ch === "\\" && i + 1 < line.length && line[i + 1] !== "\n") {
|
|
441
|
+
out += " ";
|
|
442
|
+
i += 2;
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
if (ch === top.quote[0] && (top.quote.length === 1 || line.startsWith(top.quote, i))) {
|
|
446
|
+
stack.pop();
|
|
447
|
+
out += top.quote;
|
|
448
|
+
i += top.quote.length;
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
if (top.quote === '"') {
|
|
452
|
+
if (top.bareBraceHole && ch === "{") {
|
|
453
|
+
if (line[i + 1] === "{") {
|
|
454
|
+
out += " ";
|
|
455
|
+
i += 2;
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
stack.push({ kind: "hole", depth: 0 });
|
|
459
|
+
out += ch;
|
|
460
|
+
i++;
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
if (!top.bareBraceHole && ch === "$" && line[i + 1] === "{") {
|
|
464
|
+
stack.push({ kind: "hole", depth: 0 });
|
|
465
|
+
out += line.slice(i, i + 2);
|
|
466
|
+
i += 2;
|
|
467
|
+
continue;
|
|
468
|
+
}
|
|
469
|
+
if (!top.bareBraceHole && ch === "{" && line[i + 1] === "$") {
|
|
470
|
+
stack.push({ kind: "hole", depth: 0 });
|
|
471
|
+
out += ch;
|
|
472
|
+
i++;
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
out += " ";
|
|
477
|
+
i++;
|
|
478
|
+
}
|
|
479
|
+
return out;
|
|
480
|
+
}
|
|
481
|
+
function closingQuoteRunEnd(text, from, quote, len, runClose) {
|
|
482
|
+
for (let i = from; i < text.length; i++) {
|
|
483
|
+
if (text[i] !== quote) continue;
|
|
484
|
+
let run = 0;
|
|
485
|
+
while (text[i + run] === quote) run++;
|
|
486
|
+
if (run >= len) return runClose === "last" ? i + run : i + len;
|
|
487
|
+
i += run - 1;
|
|
488
|
+
}
|
|
489
|
+
return -1;
|
|
490
|
+
}
|
|
491
|
+
var MULTILINE_CLOSER_ANCHOR = {
|
|
492
|
+
// An Elixir heredoc is terminated only by a delimiter run that begins its own line, preceded by nothing but the whitespace that also sets the indentation stripped from the body (Elixir syntax reference, section "Strings", heredocs). A run appearing mid-line inside the body is content.
|
|
493
|
+
elixir: "lineStart",
|
|
494
|
+
// The closing delimiter of a Swift multi-line string literal has to appear on a line of its own, and its indentation sets what is stripped from each body line (The Swift Programming Language, "Strings and Characters", section "Multiline String Literals"). The same section's rules apply to the extended-delimiter multi-line form (`#"""`), whose only reachable state here is the cross-line one.
|
|
495
|
+
swift: "lineStart",
|
|
496
|
+
// A PHP heredoc or nowdoc closes on its identifier at the start of a line; PHP 7.3 allowed that identifier to be indented and to be followed by other characters (PHP language reference, "Strings", section "Heredoc text"). Read by the heredoc/nowdoc branch, which builds its anchor regex from this value.
|
|
497
|
+
php: "lineStart",
|
|
498
|
+
// A PowerShell here-string terminator (`"@` / `'@`) must be the first characters on its line, with no leading whitespace at all, which is the one language here that is stricter than `'lineStart'` (about_Quoting_Rules, "Here-Strings").
|
|
499
|
+
powershell: "column0",
|
|
500
|
+
// Kotlin's raw string is terminated by the next `"""` wherever it falls, so `val s = """a"""` on one line is a complete literal (Kotlin language specification, "Expressions", section "String literals").
|
|
501
|
+
kotlin: "anywhere",
|
|
502
|
+
// Scala's multi-line string literal is likewise terminated by the next run of three quotes on any line (Scala language specification, section 1.3.5 "Character Literals and String Literals").
|
|
503
|
+
scala: "anywhere",
|
|
504
|
+
// Dart's multi-line string production is a delimiter, content, then the delimiter, with no rule about where on a line the closing delimiter falls (Dart Programming Language Specification, section "Strings").
|
|
505
|
+
dart: "anywhere",
|
|
506
|
+
// A GraphQL block string closes at the next `"""` wherever it sits: the spec's BlockString production places no positional rule on the closing delimiter, and a one-line description such as `"""A user."""` is the ordinary form (GraphQL specification, section 2.9.4 "String Value").
|
|
507
|
+
graphql: "anywhere",
|
|
508
|
+
// C# has two cross-line forms and they disagree, so the language-level value is the permissive one. A verbatim string (`@"..."`) closes on the next non-doubled quote wherever it sits and has no positional rule (C# language reference, "String literals"). A multi-line raw string literal does require its closing run to begin its own line (C# language reference, "Raw string literals"), but that rule is unreachable as a mis-pairing here: the same section forbids the content from holding a quote run as long as the delimiter, so no run inside the body can be mistaken for the closer in the first place, and the run-length rule already in `closingQuoteRunEnd` is what enforces it.
|
|
509
|
+
csharp: "anywhere",
|
|
510
|
+
// R has no fixed-delimiter multi-line form and no positional rule: an ordinary character constant runs to its next unescaped quote (R Language Definition, section 10.3.1 "Literal constants") and a raw constant to its mirrored closing punctuation (R base help page `?Quotes`, "Raw character constants"), on whatever line either lands.
|
|
511
|
+
r: "anywhere"
|
|
512
|
+
};
|
|
513
|
+
function closerSearchStart(line, from, anchor) {
|
|
514
|
+
if (anchor === "anywhere") return from;
|
|
515
|
+
const indent = anchor === "column0" ? 0 : /^[ \t]*/.exec(line)?.[0].length ?? 0;
|
|
516
|
+
return from <= indent ? indent : -1;
|
|
517
|
+
}
|
|
518
|
+
var TRIPLE_QUOTE_RUN_CLOSE = {
|
|
519
|
+
kotlin: "last",
|
|
520
|
+
scala: "last",
|
|
521
|
+
// A GraphQL block string ends at the first `"""` run, because its grammar excludes that sequence from the body outright rather than letting the longest run win (GraphQL specification, section 2.9.4 "String Value", the BlockString production).
|
|
522
|
+
graphql: "first",
|
|
523
|
+
// Swift's closing delimiter has to stand alone on its own line (The Swift Programming Language, "Strings and Characters", section "Multiline String Literals"), so no run longer than three ever terminates a valid Swift literal; it is grouped with Kotlin and Scala so that the same-line and cross-line paths agree, not to assert a rule Swift itself defines.
|
|
524
|
+
swift: "last",
|
|
525
|
+
csharp: "last",
|
|
526
|
+
// An Elixir heredoc cannot open and close on one line, because its opening `"""` must be followed by a newline, so only the cross-line closer is reachable for valid Elixir and that path has always consumed the whole run.
|
|
527
|
+
elixir: "last",
|
|
528
|
+
dart: "first",
|
|
529
|
+
// No triple-quoted literal at all: PHP uses heredoc/nowdoc, PowerShell `@"`/`@'` here-strings, R ordinary and raw character constants. Present only because the Record is exhaustive; the value is never read for these three.
|
|
530
|
+
php: "last",
|
|
531
|
+
powershell: "last",
|
|
532
|
+
r: "last"
|
|
533
|
+
};
|
|
534
|
+
function quoteRunCloser(line, from, quote, len, state) {
|
|
535
|
+
const anchor = state.closerAnchor ?? "anywhere";
|
|
536
|
+
const start = closerSearchStart(line, from, anchor);
|
|
537
|
+
if (start === -1) return null;
|
|
538
|
+
if (anchor !== "anywhere") {
|
|
539
|
+
let run = 0;
|
|
540
|
+
while (line[start + run] === quote) run++;
|
|
541
|
+
if (run < len) return null;
|
|
542
|
+
}
|
|
543
|
+
const end = closingQuoteRunEnd(line, start, quote, len, state.runClose ?? "last");
|
|
544
|
+
return end === -1 ? null : { maskEnd: end };
|
|
545
|
+
}
|
|
546
|
+
function findMultilineCloser(line, from, state) {
|
|
547
|
+
switch (state.kind) {
|
|
548
|
+
case "heredoc":
|
|
549
|
+
case "nowdoc": {
|
|
550
|
+
const indent = (state.closerAnchor ?? "anywhere") === "column0" ? "" : "[ \\t]*";
|
|
551
|
+
const re = new RegExp(`^${indent}${escapeRegExp(state.identifier)}\\b`);
|
|
552
|
+
const m = re.exec(line);
|
|
553
|
+
return m ? { maskEnd: m[0].length } : null;
|
|
554
|
+
}
|
|
555
|
+
case "sigil": {
|
|
556
|
+
const end = elixirSigilEnd(line, from, state);
|
|
557
|
+
return end === -1 ? null : { maskEnd: end };
|
|
558
|
+
}
|
|
559
|
+
case "tripleSingleQuote": {
|
|
560
|
+
return quoteRunCloser(line, from, "'", 3, state);
|
|
561
|
+
}
|
|
562
|
+
case "tripleQuote": {
|
|
563
|
+
const n = state.identifier !== "" ? parseInt(state.identifier, 10) : 3;
|
|
564
|
+
return quoteRunCloser(line, from, '"', n, state);
|
|
565
|
+
}
|
|
566
|
+
case "rRaw":
|
|
567
|
+
case "swiftExtended": {
|
|
568
|
+
const anchor = state.closerAnchor ?? "anywhere";
|
|
569
|
+
if (anchor !== "anywhere") {
|
|
570
|
+
const start = closerSearchStart(line, from, anchor);
|
|
571
|
+
if (start === -1 || !line.startsWith(state.identifier, start)) return null;
|
|
572
|
+
return { maskEnd: start + state.identifier.length };
|
|
573
|
+
}
|
|
574
|
+
const idx = line.indexOf(state.identifier, from);
|
|
575
|
+
return idx === -1 ? null : { maskEnd: idx + state.identifier.length };
|
|
576
|
+
}
|
|
577
|
+
case "rString": {
|
|
578
|
+
const idx = findRQuoteEnd(line, from, state.identifier);
|
|
579
|
+
return idx === -1 ? null : { maskEnd: idx + 1 };
|
|
580
|
+
}
|
|
581
|
+
case "verbatim": {
|
|
582
|
+
if (!state.interpolated) {
|
|
583
|
+
let j2 = from;
|
|
584
|
+
while (j2 < line.length) {
|
|
585
|
+
if (line[j2] === '"') {
|
|
586
|
+
if (line[j2 + 1] === '"') {
|
|
587
|
+
j2 += 2;
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
return { maskEnd: j2 + 1 };
|
|
591
|
+
}
|
|
592
|
+
j2++;
|
|
593
|
+
}
|
|
594
|
+
return null;
|
|
595
|
+
}
|
|
596
|
+
let j = from;
|
|
597
|
+
let holeDepth = 0;
|
|
598
|
+
let nestedQuote = null;
|
|
599
|
+
while (j < line.length) {
|
|
600
|
+
const c = line[j];
|
|
601
|
+
if (nestedQuote !== null) {
|
|
602
|
+
if (c === "\\" && j + 1 < line.length) {
|
|
603
|
+
j += 2;
|
|
604
|
+
continue;
|
|
605
|
+
}
|
|
606
|
+
if (c === nestedQuote) {
|
|
607
|
+
nestedQuote = null;
|
|
608
|
+
}
|
|
609
|
+
j++;
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
if (holeDepth > 0) {
|
|
613
|
+
if (c === '"' || c === "'") {
|
|
614
|
+
nestedQuote = c;
|
|
615
|
+
j++;
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
if (c === "{") holeDepth++;
|
|
619
|
+
else if (c === "}") holeDepth--;
|
|
620
|
+
j++;
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
if (c === "{") {
|
|
624
|
+
holeDepth = 1;
|
|
625
|
+
j++;
|
|
626
|
+
continue;
|
|
627
|
+
}
|
|
628
|
+
if (c === '"') {
|
|
629
|
+
if (line[j + 1] === '"') {
|
|
630
|
+
j += 2;
|
|
631
|
+
continue;
|
|
632
|
+
}
|
|
633
|
+
return { maskEnd: j + 1 };
|
|
634
|
+
}
|
|
635
|
+
j++;
|
|
636
|
+
}
|
|
637
|
+
return null;
|
|
638
|
+
}
|
|
639
|
+
case "psHereDouble":
|
|
640
|
+
case "psHereSingle": {
|
|
641
|
+
const start = closerSearchStart(line, from, state.closerAnchor ?? "anywhere");
|
|
642
|
+
const terminator = state.kind === "psHereDouble" ? '"@' : "'@";
|
|
643
|
+
if (start === -1 || !line.startsWith(terminator, start)) return null;
|
|
644
|
+
return { maskEnd: start + terminator.length };
|
|
645
|
+
}
|
|
646
|
+
default:
|
|
647
|
+
return null;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
var MULTILINE_OPENER_COMMENT_MARKERS = {
|
|
651
|
+
php: ["//", "#"],
|
|
652
|
+
kotlin: ["//"],
|
|
653
|
+
graphql: ["#"],
|
|
654
|
+
csharp: ["//"],
|
|
655
|
+
powershell: ["#"],
|
|
656
|
+
swift: ["//"],
|
|
657
|
+
elixir: ["#"],
|
|
658
|
+
scala: ["//"],
|
|
659
|
+
dart: ["//"],
|
|
660
|
+
r: ["#"]
|
|
661
|
+
};
|
|
662
|
+
var MULTILINE_OPENER_BLOCK_COMMENT_LANGS = /* @__PURE__ */ new Set(["php", "kotlin", "csharp", "swift", "scala", "dart"]);
|
|
663
|
+
var R_RAW_OPENER_RE = /[rR](["'])(-*)([([{])/y;
|
|
664
|
+
var R_RAW_CLOSE_BRACKET = { "(": ")", "[": "]", "{": "}" };
|
|
665
|
+
var R_IDENT_CHAR_RE = /[A-Za-z0-9._]/;
|
|
666
|
+
function matchRRawOpener(text, index) {
|
|
667
|
+
const ch = text[index];
|
|
668
|
+
if (ch !== "r" && ch !== "R") return null;
|
|
669
|
+
if (R_IDENT_CHAR_RE.test(text[index - 1] ?? "")) return null;
|
|
670
|
+
R_RAW_OPENER_RE.lastIndex = index;
|
|
671
|
+
const m = R_RAW_OPENER_RE.exec(text);
|
|
672
|
+
if (m === null) return null;
|
|
673
|
+
const close = R_RAW_CLOSE_BRACKET[m[3] ?? ""];
|
|
674
|
+
if (close === void 0) return null;
|
|
675
|
+
return { openerEnd: index + m[0].length, closer: `${close}${m[2] ?? ""}${m[1] ?? ""}` };
|
|
676
|
+
}
|
|
677
|
+
var GROOVY_OPERAND_BEFORE = /* @__PURE__ */ new Set([..."([{,;=+-*/%<>!&|^~?:"]);
|
|
678
|
+
var MAX_GROOVY_SLASHY_BODY = 1024;
|
|
679
|
+
var GROOVY_OPERAND_KEYWORDS = /* @__PURE__ */ new Set(["return", "case", "in", "new", "assert", "instanceof"]);
|
|
680
|
+
function groovyOperandPosition(text, index) {
|
|
681
|
+
let i = index - 1;
|
|
682
|
+
while (i >= 0 && (text[i] === " " || text[i] === " ")) i--;
|
|
683
|
+
if (i < 0) return true;
|
|
684
|
+
const ch = text[i];
|
|
685
|
+
if (ch === "\n" || ch === "\r") return true;
|
|
686
|
+
if (GROOVY_OPERAND_BEFORE.has(ch)) return true;
|
|
687
|
+
if (!/[\w$]/.test(ch)) return false;
|
|
688
|
+
let j = i;
|
|
689
|
+
while (j >= 0 && /[\w$]/.test(text[j])) j--;
|
|
690
|
+
return GROOVY_OPERAND_KEYWORDS.has(text.slice(j + 1, i + 1));
|
|
691
|
+
}
|
|
692
|
+
function matchGroovySlashy(text, index) {
|
|
693
|
+
const dollar = text[index] === "$" && text[index + 1] === "/";
|
|
694
|
+
if (!dollar) {
|
|
695
|
+
if (text[index] !== "/") return null;
|
|
696
|
+
const next = text[index + 1];
|
|
697
|
+
if (next === "/" || next === "*") return null;
|
|
698
|
+
if (!groovyOperandPosition(text, index)) return null;
|
|
699
|
+
}
|
|
700
|
+
const bodyStart = index + (dollar ? 2 : 1);
|
|
701
|
+
const limit = Math.min(text.length, bodyStart + MAX_GROOVY_SLASHY_BODY);
|
|
702
|
+
for (let i = bodyStart; i < limit; i++) {
|
|
703
|
+
const ch = text[i];
|
|
704
|
+
if (dollar) {
|
|
705
|
+
if (ch === "$" && (text[i + 1] === "$" || text[i + 1] === "/")) {
|
|
706
|
+
i++;
|
|
707
|
+
continue;
|
|
708
|
+
}
|
|
709
|
+
if (ch === "/" && text[i + 1] === "$") return { bodyStart, bodyEnd: i, end: i + 2 };
|
|
710
|
+
continue;
|
|
711
|
+
}
|
|
712
|
+
if (ch === "\\" && text[i + 1] === "/") {
|
|
713
|
+
i++;
|
|
714
|
+
continue;
|
|
715
|
+
}
|
|
716
|
+
if (ch === "\n") return null;
|
|
717
|
+
if (ch === "/") return { bodyStart, bodyEnd: i, end: i + 1 };
|
|
718
|
+
}
|
|
719
|
+
return null;
|
|
720
|
+
}
|
|
721
|
+
var ELIXIR_SIGIL_CLOSER = { "(": ")", "[": "]", "{": "}", "<": ">", "/": "/", "|": "|", '"': '"', "'": "'" };
|
|
722
|
+
var ELIXIR_SIGIL_OPENER = { ")": "(", "]": "[", "}": "{", ">": "<" };
|
|
723
|
+
function matchElixirSigilOpener(line, index) {
|
|
724
|
+
if (line[index] !== "~") return null;
|
|
725
|
+
let i = index + 1;
|
|
726
|
+
const first = line[i] ?? "";
|
|
727
|
+
let escapes;
|
|
728
|
+
if (first >= "a" && first <= "z") {
|
|
729
|
+
escapes = true;
|
|
730
|
+
i++;
|
|
731
|
+
} else if (first >= "A" && first <= "Z") {
|
|
732
|
+
escapes = false;
|
|
733
|
+
while (i < line.length && (line[i] ?? "") >= "A" && (line[i] ?? "") <= "Z") i++;
|
|
734
|
+
} else {
|
|
735
|
+
return null;
|
|
736
|
+
}
|
|
737
|
+
const delim = line[i] ?? "";
|
|
738
|
+
const closer = ELIXIR_SIGIL_CLOSER[delim];
|
|
739
|
+
if (closer === void 0) return null;
|
|
740
|
+
if ((delim === '"' || delim === "'") && line[i + 1] === delim && line[i + 2] === delim) return null;
|
|
741
|
+
return { openerEnd: i + 1, closer, escapes };
|
|
742
|
+
}
|
|
743
|
+
function elixirSigilEnd(line, from, state) {
|
|
744
|
+
const closer = state.identifier;
|
|
745
|
+
const opener = ELIXIR_SIGIL_OPENER[closer];
|
|
746
|
+
for (let i = from; i < line.length; i++) {
|
|
747
|
+
const ch = line[i];
|
|
748
|
+
if (state.escapes === true && ch === "\\") {
|
|
749
|
+
i++;
|
|
750
|
+
continue;
|
|
751
|
+
}
|
|
752
|
+
if (opener !== void 0 && ch === opener) {
|
|
753
|
+
state.depth = (state.depth ?? 0) + 1;
|
|
754
|
+
continue;
|
|
755
|
+
}
|
|
756
|
+
if (ch === closer) {
|
|
757
|
+
if ((state.depth ?? 0) > 0) {
|
|
758
|
+
state.depth = (state.depth ?? 0) - 1;
|
|
759
|
+
continue;
|
|
760
|
+
}
|
|
761
|
+
return i + 1;
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
return -1;
|
|
765
|
+
}
|
|
766
|
+
var SWIFT_EXTENDED_OPENER_RE = /(#+)("""|")/y;
|
|
767
|
+
function matchSwiftExtendedOpener(text, index) {
|
|
768
|
+
if (text[index] !== "#") return null;
|
|
769
|
+
SWIFT_EXTENDED_OPENER_RE.lastIndex = index;
|
|
770
|
+
const m = SWIFT_EXTENDED_OPENER_RE.exec(text);
|
|
771
|
+
if (m === null) return null;
|
|
772
|
+
const hashes = m[1] ?? "";
|
|
773
|
+
const multiline = m[2] === '"""';
|
|
774
|
+
return { openerEnd: index + m[0].length, multiline, closer: `${multiline ? '"""' : '"'}${hashes}` };
|
|
775
|
+
}
|
|
776
|
+
var BASH_WORD_TERMINATORS = /* @__PURE__ */ new Set([" ", " ", "\n", "|", "&", ";", "(", ")", "<", ">"]);
|
|
777
|
+
function matchBashHeredocOpener(text, index) {
|
|
778
|
+
if (text[index] !== "<" || text[index + 1] !== "<") return null;
|
|
779
|
+
if (text[index - 1] === "<" || text[index + 2] === "<") return null;
|
|
780
|
+
let i = index + 2;
|
|
781
|
+
if (text[i] === "-") i++;
|
|
782
|
+
while (text[i] === " " || text[i] === " ") i++;
|
|
783
|
+
let terminator = "";
|
|
784
|
+
while (i < text.length) {
|
|
785
|
+
const ch = text[i];
|
|
786
|
+
if (ch === "'") {
|
|
787
|
+
const close = text.indexOf("'", i + 1);
|
|
788
|
+
if (close === -1) return null;
|
|
789
|
+
terminator += text.slice(i + 1, close);
|
|
790
|
+
i = close + 1;
|
|
791
|
+
continue;
|
|
792
|
+
}
|
|
793
|
+
if (ch === '"') {
|
|
794
|
+
let j = i + 1;
|
|
795
|
+
for (; j < text.length; j++) {
|
|
796
|
+
if (text[j] === "\\") {
|
|
797
|
+
terminator += text[j + 1] ?? "";
|
|
798
|
+
j++;
|
|
799
|
+
continue;
|
|
800
|
+
}
|
|
801
|
+
if (text[j] === '"') break;
|
|
802
|
+
terminator += text[j];
|
|
803
|
+
}
|
|
804
|
+
if (j >= text.length) return null;
|
|
805
|
+
i = j + 1;
|
|
806
|
+
continue;
|
|
807
|
+
}
|
|
808
|
+
if (ch === "\\") {
|
|
809
|
+
if (i + 1 >= text.length) break;
|
|
810
|
+
terminator += text[i + 1];
|
|
811
|
+
i += 2;
|
|
812
|
+
continue;
|
|
813
|
+
}
|
|
814
|
+
if (ch === void 0 || BASH_WORD_TERMINATORS.has(ch)) break;
|
|
815
|
+
terminator += ch;
|
|
816
|
+
i++;
|
|
817
|
+
}
|
|
818
|
+
if (terminator === "") return null;
|
|
819
|
+
return { openerEnd: i, terminator };
|
|
820
|
+
}
|
|
821
|
+
function findRQuoteEnd(line, start, quote) {
|
|
822
|
+
for (let j = start; j < line.length; j++) {
|
|
823
|
+
const c = line[j];
|
|
824
|
+
if (c === "\\") {
|
|
825
|
+
j++;
|
|
826
|
+
continue;
|
|
827
|
+
}
|
|
828
|
+
if (c === quote) return j;
|
|
829
|
+
}
|
|
830
|
+
return -1;
|
|
831
|
+
}
|
|
832
|
+
function isInsideSameLineBlockComment(line, idx, from = 0) {
|
|
833
|
+
let comment = false;
|
|
834
|
+
let j = from;
|
|
835
|
+
while (j < idx) {
|
|
836
|
+
if (!comment) {
|
|
837
|
+
const open = line.indexOf("/*", j);
|
|
838
|
+
if (open === -1 || open >= idx) return false;
|
|
839
|
+
if (isInsideStringLiteral(line, open, from)) {
|
|
840
|
+
j = open + 2;
|
|
841
|
+
continue;
|
|
842
|
+
}
|
|
843
|
+
comment = true;
|
|
844
|
+
j = open + 2;
|
|
845
|
+
} else {
|
|
846
|
+
const close = line.indexOf("*/", j);
|
|
847
|
+
if (close === -1 || close >= idx) return true;
|
|
848
|
+
comment = false;
|
|
849
|
+
j = close + 2;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
return comment;
|
|
853
|
+
}
|
|
854
|
+
function findMultilineOpener(line, from, lang) {
|
|
855
|
+
const commentIdx = lineCommentStartIndex(line, MULTILINE_OPENER_COMMENT_MARKERS[lang], from);
|
|
856
|
+
const isCommented = (idx) => commentIdx !== -1 && idx >= commentIdx || MULTILINE_OPENER_BLOCK_COMMENT_LANGS.has(lang) && isInsideSameLineBlockComment(line, idx, from);
|
|
857
|
+
if (lang === "php") {
|
|
858
|
+
const re = /<<<\s*(['"]?)([A-Za-z_]\w*)\1/g;
|
|
859
|
+
re.lastIndex = from;
|
|
860
|
+
const m = re.exec(line);
|
|
861
|
+
if (!m || isInsideStringLiteral(line, m.index, from) || isCommented(m.index)) return null;
|
|
862
|
+
const identifier = m[2] ?? "";
|
|
863
|
+
const kind = m[1] === "'" ? "nowdoc" : "heredoc";
|
|
864
|
+
return { openStart: m.index, closesSameLine: null, state: { kind, identifier, closerAnchor: MULTILINE_CLOSER_ANCHOR[lang] } };
|
|
865
|
+
}
|
|
866
|
+
if (lang === "kotlin" || lang === "swift" || lang === "scala" || lang === "graphql") {
|
|
867
|
+
let swiftExt = null;
|
|
868
|
+
if (lang === "swift") {
|
|
869
|
+
for (let h = line.indexOf("#", from); h !== -1; h = line.indexOf("#", h + 1)) {
|
|
870
|
+
const ext = matchSwiftExtendedOpener(line, h);
|
|
871
|
+
if (ext === null || isInsideStringLiteral(line, h, from) || isCommented(h)) continue;
|
|
872
|
+
const extClose = line.indexOf(ext.closer, ext.openerEnd);
|
|
873
|
+
const extState = { kind: "swiftExtended", identifier: ext.closer, closerAnchor: MULTILINE_CLOSER_ANCHOR[lang] };
|
|
874
|
+
if (extClose !== -1) {
|
|
875
|
+
swiftExt = { openStart: h, closesSameLine: extClose + ext.closer.length, state: extState };
|
|
876
|
+
break;
|
|
877
|
+
}
|
|
878
|
+
if (ext.multiline) {
|
|
879
|
+
swiftExt = { openStart: h, closesSameLine: null, state: extState };
|
|
880
|
+
break;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
const idx = line.indexOf('"""', from);
|
|
885
|
+
if (swiftExt !== null && (idx === -1 || swiftExt.openStart < idx)) return swiftExt;
|
|
886
|
+
if (idx === -1 || isInsideStringLiteral(line, idx, from) || isCommented(idx)) return null;
|
|
887
|
+
const runClose = TRIPLE_QUOTE_RUN_CLOSE[lang];
|
|
888
|
+
const tripleState = { kind: "tripleQuote", identifier: "3", runClose, closerAnchor: MULTILINE_CLOSER_ANCHOR[lang] };
|
|
889
|
+
const closeEnd = closingQuoteRunEnd(line, idx + 3, '"', 3, runClose);
|
|
890
|
+
if (closeEnd !== -1) {
|
|
891
|
+
return { openStart: idx, closesSameLine: closeEnd, state: tripleState };
|
|
892
|
+
}
|
|
893
|
+
return { openStart: idx, closesSameLine: null, state: tripleState };
|
|
894
|
+
}
|
|
895
|
+
if (lang === "elixir" || lang === "dart") {
|
|
896
|
+
const candidates = [];
|
|
897
|
+
const dq = line.indexOf('"""', from);
|
|
898
|
+
if (dq !== -1) candidates.push([dq, "tripleQuote", '"""']);
|
|
899
|
+
const sq = line.indexOf("'''", from);
|
|
900
|
+
if (sq !== -1) candidates.push([sq, "tripleSingleQuote", "'''"]);
|
|
901
|
+
candidates.sort((a, b) => a[0] - b[0]);
|
|
902
|
+
const first = candidates[0];
|
|
903
|
+
if (lang === "elixir") {
|
|
904
|
+
for (let t = line.indexOf("~", from); t !== -1; t = line.indexOf("~", t + 1)) {
|
|
905
|
+
if (first !== void 0 && first[0] < t) break;
|
|
906
|
+
const open = matchElixirSigilOpener(line, t);
|
|
907
|
+
if (open === null || isInsideStringLiteral(line, t, from) || isCommented(t)) continue;
|
|
908
|
+
const state2 = { kind: "sigil", identifier: open.closer, depth: 0, escapes: open.escapes };
|
|
909
|
+
const end = elixirSigilEnd(line, open.openerEnd, state2);
|
|
910
|
+
return { openStart: t, closesSameLine: end === -1 ? null : end, state: state2 };
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
if (first === void 0) return null;
|
|
914
|
+
const [idx, kind, delim] = first;
|
|
915
|
+
if (isInsideStringLiteral(line, idx, from) || isCommented(idx)) return null;
|
|
916
|
+
const runClose = TRIPLE_QUOTE_RUN_CLOSE[lang];
|
|
917
|
+
const state = { kind, identifier: "3", runClose, closerAnchor: MULTILINE_CLOSER_ANCHOR[lang] };
|
|
918
|
+
const closeEnd = closingQuoteRunEnd(line, idx + 3, delim[0] ?? '"', 3, runClose);
|
|
919
|
+
if (closeEnd !== -1) return { openStart: idx, closesSameLine: closeEnd, state };
|
|
920
|
+
return { openStart: idx, closesSameLine: null, state };
|
|
921
|
+
}
|
|
922
|
+
if (lang === "r") {
|
|
923
|
+
const limit = commentIdx === -1 ? line.length : commentIdx;
|
|
924
|
+
let i = from;
|
|
925
|
+
while (i < limit) {
|
|
926
|
+
const ch = line[i] ?? "";
|
|
927
|
+
if (ch === "`") {
|
|
928
|
+
const end = line.indexOf("`", i + 1);
|
|
929
|
+
if (end === -1 || end >= limit) return null;
|
|
930
|
+
i = end + 1;
|
|
931
|
+
continue;
|
|
932
|
+
}
|
|
933
|
+
const raw = matchRRawOpener(line, i);
|
|
934
|
+
if (raw !== null) {
|
|
935
|
+
const closeIdx = line.indexOf(raw.closer, raw.openerEnd);
|
|
936
|
+
if (closeIdx === -1) return { openStart: i, closesSameLine: null, state: { kind: "rRaw", identifier: raw.closer, closerAnchor: MULTILINE_CLOSER_ANCHOR[lang] } };
|
|
937
|
+
i = closeIdx + raw.closer.length;
|
|
938
|
+
continue;
|
|
939
|
+
}
|
|
940
|
+
if (ch === '"' || ch === "'") {
|
|
941
|
+
const closeIdx = findRQuoteEnd(line, i + 1, ch);
|
|
942
|
+
if (closeIdx === -1) return { openStart: i, closesSameLine: null, state: { kind: "rString", identifier: ch, closerAnchor: MULTILINE_CLOSER_ANCHOR[lang] } };
|
|
943
|
+
i = closeIdx + 1;
|
|
944
|
+
continue;
|
|
945
|
+
}
|
|
946
|
+
i++;
|
|
947
|
+
}
|
|
948
|
+
return null;
|
|
949
|
+
}
|
|
950
|
+
if (lang === "csharp") {
|
|
951
|
+
const tripleRe = /"{3,}/g;
|
|
952
|
+
tripleRe.lastIndex = from;
|
|
953
|
+
const tripleM = tripleRe.exec(line);
|
|
954
|
+
let tripleIdx = tripleM ? tripleM.index : -1;
|
|
955
|
+
const tripleLen = tripleM ? tripleM[0].length : 0;
|
|
956
|
+
if (tripleIdx !== -1 && (isInsideStringLiteral(line, tripleIdx, from) || isCommented(tripleIdx))) tripleIdx = -1;
|
|
957
|
+
const verbRe = /\$?@\$?"/g;
|
|
958
|
+
verbRe.lastIndex = from;
|
|
959
|
+
const verbM = verbRe.exec(line);
|
|
960
|
+
let verbIdx = verbM ? verbM.index : -1;
|
|
961
|
+
if (verbIdx !== -1 && isCommented(verbIdx)) verbIdx = -1;
|
|
962
|
+
if (verbIdx !== -1 && isInsideStringLiteral(line, verbIdx, from)) verbIdx = -1;
|
|
963
|
+
if (tripleIdx === -1 && verbIdx === -1) return null;
|
|
964
|
+
const useTriple = tripleIdx !== -1 && (verbIdx === -1 || tripleIdx < verbIdx);
|
|
965
|
+
if (useTriple) {
|
|
966
|
+
const rawState = { kind: "tripleQuote", identifier: String(tripleLen), runClose: TRIPLE_QUOTE_RUN_CLOSE.csharp, closerAnchor: MULTILINE_CLOSER_ANCHOR[lang] };
|
|
967
|
+
const closeEnd = closingQuoteRunEnd(line, tripleIdx + tripleLen, '"', tripleLen, rawState.runClose ?? "last");
|
|
968
|
+
if (closeEnd !== -1) {
|
|
969
|
+
return { openStart: tripleIdx, closesSameLine: closeEnd, state: rawState };
|
|
970
|
+
}
|
|
971
|
+
return { openStart: tripleIdx, closesSameLine: null, state: rawState };
|
|
972
|
+
}
|
|
973
|
+
const quoteIdx = verbIdx + (verbM?.[0].length ?? 1) - 1;
|
|
974
|
+
const interpolated = (verbM?.[0] ?? "").includes("$");
|
|
975
|
+
const closer = findMultilineCloser(line, quoteIdx + 1, { kind: "verbatim", identifier: "", interpolated });
|
|
976
|
+
if (closer !== null) {
|
|
977
|
+
return { openStart: verbIdx, closesSameLine: closer.maskEnd, state: { kind: "verbatim", identifier: "", interpolated } };
|
|
978
|
+
}
|
|
979
|
+
return { openStart: verbIdx, closesSameLine: null, state: { kind: "verbatim", identifier: "", interpolated } };
|
|
980
|
+
}
|
|
981
|
+
if (lang === "powershell") {
|
|
982
|
+
const re = /@("|')\s*$/;
|
|
983
|
+
const tail = line.slice(from);
|
|
984
|
+
const m = re.exec(tail);
|
|
985
|
+
if (!m) return null;
|
|
986
|
+
const openStart = from + m.index;
|
|
987
|
+
if (isCommented(openStart)) return null;
|
|
988
|
+
if (isInsideStringLiteral(line, openStart, from)) return null;
|
|
989
|
+
const kind = m[1] === '"' ? "psHereDouble" : "psHereSingle";
|
|
990
|
+
return { openStart, closesSameLine: null, state: { kind, identifier: "", closerAnchor: MULTILINE_CLOSER_ANCHOR[lang] } };
|
|
991
|
+
}
|
|
992
|
+
return null;
|
|
993
|
+
}
|
|
994
|
+
function stripMultilineStringSpan(line, state, lang) {
|
|
995
|
+
let code = "";
|
|
996
|
+
let i = 0;
|
|
997
|
+
let cur = state;
|
|
998
|
+
while (i < line.length) {
|
|
999
|
+
if (cur !== null) {
|
|
1000
|
+
const closed = findMultilineCloser(line, i, cur);
|
|
1001
|
+
if (closed === null) {
|
|
1002
|
+
code += " ".repeat(line.length - i);
|
|
1003
|
+
i = line.length;
|
|
1004
|
+
continue;
|
|
1005
|
+
}
|
|
1006
|
+
code += " ".repeat(closed.maskEnd - i);
|
|
1007
|
+
i = closed.maskEnd;
|
|
1008
|
+
cur = null;
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
1011
|
+
const opened = findMultilineOpener(line, i, lang);
|
|
1012
|
+
if (opened === null) {
|
|
1013
|
+
code += line.slice(i);
|
|
1014
|
+
break;
|
|
1015
|
+
}
|
|
1016
|
+
code += line.slice(i, opened.openStart);
|
|
1017
|
+
if (opened.closesSameLine !== null) {
|
|
1018
|
+
code += " ".repeat(opened.closesSameLine - opened.openStart);
|
|
1019
|
+
i = opened.closesSameLine;
|
|
1020
|
+
cur = null;
|
|
1021
|
+
} else {
|
|
1022
|
+
code += " ".repeat(line.length - opened.openStart);
|
|
1023
|
+
i = line.length;
|
|
1024
|
+
cur = opened.state;
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
return { code, state: cur };
|
|
1028
|
+
}
|
|
1029
|
+
function makeSpanSymbol(filePath, name, kind, span, parent = "", lines, style) {
|
|
1030
|
+
return {
|
|
1031
|
+
filePath,
|
|
1032
|
+
name,
|
|
1033
|
+
kind,
|
|
1034
|
+
lineStart: span.startLine,
|
|
1035
|
+
lineEnd: span.endLine,
|
|
1036
|
+
body: span.body,
|
|
1037
|
+
docstring: lines !== void 0 && style !== void 0 ? precedingDocComment(lines, span.startLine, style) : "",
|
|
1038
|
+
parent
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
function makeLineSymbol(filePath, name, kind, line, sig, parent, lines, style) {
|
|
1042
|
+
return {
|
|
1043
|
+
filePath,
|
|
1044
|
+
name,
|
|
1045
|
+
kind,
|
|
1046
|
+
lineStart: line,
|
|
1047
|
+
lineEnd: line,
|
|
1048
|
+
body: sig ?? "",
|
|
1049
|
+
docstring: lines !== void 0 && style !== void 0 ? precedingDocComment(lines, line, style) : "",
|
|
1050
|
+
parent: parent ?? ""
|
|
1051
|
+
};
|
|
1052
|
+
}
|
|
1053
|
+
function makeSymbolEmitter(symbols, sections, seen, filePath, maxSymbols = 1e4, maxHeadingLen = 120) {
|
|
1054
|
+
return function emit(name, kind, line) {
|
|
1055
|
+
if (!name || name.length > maxHeadingLen) return;
|
|
1056
|
+
if (symbols.length >= maxSymbols) return;
|
|
1057
|
+
const key = `${name}\0${kind}\0${line}`;
|
|
1058
|
+
if (seen.has(key)) return;
|
|
1059
|
+
seen.add(key);
|
|
1060
|
+
symbols.push({
|
|
1061
|
+
filePath,
|
|
1062
|
+
name,
|
|
1063
|
+
kind,
|
|
1064
|
+
lineStart: line,
|
|
1065
|
+
lineEnd: line,
|
|
1066
|
+
body: "",
|
|
1067
|
+
docstring: "",
|
|
1068
|
+
parent: ""
|
|
1069
|
+
});
|
|
1070
|
+
sections.push({ heading: name, level: 1, line, endLine: line });
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
function assignFlatEndLines(sections, totalLines) {
|
|
1074
|
+
for (let i = 0; i < sections.length; i++) {
|
|
1075
|
+
const s = sections[i];
|
|
1076
|
+
if (s === void 0) continue;
|
|
1077
|
+
let j = i + 1;
|
|
1078
|
+
while (j < sections.length && (sections[j]?.line ?? 0) <= s.line) j++;
|
|
1079
|
+
const next = sections[j];
|
|
1080
|
+
const end = next !== void 0 ? next.line - 1 : totalLines;
|
|
1081
|
+
s.endLine = end < s.line ? s.line : end;
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
function propagateEndLinesToSymbols(symbols, sections) {
|
|
1085
|
+
const sectionMap = /* @__PURE__ */ new Map();
|
|
1086
|
+
for (const sec of sections) {
|
|
1087
|
+
const key = `${sec.heading}\0${sec.line}`;
|
|
1088
|
+
const queue = sectionMap.get(key);
|
|
1089
|
+
if (queue !== void 0) queue.push(sec.endLine);
|
|
1090
|
+
else sectionMap.set(key, [sec.endLine]);
|
|
1091
|
+
}
|
|
1092
|
+
return symbols.map((sym) => {
|
|
1093
|
+
const key = `${sym.name}\0${sym.lineStart}`;
|
|
1094
|
+
const endLine = sectionMap.get(key)?.shift();
|
|
1095
|
+
if (endLine !== void 0 && endLine !== sym.lineEnd) {
|
|
1096
|
+
return { ...sym, lineEnd: endLine };
|
|
1097
|
+
}
|
|
1098
|
+
return sym;
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
function tripleQuoteDelimiters(opts) {
|
|
1102
|
+
const delims = [];
|
|
1103
|
+
if (opts?.tripleQuote === true) delims.push('"""');
|
|
1104
|
+
if (opts?.tripleSingleQuote === true) delims.push("'''");
|
|
1105
|
+
return delims;
|
|
1106
|
+
}
|
|
1107
|
+
function quoteRunLength(content, i) {
|
|
1108
|
+
let n = 0;
|
|
1109
|
+
while (content[i + n] === '"') n++;
|
|
1110
|
+
return n;
|
|
1111
|
+
}
|
|
1112
|
+
function skipRawStringQuotes(content, from, min) {
|
|
1113
|
+
return closingQuoteRunEnd(content, from, '"', min, "last");
|
|
1114
|
+
}
|
|
1115
|
+
function stepPowershellString(content, i, quote) {
|
|
1116
|
+
const ch = content[i];
|
|
1117
|
+
if (quote === '"' && ch === "`") return { next: i + 1, open: true };
|
|
1118
|
+
return { next: i, open: ch !== quote };
|
|
1119
|
+
}
|
|
1120
|
+
function opensCsharpVerbatimString(content, i) {
|
|
1121
|
+
const prev = content[i - 1];
|
|
1122
|
+
return prev === "@" || prev === "$" && content[i - 2] === "@";
|
|
1123
|
+
}
|
|
1124
|
+
function toLineCommentPrefixes(prefix) {
|
|
1125
|
+
if (prefix === void 0) return [];
|
|
1126
|
+
return typeof prefix === "string" ? [prefix] : prefix;
|
|
1127
|
+
}
|
|
1128
|
+
function atLineComment(content, i, prefixes, exceptions) {
|
|
1129
|
+
if (exceptions.some((e) => content.startsWith(e, i))) return false;
|
|
1130
|
+
return prefixes.some((prefix) => content.startsWith(prefix, i));
|
|
1131
|
+
}
|
|
1132
|
+
function skipBlockComment(content, start, block, nested) {
|
|
1133
|
+
let i = start + block[0].length;
|
|
1134
|
+
let depth = 1;
|
|
1135
|
+
while (i < content.length) {
|
|
1136
|
+
if (nested && content.startsWith(block[0], i)) {
|
|
1137
|
+
depth++;
|
|
1138
|
+
i += block[0].length;
|
|
1139
|
+
continue;
|
|
1140
|
+
}
|
|
1141
|
+
if (content.startsWith(block[1], i)) {
|
|
1142
|
+
depth--;
|
|
1143
|
+
i += block[1].length;
|
|
1144
|
+
if (depth === 0) return i;
|
|
1145
|
+
continue;
|
|
1146
|
+
}
|
|
1147
|
+
i++;
|
|
1148
|
+
}
|
|
1149
|
+
return -1;
|
|
1150
|
+
}
|
|
1151
|
+
function findMatchingBraceEndLine(content, openBraceIndex, totalLines, lineIndex, lineCommentPrefix, opts) {
|
|
1152
|
+
const linePrefixes = toLineCommentPrefixes(lineCommentPrefix);
|
|
1153
|
+
const lineExceptions = opts?.lineCommentExceptions ?? [];
|
|
1154
|
+
const block = opts?.blockComment;
|
|
1155
|
+
const backtick = opts?.backtickQuote === true;
|
|
1156
|
+
const escapes = opts?.stringEscapes ?? "backslash";
|
|
1157
|
+
const nestedBlock = opts?.nestedBlockComments === true;
|
|
1158
|
+
const rawString = opts?.rawStringQuotes === true;
|
|
1159
|
+
const rRaw = opts?.rRawStrings === true;
|
|
1160
|
+
const tripleDelims = tripleQuoteDelimiters(opts);
|
|
1161
|
+
const lineString = opts?.lineStringPrefix;
|
|
1162
|
+
let depth = 0;
|
|
1163
|
+
let quote = null;
|
|
1164
|
+
let verbatim = false;
|
|
1165
|
+
for (let i = openBraceIndex; i < content.length; i++) {
|
|
1166
|
+
const ch = content[i];
|
|
1167
|
+
if (quote !== null) {
|
|
1168
|
+
if (verbatim) {
|
|
1169
|
+
if (ch === quote) {
|
|
1170
|
+
if (content[i + 1] === quote) {
|
|
1171
|
+
i++;
|
|
1172
|
+
continue;
|
|
1173
|
+
}
|
|
1174
|
+
quote = null;
|
|
1175
|
+
verbatim = false;
|
|
1176
|
+
}
|
|
1177
|
+
continue;
|
|
1178
|
+
}
|
|
1179
|
+
if (escapes === "powershell") {
|
|
1180
|
+
const step = stepPowershellString(content, i, quote);
|
|
1181
|
+
i = step.next;
|
|
1182
|
+
if (!step.open) quote = null;
|
|
1183
|
+
continue;
|
|
1184
|
+
}
|
|
1185
|
+
if (ch === "\\") {
|
|
1186
|
+
i++;
|
|
1187
|
+
continue;
|
|
1188
|
+
}
|
|
1189
|
+
if (ch === quote) quote = null;
|
|
1190
|
+
continue;
|
|
1191
|
+
}
|
|
1192
|
+
if (block !== void 0 && content.startsWith(block[0], i)) {
|
|
1193
|
+
const end = skipBlockComment(content, i, block, nestedBlock);
|
|
1194
|
+
i = end === -1 ? content.length : end - 1;
|
|
1195
|
+
continue;
|
|
1196
|
+
}
|
|
1197
|
+
if (atLineComment(content, i, linePrefixes, lineExceptions)) {
|
|
1198
|
+
while (i < content.length && content[i] !== "\n") i++;
|
|
1199
|
+
continue;
|
|
1200
|
+
}
|
|
1201
|
+
if (lineString !== void 0 && content.startsWith(lineString, i)) {
|
|
1202
|
+
while (i < content.length && content[i] !== "\n") i++;
|
|
1203
|
+
continue;
|
|
1204
|
+
}
|
|
1205
|
+
if (rRaw) {
|
|
1206
|
+
const rOpen = matchRRawOpener(content, i);
|
|
1207
|
+
if (rOpen !== null) {
|
|
1208
|
+
const end = content.indexOf(rOpen.closer, rOpen.openerEnd);
|
|
1209
|
+
i = end === -1 ? content.length : end + rOpen.closer.length - 1;
|
|
1210
|
+
continue;
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
if (rawString && ch === '"') {
|
|
1214
|
+
const run = quoteRunLength(content, i);
|
|
1215
|
+
if (run >= 3) {
|
|
1216
|
+
const end = skipRawStringQuotes(content, i + run, run);
|
|
1217
|
+
i = end === -1 ? content.length : end - 1;
|
|
1218
|
+
continue;
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
const tripleAt = tripleDelims.find((t) => content.startsWith(t, i));
|
|
1222
|
+
if (tripleAt !== void 0) {
|
|
1223
|
+
const end = closingQuoteRunEnd(content, i + 3, tripleAt[0] ?? '"', 3, opts?.tripleQuoteRunClose ?? "last");
|
|
1224
|
+
i = end === -1 ? content.length : end - 1;
|
|
1225
|
+
continue;
|
|
1226
|
+
}
|
|
1227
|
+
if (ch === '"' || ch === "'" || backtick && ch === "`") {
|
|
1228
|
+
quote = ch;
|
|
1229
|
+
verbatim = escapes === "csharp" && ch === '"' && opensCsharpVerbatimString(content, i);
|
|
1230
|
+
continue;
|
|
1231
|
+
}
|
|
1232
|
+
if (ch === "{") depth++;
|
|
1233
|
+
else if (ch === "}") {
|
|
1234
|
+
depth--;
|
|
1235
|
+
if (depth === 0) {
|
|
1236
|
+
return offsetToLine(lineIndex, i);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
return opts?.noMatchValue ?? totalLines;
|
|
1241
|
+
}
|
|
1242
|
+
function assignBraceBlockSpans(symbols, content, opts = {}) {
|
|
1243
|
+
const lineCommentPrefix = opts.lineComment;
|
|
1244
|
+
const stringEscapes = opts.stringEscapes ?? "backslash";
|
|
1245
|
+
const nestedBlockComments = opts.nestedBlockComments ?? false;
|
|
1246
|
+
const tripleQuote = opts.tripleQuote ?? false;
|
|
1247
|
+
const lineStringPrefix = opts.lineStringPrefix;
|
|
1248
|
+
const firstLinePrefix = toLineCommentPrefixes(lineCommentPrefix)[0];
|
|
1249
|
+
if (symbols.length === 0) return [...symbols];
|
|
1250
|
+
const lines = content.split("\n");
|
|
1251
|
+
const totalLines = lines.length;
|
|
1252
|
+
const lineIndex = buildLineIndex(content);
|
|
1253
|
+
const starts = [...new Set(symbols.map((s) => s.lineStart))].sort((a, b) => a - b);
|
|
1254
|
+
const scanContent = opts.multilineLang === void 0 ? content : maskMultilineStrings(content, opts.multilineLang);
|
|
1255
|
+
const blockComment = opts.blockComment !== void 0 ? opts.blockComment ?? void 0 : firstLinePrefix === "//" ? ["/*", "*/"] : firstLinePrefix === "#" ? ["<#", "#>"] : void 0;
|
|
1256
|
+
const scanOpts = {
|
|
1257
|
+
noMatchValue: -1,
|
|
1258
|
+
stringEscapes,
|
|
1259
|
+
tripleQuote,
|
|
1260
|
+
rawStringQuotes: opts.rawStringQuotes ?? false,
|
|
1261
|
+
tripleSingleQuote: opts.tripleSingleQuote ?? false,
|
|
1262
|
+
tripleQuoteRunClose: opts.tripleQuoteRunClose ?? "last",
|
|
1263
|
+
...blockComment === void 0 ? {} : { blockComment, nestedBlockComments },
|
|
1264
|
+
...lineStringPrefix === void 0 ? {} : { lineStringPrefix },
|
|
1265
|
+
...opts.lineCommentExceptions === void 0 ? {} : { lineCommentExceptions: opts.lineCommentExceptions }
|
|
1266
|
+
};
|
|
1267
|
+
return symbols.map((sym) => {
|
|
1268
|
+
if (sym.lineEnd !== sym.lineStart) return sym;
|
|
1269
|
+
const nextStart = starts.find((s) => s > sym.lineStart);
|
|
1270
|
+
const lastSearchLine = Math.min(nextStart !== void 0 ? nextStart - 1 : totalLines, sym.lineStart + BRACE_SEARCH_MAX_LINES);
|
|
1271
|
+
const openIndex = findBlockOpenBrace(scanContent, lineIndex, sym.lineStart, lastSearchLine, lineCommentPrefix, scanOpts);
|
|
1272
|
+
if (openIndex === null) return sym;
|
|
1273
|
+
const endLine = findMatchingBraceEndLine(
|
|
1274
|
+
scanContent,
|
|
1275
|
+
openIndex,
|
|
1276
|
+
totalLines,
|
|
1277
|
+
lineIndex,
|
|
1278
|
+
lineCommentPrefix,
|
|
1279
|
+
scanOpts
|
|
1280
|
+
);
|
|
1281
|
+
if (endLine <= sym.lineStart) return sym;
|
|
1282
|
+
return { ...sym, lineEnd: endLine, body: lines.slice(sym.lineStart - 1, endLine).join("\n") };
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
var BRACE_SEARCH_MAX_LINES = 10;
|
|
1286
|
+
function maskMultilineStrings(content, lang) {
|
|
1287
|
+
let state = null;
|
|
1288
|
+
const parts = [];
|
|
1289
|
+
let pos = 0;
|
|
1290
|
+
for (; ; ) {
|
|
1291
|
+
const nl = content.indexOf("\n", pos);
|
|
1292
|
+
const end = nl === -1 ? content.length : nl;
|
|
1293
|
+
const lineEnd = end > pos && content[end - 1] === "\r" ? end - 1 : end;
|
|
1294
|
+
const masked = stripMultilineStringSpan(content.slice(pos, lineEnd), state, lang);
|
|
1295
|
+
state = masked.state;
|
|
1296
|
+
parts.push(masked.code, content.slice(lineEnd, end));
|
|
1297
|
+
if (nl === -1) break;
|
|
1298
|
+
parts.push("\n");
|
|
1299
|
+
pos = nl + 1;
|
|
1300
|
+
}
|
|
1301
|
+
return parts.join("");
|
|
1302
|
+
}
|
|
1303
|
+
function findBlockOpenBrace(content, lineIndex, startLine, lastSearchLine, lineCommentPrefix, opts) {
|
|
1304
|
+
const blockComment = opts?.blockComment;
|
|
1305
|
+
const stringEscapes = opts?.stringEscapes ?? "backslash";
|
|
1306
|
+
const nestedBlockComments = opts?.nestedBlockComments === true;
|
|
1307
|
+
const rawString = opts?.rawStringQuotes === true;
|
|
1308
|
+
const tripleDelims = tripleQuoteDelimiters(opts);
|
|
1309
|
+
const lineString = opts?.lineStringPrefix;
|
|
1310
|
+
const linePrefixes = toLineCommentPrefixes(lineCommentPrefix);
|
|
1311
|
+
const lineExceptions = opts?.lineCommentExceptions ?? [];
|
|
1312
|
+
const from = lineIndex[startLine - 1];
|
|
1313
|
+
if (from === void 0) return null;
|
|
1314
|
+
const to = lineIndex[lastSearchLine] ?? content.length;
|
|
1315
|
+
let quote = null;
|
|
1316
|
+
let parenDepth = 0;
|
|
1317
|
+
let linesSeen = 0;
|
|
1318
|
+
let atLineStart = false;
|
|
1319
|
+
let verbatim = false;
|
|
1320
|
+
for (let i = from; i < to; i++) {
|
|
1321
|
+
const ch = content[i];
|
|
1322
|
+
if (ch === void 0) break;
|
|
1323
|
+
if (quote !== null) {
|
|
1324
|
+
if (verbatim) {
|
|
1325
|
+
if (ch === quote) {
|
|
1326
|
+
if (content[i + 1] === quote) {
|
|
1327
|
+
i++;
|
|
1328
|
+
continue;
|
|
1329
|
+
}
|
|
1330
|
+
quote = null;
|
|
1331
|
+
verbatim = false;
|
|
1332
|
+
}
|
|
1333
|
+
continue;
|
|
1334
|
+
}
|
|
1335
|
+
if (stringEscapes === "powershell") {
|
|
1336
|
+
const step = stepPowershellString(content, i, quote);
|
|
1337
|
+
i = step.next;
|
|
1338
|
+
if (!step.open) quote = null;
|
|
1339
|
+
continue;
|
|
1340
|
+
}
|
|
1341
|
+
if (ch === "\\") {
|
|
1342
|
+
i++;
|
|
1343
|
+
continue;
|
|
1344
|
+
}
|
|
1345
|
+
if (ch === quote) quote = null;
|
|
1346
|
+
continue;
|
|
1347
|
+
}
|
|
1348
|
+
if (ch === "\n") {
|
|
1349
|
+
linesSeen++;
|
|
1350
|
+
atLineStart = true;
|
|
1351
|
+
continue;
|
|
1352
|
+
}
|
|
1353
|
+
if (blockComment !== void 0 && content.startsWith(blockComment[0], i)) {
|
|
1354
|
+
const end = skipBlockComment(content, i, blockComment, nestedBlockComments);
|
|
1355
|
+
if (end === -1) return null;
|
|
1356
|
+
i = end - 1;
|
|
1357
|
+
continue;
|
|
1358
|
+
}
|
|
1359
|
+
if (atLineComment(content, i, linePrefixes, lineExceptions)) {
|
|
1360
|
+
while (i + 1 < to && content[i + 1] !== "\n") i++;
|
|
1361
|
+
continue;
|
|
1362
|
+
}
|
|
1363
|
+
if (atLineStart && !/\s/.test(ch)) {
|
|
1364
|
+
atLineStart = false;
|
|
1365
|
+
if (parenDepth === 0 && linesSeen >= 1 && startsWithBlockKeyword(content, i, to)) return null;
|
|
1366
|
+
}
|
|
1367
|
+
if (lineString !== void 0 && content.startsWith(lineString, i)) {
|
|
1368
|
+
while (i + 1 < to && content[i + 1] !== "\n") i++;
|
|
1369
|
+
continue;
|
|
1370
|
+
}
|
|
1371
|
+
if (rawString && ch === '"') {
|
|
1372
|
+
const run = quoteRunLength(content, i);
|
|
1373
|
+
if (run >= 3) {
|
|
1374
|
+
const end = skipRawStringQuotes(content, i + run, run);
|
|
1375
|
+
if (end === -1) return null;
|
|
1376
|
+
i = end - 1;
|
|
1377
|
+
continue;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
const tripleAt = tripleDelims.find((t) => content.startsWith(t, i));
|
|
1381
|
+
if (tripleAt !== void 0) {
|
|
1382
|
+
const end = closingQuoteRunEnd(content, i + 3, tripleAt[0] ?? '"', 3, opts?.tripleQuoteRunClose ?? "last");
|
|
1383
|
+
if (end === -1) return null;
|
|
1384
|
+
i = end - 1;
|
|
1385
|
+
continue;
|
|
1386
|
+
}
|
|
1387
|
+
if (ch === '"' || ch === "'") {
|
|
1388
|
+
quote = ch;
|
|
1389
|
+
verbatim = stringEscapes === "csharp" && ch === '"' && opensCsharpVerbatimString(content, i);
|
|
1390
|
+
continue;
|
|
1391
|
+
}
|
|
1392
|
+
if (ch === "(" || ch === "[") parenDepth++;
|
|
1393
|
+
else if (ch === ")" || ch === "]") {
|
|
1394
|
+
if (parenDepth > 0) parenDepth--;
|
|
1395
|
+
} else if (ch === ";") return null;
|
|
1396
|
+
else if (ch === "}" && parenDepth === 0) return null;
|
|
1397
|
+
else if (ch === "{") return i;
|
|
1398
|
+
}
|
|
1399
|
+
return null;
|
|
1400
|
+
}
|
|
1401
|
+
var BLOCK_OPENING_KEYWORDS = /* @__PURE__ */ new Set([
|
|
1402
|
+
"if",
|
|
1403
|
+
"for",
|
|
1404
|
+
"while",
|
|
1405
|
+
"do",
|
|
1406
|
+
"switch",
|
|
1407
|
+
"when",
|
|
1408
|
+
"match",
|
|
1409
|
+
"try",
|
|
1410
|
+
"foreach",
|
|
1411
|
+
"loop",
|
|
1412
|
+
"guard",
|
|
1413
|
+
"repeat",
|
|
1414
|
+
"unless",
|
|
1415
|
+
"until"
|
|
1416
|
+
]);
|
|
1417
|
+
function startsWithBlockKeyword(content, i, to) {
|
|
1418
|
+
const first = content[i];
|
|
1419
|
+
if (first === void 0 || !/[A-Za-z_]/.test(first)) return false;
|
|
1420
|
+
let j = i + 1;
|
|
1421
|
+
while (j < to && /[A-Za-z0-9_]/.test(content[j])) j++;
|
|
1422
|
+
return BLOCK_OPENING_KEYWORDS.has(content.slice(i, j));
|
|
1423
|
+
}
|
|
1424
|
+
function lastContentLine(rawLines) {
|
|
1425
|
+
let n = rawLines.length;
|
|
1426
|
+
while (n > 0 && rawLines[n - 1].trim() === "") n--;
|
|
1427
|
+
return Math.max(1, n);
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
// src/languages/ini_idx.ts
|
|
1431
|
+
init_define_import_meta_env();
|
|
1432
|
+
var MAX_SECTIONS = 200;
|
|
1433
|
+
var MAX_HEADING_LEN = 200;
|
|
1434
|
+
var MAX_ENV_KEYS = 200;
|
|
1435
|
+
var HEADER_RE = /^\[([^\]\r\n]+)\]\s*(?:[;#].*)?$/;
|
|
1436
|
+
var ENV_KEY_RE = /^(?:export\s+)?([A-Za-z_][\w.-]*)\s*(?:=|:(?!\/\/))/;
|
|
1437
|
+
function extractIni(content, filePath) {
|
|
1438
|
+
const symbols = [];
|
|
1439
|
+
const sections = [];
|
|
1440
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1441
|
+
const lines = content.split(/\r?\n/);
|
|
1442
|
+
const totalLines = countContentLines(content);
|
|
1443
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1444
|
+
if (symbols.length >= MAX_SECTIONS) break;
|
|
1445
|
+
const line = lines[i] ?? "";
|
|
1446
|
+
if (!line || line[0] !== "[") continue;
|
|
1447
|
+
const m = HEADER_RE.exec(line);
|
|
1448
|
+
if (m === null) continue;
|
|
1449
|
+
const name = m[1]?.trim() ?? "";
|
|
1450
|
+
if (!name || name.length > MAX_HEADING_LEN) continue;
|
|
1451
|
+
const key = `${name}\0${i + 1}`;
|
|
1452
|
+
if (seen.has(key)) continue;
|
|
1453
|
+
seen.add(key);
|
|
1454
|
+
symbols.push(makeLineSymbol(filePath, name, "ini_section", i + 1));
|
|
1455
|
+
sections.push({ heading: name, level: 1, line: i + 1, endLine: i + 1 });
|
|
1456
|
+
}
|
|
1457
|
+
sections.sort((a, b) => a.line - b.line);
|
|
1458
|
+
assignFlatEndLines(sections, totalLines);
|
|
1459
|
+
return propagateEndLinesToSymbols(symbols, sections);
|
|
1460
|
+
}
|
|
1461
|
+
function _isEscapedQuote(line, i, q) {
|
|
1462
|
+
if (q === "'") return false;
|
|
1463
|
+
let backslashes = 0;
|
|
1464
|
+
let j = i - 1;
|
|
1465
|
+
while (j >= 0 && line[j] === "\\") {
|
|
1466
|
+
backslashes++;
|
|
1467
|
+
j--;
|
|
1468
|
+
}
|
|
1469
|
+
return backslashes % 2 === 1;
|
|
1470
|
+
}
|
|
1471
|
+
function _lineClosesQuote(line, q) {
|
|
1472
|
+
for (let i = 0; i < line.length; i++) {
|
|
1473
|
+
if (line[i] === q && !_isEscapedQuote(line, i, q)) return true;
|
|
1474
|
+
}
|
|
1475
|
+
return false;
|
|
1476
|
+
}
|
|
1477
|
+
function _detectOpenQuote(value) {
|
|
1478
|
+
const trimmed = value.replace(/^\s+/, "");
|
|
1479
|
+
const q = trimmed[0];
|
|
1480
|
+
if (q !== '"' && q !== "'") return null;
|
|
1481
|
+
for (let i = 1; i < trimmed.length; i++) {
|
|
1482
|
+
if (trimmed[i] === q && !_isEscapedQuote(trimmed, i, q)) return null;
|
|
1483
|
+
}
|
|
1484
|
+
return q;
|
|
1485
|
+
}
|
|
1486
|
+
function extractEnv(content, filePath) {
|
|
1487
|
+
const symbols = [];
|
|
1488
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1489
|
+
const lines = content.split(/\r?\n/);
|
|
1490
|
+
let openQuote = null;
|
|
1491
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1492
|
+
if (symbols.length >= MAX_ENV_KEYS) break;
|
|
1493
|
+
const line = lines[i] ?? "";
|
|
1494
|
+
if (openQuote !== null) {
|
|
1495
|
+
if (_lineClosesQuote(line, openQuote)) openQuote = null;
|
|
1496
|
+
continue;
|
|
1497
|
+
}
|
|
1498
|
+
const trimmed = line.replace(/^[ \t]+/, "");
|
|
1499
|
+
if (!trimmed || trimmed[0] === "#" || trimmed[0] === ";") continue;
|
|
1500
|
+
const m = ENV_KEY_RE.exec(trimmed);
|
|
1501
|
+
if (m === null) continue;
|
|
1502
|
+
const name = m[1]?.trim() ?? "";
|
|
1503
|
+
if (!name || name.length > MAX_HEADING_LEN) continue;
|
|
1504
|
+
const key = `${name}\0${i + 1}`;
|
|
1505
|
+
if (seen.has(key)) continue;
|
|
1506
|
+
seen.add(key);
|
|
1507
|
+
symbols.push(makeLineSymbol(filePath, name, "env_key", i + 1));
|
|
1508
|
+
openQuote = _detectOpenQuote(trimmed.slice(m[0].length));
|
|
1509
|
+
}
|
|
1510
|
+
return symbols;
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
// src/languages/sniff.ts
|
|
1514
|
+
init_define_import_meta_env();
|
|
1515
|
+
var SNIFF_CHARS = 8192;
|
|
1516
|
+
var ABL_MARKER_RES = [
|
|
1517
|
+
/^&ANALYZE-SUSPEND\b/i,
|
|
1518
|
+
/^&(?:SCOPED|GLOBAL)-DEFINE\s/i,
|
|
1519
|
+
/^(?:ROUTINE|BLOCK)-LEVEL\s+ON\s+ERROR\s+UNDO\b/i,
|
|
1520
|
+
/^DEF(?:INE)?\s+(?:NEW\s+)?(?:GLOBAL\s+)?(?:SHARED\s+)?(?:VAR|VARIABLE|TEMP-TABLE|BUFFER|QUERY|STREAM|DATASET|FRAME|(?:INPUT|OUTPUT|INPUT-OUTPUT)\s+PARAM(?:ETER)?)\s/i,
|
|
1521
|
+
/^FUNCTION\s+[\w-]+\s+RETURNS\s/i,
|
|
1522
|
+
/^FOR\s+EACH\s/i,
|
|
1523
|
+
/^END\s+(?:PROCEDURE|FUNCTION|CLASS|INTERFACE|METHOD|CONSTRUCTOR)\s*\.$/i,
|
|
1524
|
+
/^USING\s+[\w.*-]+(?:\s+FROM\s+(?:ASSEMBLY|PROPATH))?\s*\.$/i
|
|
1525
|
+
];
|
|
1526
|
+
var ABL_HEADER_RE = /^(?:PROCEDURE\s+[\w-]+|(?:CLASS|INTERFACE)\s+[\w.-]+)(?:\s|:)/i;
|
|
1527
|
+
var ABL_SNIFF_CHARS = SNIFF_CHARS;
|
|
1528
|
+
function isAblSource(content) {
|
|
1529
|
+
const head = content.slice(0, ABL_SNIFF_CHARS);
|
|
1530
|
+
if (head.includes("\0")) return false;
|
|
1531
|
+
for (const raw of head.split(/\r?\n/)) {
|
|
1532
|
+
const line = raw.trim();
|
|
1533
|
+
if (line === "") continue;
|
|
1534
|
+
if (ABL_MARKER_RES.some((re) => re.test(line))) return true;
|
|
1535
|
+
if (ABL_HEADER_RE.test(line) && line.endsWith(":")) return true;
|
|
1536
|
+
}
|
|
1537
|
+
return false;
|
|
1538
|
+
}
|
|
1539
|
+
var SNIFF_FUNCTION_RE = /^function\b\s*(?:(?:\[[\w\s,~]*\]|[A-Za-z]\w*)\s*=\s*)?[A-Za-z]\w*(?:\.[A-Za-z]\w*)?\s*(?:\(|[%#;,]|$)/;
|
|
1540
|
+
var SNIFF_CLASSDEF_RE = /^classdef\b\s*(?:\([^)]*\)\s*)?[A-Za-z]\w*\s*(?:<|[%#]|$)/;
|
|
1541
|
+
function isMatlabSource(content) {
|
|
1542
|
+
for (const raw of content.slice(0, SNIFF_CHARS).split("\n")) {
|
|
1543
|
+
const line = raw.trim();
|
|
1544
|
+
if (SNIFF_FUNCTION_RE.test(line) || SNIFF_CLASSDEF_RE.test(line)) return true;
|
|
1545
|
+
}
|
|
1546
|
+
return false;
|
|
1547
|
+
}
|
|
1548
|
+
function isObjcSource(content) {
|
|
1549
|
+
return /^[ \t]*(?:#[ \t]*import[ \t]*[<"]|@(?:interface|implementation|protocol)\b)/m.test(content.slice(0, SNIFF_CHARS));
|
|
1550
|
+
}
|
|
1551
|
+
function isObjcHeader(content) {
|
|
1552
|
+
return /^[ \t]*@(?:interface|protocol)\b/m.test(content.slice(0, SNIFF_CHARS));
|
|
1553
|
+
}
|
|
1554
|
+
function isPascalSource(content) {
|
|
1555
|
+
const head = content.slice(0, SNIFF_CHARS);
|
|
1556
|
+
let i = 0;
|
|
1557
|
+
for (; ; ) {
|
|
1558
|
+
while (i < head.length && /\s/.test(head[i])) i++;
|
|
1559
|
+
if (head[i] === "{") {
|
|
1560
|
+
const end = head.indexOf("}", i);
|
|
1561
|
+
if (end < 0) return false;
|
|
1562
|
+
i = end + 1;
|
|
1563
|
+
} else if (head.startsWith("(*", i)) {
|
|
1564
|
+
const end = head.indexOf("*)", i);
|
|
1565
|
+
if (end < 0) return false;
|
|
1566
|
+
i = end + 2;
|
|
1567
|
+
} else if (head.startsWith("//", i)) {
|
|
1568
|
+
const end = head.indexOf("\n", i);
|
|
1569
|
+
if (end < 0) return false;
|
|
1570
|
+
i = end + 1;
|
|
1571
|
+
} else {
|
|
1572
|
+
break;
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
return /^(?:unit|program|library)[ \t\r\n]+[A-Za-z_][\w.]*[ \t\r\n]*[;(]/i.test(head.slice(i, i + 300));
|
|
1576
|
+
}
|
|
1577
|
+
var PERL_MARKER_RE = /^(?:#!.*\bperl\b|[ \t]*use[ \t]+(?:strict|warnings|Test::More|Test2::V0|Test::Simple)\b|[ \t]*package[ \t]+[\w:]+[ \t]*;|[ \t]*my[ \t]+[$@%]|[ \t]*sub[ \t]+\w+[ \t]*\{)/m;
|
|
1578
|
+
function isPerlSource(content) {
|
|
1579
|
+
const head = content.slice(0, SNIFF_CHARS);
|
|
1580
|
+
return PERL_MARKER_RE.test(head) && !/^[ \t]*use[ \t]+v6\b/m.test(head);
|
|
1581
|
+
}
|
|
1582
|
+
function isPrologSource(content) {
|
|
1583
|
+
const head = content.slice(0, SNIFF_CHARS);
|
|
1584
|
+
if (PERL_MARKER_RE.test(head)) return false;
|
|
1585
|
+
return /^:-/m.test(head) || /^[a-z]\w*(?:\([^()\n]*\))?[ \t]*:-/m.test(head);
|
|
1586
|
+
}
|
|
1587
|
+
var LATEX_CLASS_MARKER_RE = /\\(?:ProvidesClass|documentclass)\b/;
|
|
1588
|
+
function isLatexClassFile(content) {
|
|
1589
|
+
return LATEX_CLASS_MARKER_RE.test(content.slice(0, SNIFF_CHARS));
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
export {
|
|
1593
|
+
precedingDocComment,
|
|
1594
|
+
buildLineIndex,
|
|
1595
|
+
offsetToLine,
|
|
1596
|
+
stripCstyleComments,
|
|
1597
|
+
stripXmlComments,
|
|
1598
|
+
scanQuotedStringEnd,
|
|
1599
|
+
stripJsComments,
|
|
1600
|
+
stripHashComments,
|
|
1601
|
+
maskHtmlNoise,
|
|
1602
|
+
findHtmlHeadingMatches,
|
|
1603
|
+
isInsideStringLiteral,
|
|
1604
|
+
stripBlockCommentSpan,
|
|
1605
|
+
stripNestedBlockCommentSpan,
|
|
1606
|
+
stripLineComment,
|
|
1607
|
+
stripStringLiterals,
|
|
1608
|
+
matchRRawOpener,
|
|
1609
|
+
matchGroovySlashy,
|
|
1610
|
+
matchBashHeredocOpener,
|
|
1611
|
+
stripMultilineStringSpan,
|
|
1612
|
+
makeSpanSymbol,
|
|
1613
|
+
makeLineSymbol,
|
|
1614
|
+
makeSymbolEmitter,
|
|
1615
|
+
assignFlatEndLines,
|
|
1616
|
+
propagateEndLinesToSymbols,
|
|
1617
|
+
findMatchingBraceEndLine,
|
|
1618
|
+
assignBraceBlockSpans,
|
|
1619
|
+
lastContentLine,
|
|
1620
|
+
extractIni,
|
|
1621
|
+
_lineClosesQuote,
|
|
1622
|
+
_detectOpenQuote,
|
|
1623
|
+
extractEnv,
|
|
1624
|
+
isAblSource,
|
|
1625
|
+
isMatlabSource,
|
|
1626
|
+
isObjcSource,
|
|
1627
|
+
isObjcHeader,
|
|
1628
|
+
isPascalSource,
|
|
1629
|
+
isPerlSource,
|
|
1630
|
+
isPrologSource,
|
|
1631
|
+
isLatexClassFile
|
|
1632
|
+
};
|