tokless 0.4.0 → 0.5.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.
@@ -0,0 +1,722 @@
1
+ 'use strict';
2
+
3
+ const REGEX_PREV_KEYWORDS = new Set([
4
+ 'return',
5
+ 'throw',
6
+ 'case',
7
+ 'typeof',
8
+ 'void',
9
+ 'delete',
10
+ 'in',
11
+ 'instanceof',
12
+ 'new',
13
+ 'await',
14
+ 'yield',
15
+ 'else',
16
+ 'do',
17
+ 'of',
18
+ ]);
19
+
20
+ const DEFAULT_LEXER_CONFIG = {
21
+ lineComments: ['//'],
22
+ blockComments: [['/*', '*/']],
23
+ nestedBlockComments: false,
24
+ strings: ['"', "'"],
25
+ templateBacktick: false,
26
+ templateDollarString: false,
27
+ rawBacktick: false,
28
+ tripleQuotes: false,
29
+ rustRawStrings: false,
30
+ rustLifetimes: false,
31
+ cSharpVerbatimStrings: false,
32
+ regexLiterals: false,
33
+ charSingleQuote: false,
34
+ };
35
+
36
+ const LEXER_PRESETS = {
37
+ js: {
38
+ ...DEFAULT_LEXER_CONFIG,
39
+ templateBacktick: true,
40
+ regexLiterals: true,
41
+ },
42
+ java: {
43
+ ...DEFAULT_LEXER_CONFIG,
44
+ tripleQuotes: ['"""'],
45
+ charSingleQuote: true,
46
+ },
47
+ c: {
48
+ ...DEFAULT_LEXER_CONFIG,
49
+ cSharpVerbatimStrings: true,
50
+ charSingleQuote: true,
51
+ },
52
+ kotlin: {
53
+ ...DEFAULT_LEXER_CONFIG,
54
+ nestedBlockComments: true,
55
+ strings: ['"'],
56
+ templateDollarString: true,
57
+ tripleQuotes: ['"""'],
58
+ charSingleQuote: true,
59
+ },
60
+ go: {
61
+ ...DEFAULT_LEXER_CONFIG,
62
+ rawBacktick: true,
63
+ charSingleQuote: true,
64
+ },
65
+ rust: {
66
+ ...DEFAULT_LEXER_CONFIG,
67
+ nestedBlockComments: true,
68
+ strings: ['"'],
69
+ rustRawStrings: true,
70
+ rustLifetimes: true,
71
+ },
72
+ python: {
73
+ ...DEFAULT_LEXER_CONFIG,
74
+ lineComments: ['#'],
75
+ blockComments: [],
76
+ tripleQuotes: ['"""', "'''"],
77
+ },
78
+ };
79
+
80
+ function resolveLexerConfig(configOrPreset) {
81
+ if (!configOrPreset) return DEFAULT_LEXER_CONFIG;
82
+ if (typeof configOrPreset === 'string') {
83
+ return LEXER_PRESETS[configOrPreset] || DEFAULT_LEXER_CONFIG;
84
+ }
85
+ return { ...DEFAULT_LEXER_CONFIG, ...configOrPreset };
86
+ }
87
+
88
+ function estimateTokens(text) {
89
+ if (!text) return 0;
90
+ let cjk = 0;
91
+ for (let i = 0; i < text.length; i++) {
92
+ const code = text.charCodeAt(i);
93
+ if (
94
+ (code >= 0x4e00 && code <= 0x9fff) ||
95
+ (code >= 0x3400 && code <= 0x4dbf) ||
96
+ (code >= 0x3000 && code <= 0x303f) ||
97
+ (code >= 0xff00 && code <= 0xffef)
98
+ ) {
99
+ cjk++;
100
+ }
101
+ }
102
+ const nonCjk = text.length - cjk;
103
+ return Math.max(1, Math.ceil(cjk * 1.5 + nonCjk / 3.8));
104
+ }
105
+
106
+ function splitLines(content) {
107
+ if (!content) return [];
108
+ const normalized = content.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
109
+ const lines = normalized.split('\n');
110
+ if (lines.length > 0 && lines[lines.length - 1] === '') {
111
+ lines.pop();
112
+ }
113
+ return lines;
114
+ }
115
+
116
+ function formatInt(n) {
117
+ return Number(n || 0).toLocaleString('en-US');
118
+ }
119
+
120
+ function matchPrefixAt(str, pos, prefixes) {
121
+ if (!prefixes || prefixes.length === 0) return null;
122
+ for (let i = 0; i < prefixes.length; i++) {
123
+ const p = prefixes[i];
124
+ if (p && str.startsWith(p, pos)) return p;
125
+ }
126
+ return null;
127
+ }
128
+
129
+ function matchPairStartAt(str, pos, pairs) {
130
+ if (!pairs || pairs.length === 0) return null;
131
+ for (let i = 0; i < pairs.length; i++) {
132
+ const pair = pairs[i];
133
+ if (pair && pair[0] && str.startsWith(pair[0], pos)) return pair;
134
+ }
135
+ return null;
136
+ }
137
+
138
+ function preprocessBraceLines(lines, configOrPreset) {
139
+ const cfg = resolveLexerConfig(configOrPreset);
140
+ const tripleList = Array.isArray(cfg.tripleQuotes)
141
+ ? cfg.tripleQuotes
142
+ : cfg.tripleQuotes
143
+ ? ['"""', "'''"]
144
+ : [];
145
+ const stringSet = new Set(cfg.strings || []);
146
+
147
+ const result = new Array(lines.length);
148
+ let braceDepth = 0;
149
+ let parenDepth = 0;
150
+ let bracketDepth = 0;
151
+
152
+ let activeBlockComment = null;
153
+ let blockCommentNested = 0;
154
+ let activeTripleQuote = null;
155
+ let inBacktick = false;
156
+ let inCSharpVerbatim = false;
157
+ let inRustRawString = false;
158
+ let rustRawHashes = 0;
159
+ const templateExprStack = [];
160
+
161
+ for (let lineIdx = 0; lineIdx < lines.length; lineIdx++) {
162
+ const raw = lines[lineIdx];
163
+ const len = raw.length;
164
+ const out = [];
165
+ const braceStart = braceDepth;
166
+ const parenStart = parenDepth;
167
+ const bracketStart = bracketDepth;
168
+
169
+ let inLineComment = false;
170
+ let inStringQuote = null;
171
+ let inRegex = false;
172
+ let inRegexClass = false;
173
+ let prevSigToken = '';
174
+
175
+ for (let i = 0; i < len; i++) {
176
+ const ch = raw[i];
177
+ const next = i + 1 < len ? raw[i + 1] : '';
178
+
179
+ if (inLineComment) {
180
+ out.push(' ');
181
+ continue;
182
+ }
183
+
184
+ if (activeBlockComment) {
185
+ const [openTok, closeTok] = activeBlockComment;
186
+ if (cfg.nestedBlockComments && raw.startsWith(openTok, i)) {
187
+ blockCommentNested++;
188
+ out.push(' '.repeat(openTok.length));
189
+ i += openTok.length - 1;
190
+ continue;
191
+ }
192
+ if (raw.startsWith(closeTok, i)) {
193
+ out.push(' '.repeat(closeTok.length));
194
+ i += closeTok.length - 1;
195
+ if (cfg.nestedBlockComments && blockCommentNested > 0) {
196
+ blockCommentNested--;
197
+ } else {
198
+ activeBlockComment = null;
199
+ }
200
+ continue;
201
+ }
202
+ out.push(' ');
203
+ continue;
204
+ }
205
+
206
+ // 陷阱: Java 15+ / Kotlin / Python 多行三引号文本块内常含未闭合 `"` 或 `{`,必须跨行吞掉内部字符并保留等宽空格对齐列索引
207
+ if (activeTripleQuote) {
208
+ if (!cfg.templateDollarString && ch === '\\') {
209
+ out.push(' ');
210
+ i++;
211
+ continue;
212
+ }
213
+ if (cfg.templateDollarString && ch === '$' && next === '{') {
214
+ templateExprStack.push({ depth: braceDepth, resume: 'triple', quote: activeTripleQuote });
215
+ braceDepth++;
216
+ out.push(' ');
217
+ out.push('{');
218
+ i++;
219
+ activeTripleQuote = null;
220
+ prevSigToken = '{';
221
+ continue;
222
+ }
223
+ if (raw.startsWith(activeTripleQuote, i)) {
224
+ const qLen = activeTripleQuote.length;
225
+ out.push('"'.repeat(qLen));
226
+ i += qLen - 1;
227
+ activeTripleQuote = null;
228
+ prevSigToken = '"';
229
+ continue;
230
+ }
231
+ out.push(' ');
232
+ continue;
233
+ }
234
+
235
+ if (inCSharpVerbatim) {
236
+ if (ch === '"' && next === '"') {
237
+ out.push(' ');
238
+ i++;
239
+ continue;
240
+ }
241
+ if (ch === '"') {
242
+ out.push('"');
243
+ inCSharpVerbatim = false;
244
+ prevSigToken = '"';
245
+ continue;
246
+ }
247
+ out.push(' ');
248
+ continue;
249
+ }
250
+
251
+ if (inRustRawString) {
252
+ if (ch === '"') {
253
+ let hashes = 0;
254
+ while (i + 1 + hashes < len && raw[i + 1 + hashes] === '#' && hashes < rustRawHashes) {
255
+ hashes++;
256
+ }
257
+ if (hashes === rustRawHashes) {
258
+ out.push('"');
259
+ for (let h = 0; h < hashes; h++) out.push('#');
260
+ i += hashes;
261
+ inRustRawString = false;
262
+ prevSigToken = '"';
263
+ continue;
264
+ }
265
+ }
266
+ out.push(' ');
267
+ continue;
268
+ }
269
+
270
+ if (inBacktick) {
271
+ if (cfg.templateBacktick) {
272
+ if (ch === '\\') {
273
+ out.push(' ');
274
+ i++;
275
+ continue;
276
+ }
277
+ if (ch === '$' && next === '{') {
278
+ templateExprStack.push({ depth: braceDepth, resume: 'backtick', quote: '`' });
279
+ braceDepth++;
280
+ out.push(' ');
281
+ out.push('{');
282
+ i++;
283
+ inBacktick = false;
284
+ prevSigToken = '{';
285
+ continue;
286
+ }
287
+ if (ch === '`') {
288
+ inBacktick = false;
289
+ out.push('`');
290
+ prevSigToken = '`';
291
+ continue;
292
+ }
293
+ out.push(' ');
294
+ continue;
295
+ }
296
+ if (ch === '`') {
297
+ inBacktick = false;
298
+ out.push('`');
299
+ prevSigToken = '`';
300
+ } else {
301
+ out.push(' ');
302
+ }
303
+ continue;
304
+ }
305
+
306
+ if (inStringQuote) {
307
+ if (ch === '\\') {
308
+ out.push(' ');
309
+ i++;
310
+ continue;
311
+ }
312
+ if (cfg.templateDollarString && inStringQuote === '"' && ch === '$' && next === '{') {
313
+ templateExprStack.push({ depth: braceDepth, resume: 'string', quote: '"' });
314
+ braceDepth++;
315
+ out.push(' ');
316
+ out.push('{');
317
+ i++;
318
+ inStringQuote = null;
319
+ prevSigToken = '{';
320
+ continue;
321
+ }
322
+ if (ch === inStringQuote) {
323
+ out.push(ch);
324
+ inStringQuote = null;
325
+ prevSigToken = ch;
326
+ continue;
327
+ }
328
+ out.push(' ');
329
+ continue;
330
+ }
331
+
332
+ if (inRegex) {
333
+ if (ch === '\\') {
334
+ out.push(' ');
335
+ i++;
336
+ continue;
337
+ }
338
+ if (ch === '[') {
339
+ inRegexClass = true;
340
+ out.push(' ');
341
+ continue;
342
+ }
343
+ if (ch === ']' && inRegexClass) {
344
+ inRegexClass = false;
345
+ out.push(' ');
346
+ continue;
347
+ }
348
+ if (ch === '/' && !inRegexClass) {
349
+ inRegex = false;
350
+ out.push('/');
351
+ prevSigToken = '/';
352
+ while (i + 1 < len && /[a-z]/i.test(raw[i + 1])) {
353
+ out.push(' ');
354
+ i++;
355
+ }
356
+ continue;
357
+ }
358
+ out.push(' ');
359
+ continue;
360
+ }
361
+
362
+ const lineCommentTok = matchPrefixAt(raw, i, cfg.lineComments);
363
+ if (lineCommentTok) {
364
+ inLineComment = true;
365
+ out.push(' '.repeat(lineCommentTok.length));
366
+ i += lineCommentTok.length - 1;
367
+ continue;
368
+ }
369
+
370
+ const blockPair = matchPairStartAt(raw, i, cfg.blockComments);
371
+ if (blockPair) {
372
+ activeBlockComment = blockPair;
373
+ blockCommentNested = 0;
374
+ out.push(' '.repeat(blockPair[0].length));
375
+ i += blockPair[0].length - 1;
376
+ continue;
377
+ }
378
+
379
+ const tripleTok = matchPrefixAt(raw, i, tripleList);
380
+ if (tripleTok) {
381
+ activeTripleQuote = tripleTok;
382
+ out.push('"'.repeat(tripleTok.length));
383
+ i += tripleTok.length - 1;
384
+ continue;
385
+ }
386
+
387
+ if (cfg.cSharpVerbatimStrings && ch === '@' && next === '"') {
388
+ inCSharpVerbatim = true;
389
+ out.push(' "');
390
+ i++;
391
+ continue;
392
+ }
393
+
394
+ if (cfg.rustRawStrings && (ch === 'r' || (ch === 'b' && next === 'r'))) {
395
+ let pos = ch === 'b' ? i + 2 : i + 1;
396
+ let hashes = 0;
397
+ while (pos < len && raw[pos] === '#') {
398
+ hashes++;
399
+ pos++;
400
+ }
401
+ if (pos < len && raw[pos] === '"' && (i === 0 || !/[A-Za-z0-9_]/.test(raw[i - 1]))) {
402
+ inRustRawString = true;
403
+ rustRawHashes = hashes;
404
+ for (let k = i; k <= pos; k++) out.push(raw[k]);
405
+ i = pos;
406
+ continue;
407
+ }
408
+ }
409
+
410
+ if (cfg.regexLiterals && ch === '/') {
411
+ const startsRegex =
412
+ prevSigToken === '' ||
413
+ '([{,;:=!?&|^~+-*%<>'.includes(prevSigToken) ||
414
+ REGEX_PREV_KEYWORDS.has(prevSigToken);
415
+ if (startsRegex) {
416
+ inRegex = true;
417
+ inRegexClass = false;
418
+ out.push('/');
419
+ continue;
420
+ }
421
+ }
422
+
423
+ if (ch === "'" && cfg.rustLifetimes) {
424
+ const tail = raw.slice(i);
425
+ const charLitMatch = tail.match(/^'(?:\\(?:x[0-9a-fA-F]{2}|u\{[0-9a-fA-F_]+\}|.)|[^'\\])'/);
426
+ if (charLitMatch) {
427
+ out.push("'");
428
+ for (let k = 1; k < charLitMatch[0].length - 1; k++) out.push(' ');
429
+ out.push("'");
430
+ i += charLitMatch[0].length - 1;
431
+ prevSigToken = "'";
432
+ continue;
433
+ }
434
+ out.push("'");
435
+ prevSigToken = "'";
436
+ continue;
437
+ }
438
+
439
+ if (stringSet.has(ch)) {
440
+ inStringQuote = ch;
441
+ out.push(ch);
442
+ continue;
443
+ }
444
+
445
+ if (ch === '`' && (cfg.templateBacktick || cfg.rawBacktick)) {
446
+ inBacktick = true;
447
+ out.push('`');
448
+ continue;
449
+ }
450
+
451
+ if (ch === '{') {
452
+ braceDepth++;
453
+ } else if (ch === '}') {
454
+ braceDepth = Math.max(0, braceDepth - 1);
455
+ if (
456
+ templateExprStack.length > 0 &&
457
+ braceDepth === templateExprStack[templateExprStack.length - 1].depth
458
+ ) {
459
+ const resumed = templateExprStack.pop();
460
+ out.push('}');
461
+ prevSigToken = '}';
462
+ if (resumed.resume === 'backtick') inBacktick = true;
463
+ else if (resumed.resume === 'triple') activeTripleQuote = resumed.quote;
464
+ else if (resumed.resume === 'string') inStringQuote = resumed.quote;
465
+ continue;
466
+ }
467
+ } else if (ch === '(') {
468
+ parenDepth++;
469
+ } else if (ch === ')') {
470
+ parenDepth = Math.max(0, parenDepth - 1);
471
+ } else if (ch === '[') {
472
+ bracketDepth++;
473
+ } else if (ch === ']') {
474
+ bracketDepth = Math.max(0, bracketDepth - 1);
475
+ }
476
+
477
+ out.push(ch);
478
+
479
+ if (!/\s/.test(ch)) {
480
+ if (/[A-Za-z0-9_$]/.test(ch)) {
481
+ if (i > 0 && /[A-Za-z0-9_$]/.test(raw[i - 1]) && /[A-Za-z0-9_$]/.test(prevSigToken)) {
482
+ prevSigToken += ch;
483
+ } else {
484
+ prevSigToken = ch;
485
+ }
486
+ } else {
487
+ prevSigToken = ch;
488
+ }
489
+ }
490
+ }
491
+
492
+ result[lineIdx] = {
493
+ raw,
494
+ clean: out.join(''),
495
+ braceStart,
496
+ braceEnd: braceDepth,
497
+ parenStart,
498
+ parenEnd: parenDepth,
499
+ bracketStart,
500
+ bracketEnd: bracketDepth,
501
+ };
502
+ }
503
+
504
+ return result;
505
+ }
506
+
507
+ const OPEN_TO_CLOSE = {
508
+ '(': ')',
509
+ '[': ']',
510
+ '{': '}',
511
+ '<': '>',
512
+ };
513
+
514
+ const CLOSE_TO_OPEN = {
515
+ ')': '(',
516
+ ']': '[',
517
+ '}': '{',
518
+ '>': '<',
519
+ };
520
+
521
+ function findMatchingForward(analyzed, startLine, startCol, openChar = '(', closeChar = OPEN_TO_CLOSE[openChar]) {
522
+ let depth = 0;
523
+ for (let line = startLine; line < analyzed.length; line++) {
524
+ const clean = analyzed[line].clean;
525
+ const kStart = line === startLine ? startCol : 0;
526
+ for (let col = kStart; col < clean.length; col++) {
527
+ const ch = clean[col];
528
+ if (ch === openChar) {
529
+ depth++;
530
+ } else if (ch === closeChar) {
531
+ depth--;
532
+ if (depth === 0) {
533
+ return { line, col };
534
+ }
535
+ }
536
+ }
537
+ }
538
+ return null;
539
+ }
540
+
541
+ function findMatchingBackward(analyzed, endLine, endCol, closeChar = ')', openChar = CLOSE_TO_OPEN[closeChar], minLine = 0) {
542
+ let depth = 0;
543
+ const floor = Math.max(0, minLine);
544
+ for (let line = endLine; line >= floor; line--) {
545
+ const clean = analyzed[line].clean;
546
+ const kStart = line === endLine ? endCol : clean.length - 1;
547
+ for (let col = kStart; col >= 0; col--) {
548
+ const ch = clean[col];
549
+ if (ch === closeChar) {
550
+ depth++;
551
+ } else if (ch === openChar) {
552
+ depth--;
553
+ if (depth === 0) {
554
+ return { line, col };
555
+ }
556
+ }
557
+ }
558
+ }
559
+ return null;
560
+ }
561
+
562
+ function skipWhitespaceForward(analyzed, startLine, startCol, maxLine = analyzed.length - 1) {
563
+ const ceil = Math.min(analyzed.length - 1, maxLine);
564
+ for (let line = startLine; line <= ceil; line++) {
565
+ const clean = analyzed[line].clean;
566
+ const kStart = line === startLine ? startCol : 0;
567
+ for (let col = kStart; col < clean.length; col++) {
568
+ if (!/\s/.test(clean[col])) {
569
+ return { line, col, ch: clean[col] };
570
+ }
571
+ }
572
+ }
573
+ return null;
574
+ }
575
+
576
+ function skipWhitespaceBackward(analyzed, startLine, startCol, minLine = 0) {
577
+ const floor = Math.max(0, minLine);
578
+ for (let line = startLine; line >= floor; line--) {
579
+ const clean = analyzed[line].clean;
580
+ const kStart = line === startLine ? startCol : clean.length - 1;
581
+ for (let col = kStart; col >= 0; col--) {
582
+ if (!/\s/.test(clean[col])) {
583
+ return { line, col, ch: clean[col] };
584
+ }
585
+ }
586
+ }
587
+ return null;
588
+ }
589
+
590
+ function stripLeadingAnnotationsOnText(cleanText) {
591
+ let pos = 0;
592
+ const len = cleanText.length;
593
+ while (pos < len) {
594
+ while (pos < len && /\s/.test(cleanText[pos])) pos++;
595
+ if (pos >= len || cleanText[pos] !== '@') break;
596
+ // 陷阱: `@interface` 是 Java 注解类型容器声明本身,不能当作前置修饰注解剥掉
597
+ if (/^@interface\b/.test(cleanText.slice(pos))) break;
598
+ pos++;
599
+ while (pos < len && /\s/.test(cleanText[pos])) pos++;
600
+ const nameMatch = cleanText.slice(pos).match(/^[A-Za-z_$][\w$.:]*/);
601
+ if (!nameMatch) break;
602
+ pos += nameMatch[0].length;
603
+ while (pos < len && /\s/.test(cleanText[pos])) pos++;
604
+ if (pos < len && cleanText[pos] === '(') {
605
+ let depth = 0;
606
+ while (pos < len) {
607
+ if (cleanText[pos] === '(') depth++;
608
+ else if (cleanText[pos] === ')') {
609
+ depth--;
610
+ if (depth === 0) {
611
+ pos++;
612
+ break;
613
+ }
614
+ }
615
+ pos++;
616
+ }
617
+ }
618
+ }
619
+ while (pos < len && /\s/.test(cleanText[pos])) pos++;
620
+ return { rest: cleanText.slice(pos), offset: pos };
621
+ }
622
+
623
+ function skipLeadingAnnotations(analyzed, startLine, startCol = 0) {
624
+ let line = startLine;
625
+ let col = startCol;
626
+ while (line < analyzed.length) {
627
+ const next = skipWhitespaceForward(analyzed, line, col);
628
+ if (!next) return null;
629
+ line = next.line;
630
+ col = next.col;
631
+ const clean = analyzed[line].clean;
632
+ if (clean[col] !== '@') {
633
+ return { line, col };
634
+ }
635
+ if (/^@interface\b/.test(clean.slice(col))) {
636
+ return { line, col };
637
+ }
638
+ let curCol = col + 1;
639
+ while (curCol < clean.length && /\s/.test(clean[curCol])) curCol++;
640
+ const nameMatch = clean.slice(curCol).match(/^[A-Za-z_$][\w$.:]*/);
641
+ if (!nameMatch) {
642
+ return { line, col };
643
+ }
644
+ curCol += nameMatch[0].length;
645
+ const afterName = skipWhitespaceForward(analyzed, line, curCol, Math.min(analyzed.length - 1, line + 1));
646
+ if (afterName && afterName.ch === '(') {
647
+ const closePos = findMatchingForward(analyzed, afterName.line, afterName.col, '(', ')');
648
+ if (!closePos) return null;
649
+ line = closePos.line;
650
+ col = closePos.col + 1;
651
+ continue;
652
+ }
653
+ col = curCol;
654
+ }
655
+ return null;
656
+ }
657
+
658
+ function sliceCleanRange(analyzed, startLine, startCol, endLine, endCol) {
659
+ if (startLine > endLine || (startLine === endLine && startCol > endCol)) return '';
660
+ if (startLine === endLine) {
661
+ return analyzed[startLine].clean.slice(startCol, endCol + 1);
662
+ }
663
+ const parts = [analyzed[startLine].clean.slice(startCol)];
664
+ for (let i = startLine + 1; i < endLine; i++) {
665
+ parts.push(analyzed[i].clean);
666
+ }
667
+ parts.push(analyzed[endLine].clean.slice(0, endCol + 1));
668
+ return parts.join('\n');
669
+ }
670
+
671
+ function hasTopLevelChar(text, targetChar) {
672
+ let paren = 0;
673
+ let bracket = 0;
674
+ let brace = 0;
675
+ let angle = 0;
676
+ for (let i = 0; i < text.length; i++) {
677
+ const ch = text[i];
678
+ const prev = i > 0 ? text[i - 1] : '';
679
+ const next = i + 1 < text.length ? text[i + 1] : '';
680
+ if (ch === '(') paren++;
681
+ else if (ch === ')') paren = Math.max(0, paren - 1);
682
+ else if (ch === '[') bracket++;
683
+ else if (ch === ']') bracket = Math.max(0, bracket - 1);
684
+ else if (ch === '{') brace++;
685
+ else if (ch === '}') brace = Math.max(0, brace - 1);
686
+ else if (ch === '<' && next !== '=' && prev !== '-' && prev !== '=') angle++;
687
+ else if (ch === '>' && prev !== '-' && prev !== '=' && next !== '=') {
688
+ if (angle > 0) angle--;
689
+ } else if (
690
+ ch === targetChar &&
691
+ paren === 0 &&
692
+ bracket === 0 &&
693
+ brace === 0 &&
694
+ angle === 0
695
+ ) {
696
+ if (targetChar === '=' && (prev === '=' || prev === '!' || prev === '<' || prev === '>' || next === '=' || next === '>')) {
697
+ continue;
698
+ }
699
+ return true;
700
+ }
701
+ }
702
+ return false;
703
+ }
704
+
705
+ module.exports = {
706
+ REGEX_PREV_KEYWORDS,
707
+ DEFAULT_LEXER_CONFIG,
708
+ LEXER_PRESETS,
709
+ resolveLexerConfig,
710
+ estimateTokens,
711
+ splitLines,
712
+ formatInt,
713
+ preprocessBraceLines,
714
+ findMatchingForward,
715
+ findMatchingBackward,
716
+ skipWhitespaceForward,
717
+ skipWhitespaceBackward,
718
+ stripLeadingAnnotationsOnText,
719
+ skipLeadingAnnotations,
720
+ sliceCleanRange,
721
+ hasTopLevelChar,
722
+ };