parseman 0.41.0 → 0.42.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.
- package/dist/combinators/expect.d.ts.map +1 -1
- package/dist/combinators/grammar.d.ts.map +1 -1
- package/dist/combinators/literal.d.ts.map +1 -1
- package/dist/combinators/node.d.ts.map +1 -1
- package/dist/combinators/regex.d.ts.map +1 -1
- package/dist/combinators/scanTo.d.ts.map +1 -1
- package/dist/combinators/trivia-skip.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts +3 -0
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/compiler/inline-build.d.ts +1 -1
- package/dist/compiler/inline-build.d.ts.map +1 -1
- package/dist/compiler/line-index.d.ts +1 -15
- package/dist/compiler/line-index.d.ts.map +1 -1
- package/dist/cst/capture-buffer.d.ts.map +1 -1
- package/dist/index.cjs +364 -99
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +364 -99
- package/dist/index.js.map +4 -4
- package/dist/language-service/index.cjs +48 -2
- package/dist/language-service/index.cjs.map +3 -3
- package/dist/language-service/index.js +48 -2
- package/dist/language-service/index.js.map +3 -3
- package/dist/line-index.d.ts +41 -0
- package/dist/line-index.d.ts.map +1 -0
- package/dist/plugin/index.cjs +334 -93
- package/dist/plugin/index.cjs.map +4 -4
- package/dist/plugin/index.js +334 -93
- package/dist/plugin/index.js.map +4 -4
- package/dist/recovery/scan.d.ts.map +1 -1
- package/dist/regex/first-set.d.ts.map +1 -1
- package/dist/run/index.cjs +47 -1
- package/dist/run/index.cjs.map +3 -3
- package/dist/run/index.d.ts +3 -2
- package/dist/run/index.d.ts.map +1 -1
- package/dist/run/index.js +47 -1
- package/dist/run/index.js.map +3 -3
- package/dist/spec/index.cjs +170 -50
- package/dist/spec/index.cjs.map +4 -4
- package/dist/spec/index.js +170 -50
- package/dist/spec/index.js.map +4 -4
- package/dist/types.d.ts +12 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -24,6 +24,50 @@ __export(language_service_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(language_service_exports);
|
|
26
26
|
|
|
27
|
+
// src/line-index.ts
|
|
28
|
+
function recordLineRange(index, input, start, end) {
|
|
29
|
+
const lineStarts = index.lineStarts;
|
|
30
|
+
for (let i = start; i < end; i++) {
|
|
31
|
+
if (input.charCodeAt(i) === 10) lineStarts.push(i + 1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function recordLineRangeFromContext(ctx, input, _startHint, end) {
|
|
35
|
+
if (!ctx.trackLines) return;
|
|
36
|
+
const from = ctx._lineScannedTo ?? 0;
|
|
37
|
+
if (end <= from) return;
|
|
38
|
+
const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
|
|
39
|
+
if (!index) return;
|
|
40
|
+
recordLineRange(index, input, from, end);
|
|
41
|
+
ctx._lineScannedTo = end;
|
|
42
|
+
}
|
|
43
|
+
function offsetToLineCol(index, offset) {
|
|
44
|
+
const { lineStarts } = index;
|
|
45
|
+
let lo = 0;
|
|
46
|
+
let hi = lineStarts.length - 1;
|
|
47
|
+
while (lo < hi) {
|
|
48
|
+
const mid = lo + hi + 1 >> 1;
|
|
49
|
+
if (lineStarts[mid] <= offset) lo = mid;
|
|
50
|
+
else hi = mid - 1;
|
|
51
|
+
}
|
|
52
|
+
return { line: lo + 1, col: offset - lineStarts[lo] + 1 };
|
|
53
|
+
}
|
|
54
|
+
function annotateSpan(span, index) {
|
|
55
|
+
const s = offsetToLineCol(index, span.start);
|
|
56
|
+
const e = offsetToLineCol(index, span.end);
|
|
57
|
+
return {
|
|
58
|
+
...span,
|
|
59
|
+
startLine: s.line,
|
|
60
|
+
startColumn: s.col,
|
|
61
|
+
endLine: e.line,
|
|
62
|
+
endColumn: e.col
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function annotateSpanFromLineContext(span, ctx) {
|
|
66
|
+
if (!ctx.trackLines) return span;
|
|
67
|
+
const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
|
|
68
|
+
return index ? annotateSpan(span, index) : span;
|
|
69
|
+
}
|
|
70
|
+
|
|
27
71
|
// src/cst/capture-buffer.ts
|
|
28
72
|
function cstCaptureActive(ctx) {
|
|
29
73
|
return ctx._cstBuf !== void 0 || ctx._cstLeaves !== void 0;
|
|
@@ -124,7 +168,9 @@ function firstSetSentinel(fs) {
|
|
|
124
168
|
function recoverScan(input, from, ctx, sync, expected) {
|
|
125
169
|
let scanPos = from;
|
|
126
170
|
while (scanPos < input.length && !probeAt(sync, input, scanPos, ctx)) scanPos++;
|
|
127
|
-
const
|
|
171
|
+
const span = { start: from, end: scanPos };
|
|
172
|
+
if (ctx.trackLines) recordLineRangeFromContext(ctx, input, from, scanPos);
|
|
173
|
+
const error = { _tag: "parseError", span: ctx.trackLines ? annotateSpanFromLineContext(span, ctx) : span, expected };
|
|
128
174
|
ctx._errors?.push(error);
|
|
129
175
|
return { error, end: scanPos };
|
|
130
176
|
}
|
|
@@ -431,7 +477,7 @@ function normalizeCstCollapse(collapse) {
|
|
|
431
477
|
return typeof collapse === "function" ? collapse : void 0;
|
|
432
478
|
}
|
|
433
479
|
function buildCstNode(type, children, _fields, span, _rawChildren, _triviaLog, state) {
|
|
434
|
-
return { _tag: "node", type, span: {
|
|
480
|
+
return { _tag: "node", type, span: { ...span }, state: state ?? null, children: [...children] };
|
|
435
481
|
}
|
|
436
482
|
function cstBuildHost(typeOrOptions, children, _fields, span, rawChildren, triviaLog, state) {
|
|
437
483
|
if (typeof typeOrOptions === "string") {
|