parseman 0.43.0 → 0.45.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/analysis/diagnose.d.ts +118 -0
- package/dist/analysis/diagnose.d.ts.map +1 -0
- package/dist/analysis/gating.d.ts +9 -9
- package/dist/analysis/gating.d.ts.map +1 -1
- package/dist/analysis/grammar.d.ts.map +1 -1
- package/dist/combinators/attempt.d.ts.map +1 -1
- package/dist/combinators/choice.d.ts.map +1 -1
- package/dist/combinators/dispatch.d.ts +19 -1
- package/dist/combinators/dispatch.d.ts.map +1 -1
- package/dist/combinators/expect.d.ts.map +1 -1
- package/dist/combinators/first-set.d.ts.map +1 -1
- package/dist/combinators/grammar.d.ts +7 -0
- package/dist/combinators/grammar.d.ts.map +1 -1
- package/dist/combinators/map.d.ts +11 -0
- package/dist/combinators/map.d.ts.map +1 -1
- package/dist/combinators/node.d.ts +19 -0
- package/dist/combinators/node.d.ts.map +1 -1
- package/dist/combinators/token.d.ts +3 -2
- package/dist/combinators/token.d.ts.map +1 -1
- package/dist/combinators/trivia-skip.d.ts +1 -0
- package/dist/combinators/trivia-skip.d.ts.map +1 -1
- package/dist/compiler/build-arity.d.ts +28 -0
- package/dist/compiler/build-arity.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts +80 -60
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/compiler/degradation.d.ts +123 -0
- package/dist/compiler/degradation.d.ts.map +1 -0
- package/dist/compiler/fields.d.ts.map +1 -1
- package/dist/compiler/grammar-coverage-ids.d.ts.map +1 -1
- package/dist/compiler/inline-build.d.ts.map +1 -1
- package/dist/compiler/ir-serialize.d.ts.map +1 -1
- package/dist/compiler/linker.d.ts +1 -1
- package/dist/compiler/linker.d.ts.map +1 -1
- package/dist/compiler/scannable-run.d.ts +1 -1
- package/dist/compiler/scannable-run.d.ts.map +1 -1
- package/dist/compiler/trivia-fast-path.d.ts +4 -3
- package/dist/compiler/trivia-fast-path.d.ts.map +1 -1
- package/dist/coverage.d.ts +13 -0
- package/dist/coverage.d.ts.map +1 -1
- package/dist/cst/reflection.d.ts.map +1 -1
- package/dist/cst/trivia-entries.d.ts +15 -9
- package/dist/cst/trivia-entries.d.ts.map +1 -1
- package/dist/cst/trivia-kinds.d.ts +15 -11
- package/dist/cst/trivia-kinds.d.ts.map +1 -1
- package/dist/functional/run.d.ts +22 -16
- package/dist/functional/run.d.ts.map +1 -1
- package/dist/index.cjs +2131 -1594
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +6 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2131 -1594
- package/dist/index.js.map +4 -4
- package/dist/language-service/index.cjs +201 -132
- package/dist/language-service/index.cjs.map +4 -4
- package/dist/language-service/index.js +201 -132
- package/dist/language-service/index.js.map +4 -4
- package/dist/oracle/digest.d.ts +132 -6
- package/dist/oracle/digest.d.ts.map +1 -1
- package/dist/oracle/index.cjs +136 -305
- package/dist/oracle/index.cjs.map +4 -4
- package/dist/oracle/index.d.ts +43 -31
- package/dist/oracle/index.d.ts.map +1 -1
- package/dist/oracle/index.js +136 -305
- package/dist/oracle/index.js.map +4 -4
- package/dist/plugin/evaluator.d.ts +3 -0
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.cjs +2333 -1721
- package/dist/plugin/index.cjs.map +4 -4
- package/dist/plugin/index.d.ts +18 -0
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +2333 -1721
- package/dist/plugin/index.js.map +4 -4
- package/dist/plugin/reducer-resolver.d.ts +41 -0
- package/dist/plugin/reducer-resolver.d.ts.map +1 -0
- package/dist/run/index.cjs +185 -132
- package/dist/run/index.cjs.map +3 -3
- package/dist/run/index.d.ts +1 -1
- package/dist/run/index.d.ts.map +1 -1
- package/dist/run/index.js +185 -132
- package/dist/run/index.js.map +3 -3
- package/dist/spec/index.cjs +1637 -1322
- package/dist/spec/index.cjs.map +4 -4
- package/dist/spec/index.js +1637 -1322
- package/dist/spec/index.js.map +4 -4
- package/dist/spec/model.d.ts.map +1 -1
- package/dist/types.d.ts +31 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +7 -3
- package/dist/combinators/guard.d.ts +0 -8
- package/dist/combinators/guard.d.ts.map +0 -1
- package/dist/cst/offset-model.d.ts +0 -119
- package/dist/cst/offset-model.d.ts.map +0 -1
- package/dist/oracle/corpus.d.ts +0 -32
- package/dist/oracle/corpus.d.ts.map +0 -1
- package/dist/oracle/identity.d.ts +0 -117
- package/dist/oracle/identity.d.ts.map +0 -1
package/dist/run/index.js
CHANGED
|
@@ -1,105 +1,97 @@
|
|
|
1
1
|
// src/cst/trivia-entries.ts
|
|
2
2
|
var EMPTY_INDICES = Object.freeze([]);
|
|
3
3
|
var EMPTY_GAPS = Object.freeze([]);
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
4
|
+
var SELECTED_ROOT_STRIDE = 5;
|
|
5
|
+
function buildRootTriviaIndex(log, labels) {
|
|
6
|
+
const length = Math.floor(log.length / SELECTED_ROOT_STRIDE);
|
|
7
|
+
const markerOffset = (i) => i * SELECTED_ROOT_STRIDE;
|
|
8
|
+
const ownedRangeStart = (i) => log[markerOffset(i)];
|
|
9
|
+
const ownedRangeEnd = (i) => log[markerOffset(i) + 1];
|
|
10
|
+
const markerStart = (i) => log[markerOffset(i) + 2];
|
|
11
|
+
const markerEnd = (i) => log[markerOffset(i) + 3];
|
|
12
|
+
const markerKind = (i) => log[markerOffset(i) + 4];
|
|
13
|
+
const entries = {
|
|
12
14
|
length,
|
|
13
15
|
labels,
|
|
14
|
-
stride,
|
|
15
|
-
start
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return log[entryOffset(i, stride) + 1];
|
|
20
|
-
},
|
|
21
|
-
insertIndex(i) {
|
|
22
|
-
return opts?.nodeLog ? log[entryOffset(i, stride) + 2] : void 0;
|
|
23
|
-
},
|
|
24
|
-
kindIndex(i) {
|
|
25
|
-
if (!labels) return void 0;
|
|
26
|
-
return log[entryOffset(i, stride) + baseStride];
|
|
27
|
-
},
|
|
16
|
+
stride: SELECTED_ROOT_STRIDE,
|
|
17
|
+
start: markerStart,
|
|
18
|
+
end: markerEnd,
|
|
19
|
+
insertIndex: () => void 0,
|
|
20
|
+
kindIndex: markerKind,
|
|
28
21
|
kind(i) {
|
|
29
|
-
|
|
30
|
-
return ki !== void 0 ? labels[ki] : void 0;
|
|
22
|
+
return labels[markerKind(i)];
|
|
31
23
|
},
|
|
32
24
|
text(i, input) {
|
|
33
|
-
|
|
34
|
-
const e = log[entryOffset(i, stride) + 1];
|
|
35
|
-
return input.slice(s, e);
|
|
25
|
+
return input.slice(markerStart(i), markerEnd(i));
|
|
36
26
|
}
|
|
37
27
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
for (let i = first; i <= last; i++) indices.push(i);
|
|
46
|
-
}
|
|
47
|
-
function buildGap(entries, start, end, first, last) {
|
|
48
|
-
const entryIndices = [];
|
|
49
|
-
for (let i = first; i <= last; i++) entryIndices.push(i);
|
|
50
|
-
return {
|
|
51
|
-
start,
|
|
52
|
-
end,
|
|
53
|
-
entryIndices,
|
|
54
|
-
hasKind(kind) {
|
|
55
|
-
for (const i of entryIndices) {
|
|
56
|
-
if (entries.kind(i) === kind) return true;
|
|
57
|
-
}
|
|
58
|
-
return false;
|
|
59
|
-
},
|
|
60
|
-
text(input) {
|
|
61
|
-
return input.slice(start, end);
|
|
28
|
+
const lowerBound = (offset, by) => {
|
|
29
|
+
let lo = 0;
|
|
30
|
+
let hi = length;
|
|
31
|
+
while (lo < hi) {
|
|
32
|
+
const mid = lo + hi >>> 1;
|
|
33
|
+
if (by(mid) < offset) lo = mid + 1;
|
|
34
|
+
else hi = mid;
|
|
62
35
|
}
|
|
36
|
+
return lo;
|
|
63
37
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
38
|
+
const gapRowsAt = (offset, direction) => {
|
|
39
|
+
const edge = direction === "before" ? ownedRangeEnd : ownedRangeStart;
|
|
40
|
+
let first = lowerBound(offset, edge);
|
|
41
|
+
if (first === length || edge(first) !== offset) return void 0;
|
|
42
|
+
const start = ownedRangeStart(first);
|
|
43
|
+
const end = ownedRangeEnd(first);
|
|
44
|
+
while (first > 0 && ownedRangeStart(first - 1) === start && ownedRangeEnd(first - 1) === end) first--;
|
|
45
|
+
let last = first + 1;
|
|
46
|
+
while (last < length && ownedRangeStart(last) === start && ownedRangeEnd(last) === end) last++;
|
|
47
|
+
return [first, last];
|
|
48
|
+
};
|
|
49
|
+
const indices = (first, last) => {
|
|
50
|
+
const out = [];
|
|
51
|
+
for (let i = first; i < last; i++) out.push(i);
|
|
52
|
+
return out;
|
|
53
|
+
};
|
|
54
|
+
const makeGap = (first, last) => {
|
|
55
|
+
const start = ownedRangeStart(first);
|
|
56
|
+
const end = ownedRangeEnd(first);
|
|
57
|
+
let entryIndices;
|
|
58
|
+
return {
|
|
59
|
+
start,
|
|
60
|
+
end,
|
|
61
|
+
get entryIndices() {
|
|
62
|
+
return entryIndices ??= indices(first, last);
|
|
63
|
+
},
|
|
64
|
+
hasKind(kind) {
|
|
65
|
+
for (let i = first; i < last; i++) {
|
|
66
|
+
if (labels[markerKind(i)] === kind) return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
},
|
|
70
|
+
text(input) {
|
|
71
|
+
return input.slice(start, end);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
79
74
|
};
|
|
80
|
-
let first = 0;
|
|
81
|
-
let start = entries.start(0);
|
|
82
|
-
let end = entries.end(0);
|
|
83
|
-
for (let i = 1; i < entries.length; i++) {
|
|
84
|
-
const nextStart = entries.start(i);
|
|
85
|
-
const nextEnd = entries.end(i);
|
|
86
|
-
if (nextStart === end) {
|
|
87
|
-
end = nextEnd;
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
appendGap(first, i - 1, start, end);
|
|
91
|
-
first = i;
|
|
92
|
-
start = nextStart;
|
|
93
|
-
end = nextEnd;
|
|
94
|
-
}
|
|
95
|
-
appendGap(first, entries.length - 1, start, end);
|
|
96
|
-
return { before, after, beforeGaps, afterGaps, gaps };
|
|
97
|
-
}
|
|
98
|
-
function buildRootTriviaIndex(log, labels) {
|
|
99
|
-
const entries = triviaEntries(log, labels);
|
|
100
75
|
let maps;
|
|
101
76
|
const getMaps = () => {
|
|
102
|
-
maps
|
|
77
|
+
if (maps !== void 0) return maps;
|
|
78
|
+
const before = /* @__PURE__ */ new Map();
|
|
79
|
+
const after = /* @__PURE__ */ new Map();
|
|
80
|
+
const beforeGaps = /* @__PURE__ */ new Map();
|
|
81
|
+
const afterGaps = /* @__PURE__ */ new Map();
|
|
82
|
+
const gaps = [];
|
|
83
|
+
for (let first = 0; first < length; ) {
|
|
84
|
+
let last = first + 1;
|
|
85
|
+
while (last < length && ownedRangeStart(last) === ownedRangeStart(first) && ownedRangeEnd(last) === ownedRangeEnd(first)) last++;
|
|
86
|
+
const gap = makeGap(first, last);
|
|
87
|
+
gaps.push(gap);
|
|
88
|
+
afterGaps.set(gap.start, gap);
|
|
89
|
+
beforeGaps.set(gap.end, gap);
|
|
90
|
+
after.set(gap.start, [...gap.entryIndices]);
|
|
91
|
+
before.set(gap.end, [...gap.entryIndices]);
|
|
92
|
+
first = last;
|
|
93
|
+
}
|
|
94
|
+
maps = { before, after, beforeGaps, afterGaps, gaps };
|
|
103
95
|
return maps;
|
|
104
96
|
};
|
|
105
97
|
return {
|
|
@@ -112,16 +104,20 @@ function buildRootTriviaIndex(log, labels) {
|
|
|
112
104
|
return getMaps().after;
|
|
113
105
|
},
|
|
114
106
|
entryIndicesBefore(offset) {
|
|
115
|
-
|
|
107
|
+
const rows = gapRowsAt(offset, "before");
|
|
108
|
+
return rows ? indices(rows[0], rows[1]) : EMPTY_INDICES;
|
|
116
109
|
},
|
|
117
110
|
entryIndicesAfter(offset) {
|
|
118
|
-
|
|
111
|
+
const rows = gapRowsAt(offset, "after");
|
|
112
|
+
return rows ? indices(rows[0], rows[1]) : EMPTY_INDICES;
|
|
119
113
|
},
|
|
120
114
|
gapBefore(offset) {
|
|
121
|
-
|
|
115
|
+
const rows = gapRowsAt(offset, "before");
|
|
116
|
+
return rows ? makeGap(rows[0], rows[1]) : void 0;
|
|
122
117
|
},
|
|
123
118
|
gapAfter(offset) {
|
|
124
|
-
|
|
119
|
+
const rows = gapRowsAt(offset, "after");
|
|
120
|
+
return rows ? makeGap(rows[0], rows[1]) : void 0;
|
|
125
121
|
},
|
|
126
122
|
gaps() {
|
|
127
123
|
return getMaps().gaps;
|
|
@@ -129,13 +125,21 @@ function buildRootTriviaIndex(log, labels) {
|
|
|
129
125
|
gapsWithKind(kind) {
|
|
130
126
|
const kinds = typeof kind === "string" ? [kind] : kind;
|
|
131
127
|
const matches = [];
|
|
132
|
-
for (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
128
|
+
for (let first = 0; first < length; ) {
|
|
129
|
+
let last = first + 1;
|
|
130
|
+
while (last < length && ownedRangeStart(last) === ownedRangeStart(first) && ownedRangeEnd(last) === ownedRangeEnd(first)) last++;
|
|
131
|
+
let matched = false;
|
|
132
|
+
for (let i = first; i < last && !matched; i++) {
|
|
133
|
+
const label = labels[markerKind(i)];
|
|
134
|
+
for (const kind2 of kinds) {
|
|
135
|
+
if (label === kind2) {
|
|
136
|
+
matched = true;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
137
139
|
}
|
|
138
140
|
}
|
|
141
|
+
if (matched) matches.push(makeGap(first, last));
|
|
142
|
+
first = last;
|
|
139
143
|
}
|
|
140
144
|
return matches.length === 0 ? EMPTY_GAPS : matches;
|
|
141
145
|
}
|
|
@@ -220,6 +224,7 @@ function probeAt(sentinel, input, pos, ctx) {
|
|
|
220
224
|
_cstRawChildren: ctx._cstRawChildren,
|
|
221
225
|
_cstTriviaLog: ctx._cstTriviaLog,
|
|
222
226
|
_triviaLog: ctx._triviaLog,
|
|
227
|
+
_rootTriviaLog: ctx._rootTriviaLog,
|
|
223
228
|
_fields: ctx._fields,
|
|
224
229
|
_cstBuf: ctx._cstBuf,
|
|
225
230
|
_tolerant: ctx._tolerant,
|
|
@@ -232,6 +237,7 @@ function probeAt(sentinel, input, pos, ctx) {
|
|
|
232
237
|
ctx._cstRawChildren = void 0;
|
|
233
238
|
ctx._cstTriviaLog = void 0;
|
|
234
239
|
ctx._triviaLog = void 0;
|
|
240
|
+
ctx._rootTriviaLog = void 0;
|
|
235
241
|
ctx._fields = void 0;
|
|
236
242
|
ctx._cstBuf = void 0;
|
|
237
243
|
ctx._tolerant = void 0;
|
|
@@ -246,6 +252,7 @@ function probeAt(sentinel, input, pos, ctx) {
|
|
|
246
252
|
ctx._cstRawChildren = s._cstRawChildren;
|
|
247
253
|
ctx._cstTriviaLog = s._cstTriviaLog;
|
|
248
254
|
ctx._triviaLog = s._triviaLog;
|
|
255
|
+
ctx._rootTriviaLog = s._rootTriviaLog;
|
|
249
256
|
ctx._fields = s._fields;
|
|
250
257
|
ctx._cstBuf = s._cstBuf;
|
|
251
258
|
ctx._tolerant = s._tolerant;
|
|
@@ -318,12 +325,54 @@ function assertHostModeCompatible(mode, build, hostBranchElided = true) {
|
|
|
318
325
|
}
|
|
319
326
|
|
|
320
327
|
// src/functional/run.ts
|
|
328
|
+
var SELECT_EXAMPLE = "run(entry, input, { rootTrivia: { select: ['blockComment', 'lineComment'] } })";
|
|
329
|
+
var REMOVED_RUN_RESULT_FIELDS = [
|
|
330
|
+
[
|
|
331
|
+
"triviaMap",
|
|
332
|
+
`It was a dense root-trivia index built on every parse; root trivia is now an OPT-IN sparse capture, because most grammars paid for an index they never read. Migration: name the trivia labels your grammar defines \u2014 ${SELECT_EXAMPLE} \u2014 and read \`RunResult.rootTrivia\`, whose \`.index\` carries the labels and gap lookups \`triviaMap\` exposed.`
|
|
333
|
+
],
|
|
334
|
+
[
|
|
335
|
+
"triviaLog",
|
|
336
|
+
`It was the flat \`start, end[, kindIndex]\` log every other trivia view was derived from, and it is no longer allocated at all \u2014 not empty, absent. Migration: request the labels you need \u2014 ${SELECT_EXAMPLE} \u2014 and read \`RunResult.rootTrivia.rows\`. Do NOT reuse a stride-2/3 reader: rows are a different width and a different unit (one row per SELECTED marker, not one per trivia chunk), so an old loop reads confidently wrong offsets rather than failing.`
|
|
337
|
+
],
|
|
338
|
+
[
|
|
339
|
+
"triviaKindLabels",
|
|
340
|
+
`It was already optional, so nothing ever flagged its disappearance \u2014 and \`triviaKindMask(undefined, \u2026)\` means "capture everything", so reading it now silently WIDENS capture instead of erroring. Migration: request labels \u2014 ${SELECT_EXAMPLE} \u2014 then the set you asked for is \`RunResult.rootTrivia.select\` and the resolved table is \`RunResult.rootTrivia.index.labels\`.`
|
|
341
|
+
]
|
|
342
|
+
];
|
|
343
|
+
function guardRemovedFields(result) {
|
|
344
|
+
for (const [name, detail] of REMOVED_RUN_RESULT_FIELDS) {
|
|
345
|
+
Object.defineProperty(result, name, {
|
|
346
|
+
configurable: true,
|
|
347
|
+
enumerable: false,
|
|
348
|
+
get() {
|
|
349
|
+
throw new TypeError(
|
|
350
|
+
`RunResult.${name} was REMOVED in parseman 0.44.0 and has no default replacement. ${detail}`
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
return result;
|
|
356
|
+
}
|
|
321
357
|
var invoke = (r, input, pos, ctx) => typeof r === "function" ? r(input, pos, ctx) : r.parse(input, pos, ctx);
|
|
322
358
|
function triviaKindLabelsFromRunnable(r) {
|
|
323
359
|
if (!r) return void 0;
|
|
324
360
|
if (typeof r === "function") return r._meta?.triviaKindLabels;
|
|
325
361
|
const grammarTrivia = r._meta.grammarTrivia;
|
|
326
|
-
return
|
|
362
|
+
return grammarTrivia?._meta.triviaKindLabels ?? r._meta.triviaKindLabels ?? (r._def.tag === "grammar" ? r._def.triviaParser?._meta.triviaKindLabels : void 0);
|
|
363
|
+
}
|
|
364
|
+
function rootTriviaClassifiedFromRunnable(r) {
|
|
365
|
+
if (!r) return false;
|
|
366
|
+
if (typeof r === "function") return r._meta?.rootTriviaClassified === true;
|
|
367
|
+
const grammarTrivia = r._meta.grammarTrivia;
|
|
368
|
+
return grammarTrivia?._meta.rootTriviaClassified === true || r._meta.rootTriviaClassified === true;
|
|
369
|
+
}
|
|
370
|
+
function makeSelectedRootLabelIndex(labels) {
|
|
371
|
+
const index = /* @__PURE__ */ Object.create(null);
|
|
372
|
+
for (let i = 0; i < labels.length; i++) {
|
|
373
|
+
if (index[labels[i]] === void 0) index[labels[i]] = i;
|
|
374
|
+
}
|
|
375
|
+
return index;
|
|
327
376
|
}
|
|
328
377
|
function runOnce(entry, input, options, phase, profileState) {
|
|
329
378
|
if (typeof entry !== "function" && typeof entry?.parse !== "function") {
|
|
@@ -331,13 +380,31 @@ function runOnce(entry, input, options, phase, profileState) {
|
|
|
331
380
|
`run(): start production is ${entry === null ? "null" : typeof entry}, not a rule \u2014 the requested grammar rule does not exist (check the rule name).`
|
|
332
381
|
);
|
|
333
382
|
}
|
|
334
|
-
const
|
|
383
|
+
const rootTriviaSelection = options.rootTrivia?.select;
|
|
384
|
+
const captureRootTrivia = rootTriviaSelection !== void 0 && rootTriviaSelection.length > 0;
|
|
385
|
+
const selectedRootLog = captureRootTrivia ? [] : void 0;
|
|
386
|
+
const selectedRootLabelIndex = captureRootTrivia ? makeSelectedRootLabelIndex(rootTriviaSelection) : void 0;
|
|
335
387
|
const errors = [];
|
|
336
388
|
const profile = profileState ?? (phase === void 0 ? void 0 : { phase, nodes: 0, childSlots: 0, rawSlots: 0, triviaSlots: 0, fieldSlots: 0, hostCalls: 0 });
|
|
337
389
|
const skipGlobalSinks = phase === "recognizer" || phase === "capture";
|
|
338
390
|
const grammarTrivia = typeof entry !== "function" ? entry._meta.grammarTrivia : void 0;
|
|
339
391
|
const grammarScanSkip = typeof entry !== "function" ? entry._meta.grammarScanSkip : void 0;
|
|
340
392
|
const triviaKindLabels = triviaKindLabelsFromRunnable(entry) ?? triviaKindLabelsFromRunnable(options.trivia);
|
|
393
|
+
if (captureRootTrivia && triviaKindLabels === void 0) {
|
|
394
|
+
throw new TypeError("run(): rootTrivia.select requires labeled grammar trivia.");
|
|
395
|
+
}
|
|
396
|
+
if (captureRootTrivia) {
|
|
397
|
+
for (const label of rootTriviaSelection) {
|
|
398
|
+
if (!triviaKindLabels.includes(label)) {
|
|
399
|
+
throw new TypeError(`run(): rootTrivia.select contains unknown trivia label ${JSON.stringify(label)}.`);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
if (captureRootTrivia && !rootTriviaClassifiedFromRunnable(entry) && !rootTriviaClassifiedFromRunnable(options.trivia)) {
|
|
404
|
+
throw new TypeError(
|
|
405
|
+
"run(): rootTrivia.select requires classifiedTrivia() at the root."
|
|
406
|
+
);
|
|
407
|
+
}
|
|
341
408
|
const stamped = entry;
|
|
342
409
|
assertHostModeCompatible(
|
|
343
410
|
typeof entry === "function" ? stamped[FUSED_HOST_MODE] ?? "ast" : entry._meta.grammarHostMode ?? "ast",
|
|
@@ -346,7 +413,15 @@ function runOnce(entry, input, options, phase, profileState) {
|
|
|
346
413
|
);
|
|
347
414
|
const ctx = {
|
|
348
415
|
trackLines: false,
|
|
349
|
-
...skipGlobalSinks ? { _pmProfile: profile } : {
|
|
416
|
+
...skipGlobalSinks ? { _pmProfile: profile } : {
|
|
417
|
+
...captureRootTrivia ? {
|
|
418
|
+
_rootTriviaLog: selectedRootLog,
|
|
419
|
+
_rootTriviaKindIndex: selectedRootLabelIndex,
|
|
420
|
+
_rootTriviaStrictScopes: true
|
|
421
|
+
} : {},
|
|
422
|
+
_errors: errors,
|
|
423
|
+
...profile === void 0 ? {} : { _pmProfile: profile }
|
|
424
|
+
},
|
|
350
425
|
build: options.build,
|
|
351
426
|
state: options.state,
|
|
352
427
|
...grammarTrivia !== void 0 ? { trivia: grammarTrivia, ...triviaKindLabels ? { triviaKindLabels } : {} } : triviaKindLabels ? { triviaKindLabels } : {},
|
|
@@ -371,43 +446,21 @@ function runOnce(entry, input, options, phase, profileState) {
|
|
|
371
446
|
span: r.span ?? { start: 0, end: 0 },
|
|
372
447
|
expected: r.ok ? [] : r.expected ?? [],
|
|
373
448
|
errors,
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
449
|
+
...selectedRootLog !== void 0 && selectedRootLog.length > 0 ? {
|
|
450
|
+
rootTrivia: {
|
|
451
|
+
rows: selectedRootLog,
|
|
452
|
+
select: rootTriviaSelection,
|
|
453
|
+
index: buildRootTriviaIndex(selectedRootLog, rootTriviaSelection)
|
|
454
|
+
}
|
|
455
|
+
} : {},
|
|
377
456
|
unconsumedFrom
|
|
378
457
|
};
|
|
379
458
|
}
|
|
380
|
-
function clonePassState(state) {
|
|
381
|
-
if (state === null || typeof state !== "object") return state;
|
|
382
|
-
return Array.isArray(state) ? [...state] : { ...state };
|
|
383
|
-
}
|
|
384
|
-
function profilePass(entry, input, options, phase) {
|
|
385
|
-
const state = { phase, nodes: 0, childSlots: 0, rawSlots: 0, triviaSlots: 0, fieldSlots: 0, hostCalls: 0 };
|
|
386
|
-
const passOptions = options.state === void 0 ? options : { ...options, state: clonePassState(options.state) };
|
|
387
|
-
const start = performance.now();
|
|
388
|
-
const result = runOnce(entry, input, passOptions, phase, state);
|
|
389
|
-
const { phase: _phase, ...counts } = state;
|
|
390
|
-
return { result, profile: { ms: performance.now() - start, ...counts } };
|
|
391
|
-
}
|
|
392
459
|
function run(entry, input, options = {}) {
|
|
393
|
-
if (!options.profile) return runOnce(entry, input, options);
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
const recognizer = profilePass(entry, input, options, "recognizer");
|
|
398
|
-
const capture = profilePass(entry, input, options, "capture");
|
|
399
|
-
const host = profilePass(entry, input, options, "host");
|
|
400
|
-
if (recognizer.result.ok !== host.result.ok || capture.result.ok !== host.result.ok || recognizer.result.unconsumedFrom !== host.result.unconsumedFrom || capture.result.unconsumedFrom !== host.result.unconsumedFrom) {
|
|
401
|
-
throw new Error("run({ profile: true }) changed recognition; the grammar is not profile-safe");
|
|
402
|
-
}
|
|
403
|
-
return {
|
|
404
|
-
...host.result,
|
|
405
|
-
profile: {
|
|
406
|
-
recognizer: recognizer.profile,
|
|
407
|
-
structuralCapture: capture.profile,
|
|
408
|
-
hostConstruction: host.profile
|
|
409
|
-
}
|
|
410
|
-
};
|
|
460
|
+
if (!options.profile) return guardRemovedFields(runOnce(entry, input, options));
|
|
461
|
+
throw new TypeError(
|
|
462
|
+
"run({ profile: true }) is unavailable: profiling counters are no longer compiled into parser artifacts, and the interpreter does not implement them yet. Profiling is moving to interpreted mode."
|
|
463
|
+
);
|
|
411
464
|
}
|
|
412
465
|
export {
|
|
413
466
|
buildRootTriviaIndex,
|