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.
Files changed (97) hide show
  1. package/dist/analysis/diagnose.d.ts +118 -0
  2. package/dist/analysis/diagnose.d.ts.map +1 -0
  3. package/dist/analysis/gating.d.ts +9 -9
  4. package/dist/analysis/gating.d.ts.map +1 -1
  5. package/dist/analysis/grammar.d.ts.map +1 -1
  6. package/dist/combinators/attempt.d.ts.map +1 -1
  7. package/dist/combinators/choice.d.ts.map +1 -1
  8. package/dist/combinators/dispatch.d.ts +19 -1
  9. package/dist/combinators/dispatch.d.ts.map +1 -1
  10. package/dist/combinators/expect.d.ts.map +1 -1
  11. package/dist/combinators/first-set.d.ts.map +1 -1
  12. package/dist/combinators/grammar.d.ts +7 -0
  13. package/dist/combinators/grammar.d.ts.map +1 -1
  14. package/dist/combinators/map.d.ts +11 -0
  15. package/dist/combinators/map.d.ts.map +1 -1
  16. package/dist/combinators/node.d.ts +19 -0
  17. package/dist/combinators/node.d.ts.map +1 -1
  18. package/dist/combinators/token.d.ts +3 -2
  19. package/dist/combinators/token.d.ts.map +1 -1
  20. package/dist/combinators/trivia-skip.d.ts +1 -0
  21. package/dist/combinators/trivia-skip.d.ts.map +1 -1
  22. package/dist/compiler/build-arity.d.ts +28 -0
  23. package/dist/compiler/build-arity.d.ts.map +1 -1
  24. package/dist/compiler/codegen.d.ts +80 -60
  25. package/dist/compiler/codegen.d.ts.map +1 -1
  26. package/dist/compiler/degradation.d.ts +123 -0
  27. package/dist/compiler/degradation.d.ts.map +1 -0
  28. package/dist/compiler/fields.d.ts.map +1 -1
  29. package/dist/compiler/grammar-coverage-ids.d.ts.map +1 -1
  30. package/dist/compiler/inline-build.d.ts.map +1 -1
  31. package/dist/compiler/ir-serialize.d.ts.map +1 -1
  32. package/dist/compiler/linker.d.ts +1 -1
  33. package/dist/compiler/linker.d.ts.map +1 -1
  34. package/dist/compiler/scannable-run.d.ts +1 -1
  35. package/dist/compiler/scannable-run.d.ts.map +1 -1
  36. package/dist/compiler/trivia-fast-path.d.ts +4 -3
  37. package/dist/compiler/trivia-fast-path.d.ts.map +1 -1
  38. package/dist/coverage.d.ts +13 -0
  39. package/dist/coverage.d.ts.map +1 -1
  40. package/dist/cst/reflection.d.ts.map +1 -1
  41. package/dist/cst/trivia-entries.d.ts +15 -9
  42. package/dist/cst/trivia-entries.d.ts.map +1 -1
  43. package/dist/cst/trivia-kinds.d.ts +15 -11
  44. package/dist/cst/trivia-kinds.d.ts.map +1 -1
  45. package/dist/functional/run.d.ts +22 -16
  46. package/dist/functional/run.d.ts.map +1 -1
  47. package/dist/index.cjs +2131 -1594
  48. package/dist/index.cjs.map +4 -4
  49. package/dist/index.d.ts +6 -8
  50. package/dist/index.d.ts.map +1 -1
  51. package/dist/index.js +2131 -1594
  52. package/dist/index.js.map +4 -4
  53. package/dist/language-service/index.cjs +201 -132
  54. package/dist/language-service/index.cjs.map +4 -4
  55. package/dist/language-service/index.js +201 -132
  56. package/dist/language-service/index.js.map +4 -4
  57. package/dist/oracle/digest.d.ts +132 -6
  58. package/dist/oracle/digest.d.ts.map +1 -1
  59. package/dist/oracle/index.cjs +136 -305
  60. package/dist/oracle/index.cjs.map +4 -4
  61. package/dist/oracle/index.d.ts +43 -31
  62. package/dist/oracle/index.d.ts.map +1 -1
  63. package/dist/oracle/index.js +136 -305
  64. package/dist/oracle/index.js.map +4 -4
  65. package/dist/plugin/evaluator.d.ts +3 -0
  66. package/dist/plugin/evaluator.d.ts.map +1 -1
  67. package/dist/plugin/index.cjs +2333 -1721
  68. package/dist/plugin/index.cjs.map +4 -4
  69. package/dist/plugin/index.d.ts +18 -0
  70. package/dist/plugin/index.d.ts.map +1 -1
  71. package/dist/plugin/index.js +2333 -1721
  72. package/dist/plugin/index.js.map +4 -4
  73. package/dist/plugin/reducer-resolver.d.ts +41 -0
  74. package/dist/plugin/reducer-resolver.d.ts.map +1 -0
  75. package/dist/run/index.cjs +185 -132
  76. package/dist/run/index.cjs.map +3 -3
  77. package/dist/run/index.d.ts +1 -1
  78. package/dist/run/index.d.ts.map +1 -1
  79. package/dist/run/index.js +185 -132
  80. package/dist/run/index.js.map +3 -3
  81. package/dist/spec/index.cjs +1637 -1322
  82. package/dist/spec/index.cjs.map +4 -4
  83. package/dist/spec/index.js +1637 -1322
  84. package/dist/spec/index.js.map +4 -4
  85. package/dist/spec/model.d.ts.map +1 -1
  86. package/dist/types.d.ts +31 -1
  87. package/dist/types.d.ts.map +1 -1
  88. package/dist/version.d.ts +1 -1
  89. package/package.json +7 -3
  90. package/dist/combinators/guard.d.ts +0 -8
  91. package/dist/combinators/guard.d.ts.map +0 -1
  92. package/dist/cst/offset-model.d.ts +0 -119
  93. package/dist/cst/offset-model.d.ts.map +0 -1
  94. package/dist/oracle/corpus.d.ts +0 -32
  95. package/dist/oracle/corpus.d.ts.map +0 -1
  96. package/dist/oracle/identity.d.ts +0 -117
  97. package/dist/oracle/identity.d.ts.map +0 -1
@@ -76,6 +76,7 @@ function probeAt(sentinel, input, pos, ctx) {
76
76
  _cstRawChildren: ctx._cstRawChildren,
77
77
  _cstTriviaLog: ctx._cstTriviaLog,
78
78
  _triviaLog: ctx._triviaLog,
79
+ _rootTriviaLog: ctx._rootTriviaLog,
79
80
  _fields: ctx._fields,
80
81
  _cstBuf: ctx._cstBuf,
81
82
  _tolerant: ctx._tolerant,
@@ -88,6 +89,7 @@ function probeAt(sentinel, input, pos, ctx) {
88
89
  ctx._cstRawChildren = void 0;
89
90
  ctx._cstTriviaLog = void 0;
90
91
  ctx._triviaLog = void 0;
92
+ ctx._rootTriviaLog = void 0;
91
93
  ctx._fields = void 0;
92
94
  ctx._cstBuf = void 0;
93
95
  ctx._tolerant = void 0;
@@ -102,6 +104,7 @@ function probeAt(sentinel, input, pos, ctx) {
102
104
  ctx._cstRawChildren = s._cstRawChildren;
103
105
  ctx._cstTriviaLog = s._cstTriviaLog;
104
106
  ctx._triviaLog = s._triviaLog;
107
+ ctx._rootTriviaLog = s._rootTriviaLog;
105
108
  ctx._fields = s._fields;
106
109
  ctx._cstBuf = s._cstBuf;
107
110
  ctx._tolerant = s._tolerant;
@@ -159,105 +162,97 @@ var REC = { scan: recoverScan, at: matchesAt, or: orSentinel, sentinel: firstSet
159
162
  // src/cst/trivia-entries.ts
160
163
  var EMPTY_INDICES = Object.freeze([]);
161
164
  var EMPTY_GAPS = Object.freeze([]);
162
- function entryOffset(i, stride) {
163
- return i * stride;
164
- }
165
- function triviaEntries(log, labels, opts) {
166
- const baseStride = opts?.nodeLog ? 3 : 2;
167
- const stride = labels ? baseStride + 1 : baseStride;
168
- const length = Math.floor(log.length / stride);
169
- return {
165
+ var SELECTED_ROOT_STRIDE = 5;
166
+ function buildRootTriviaIndex(log, labels) {
167
+ const length = Math.floor(log.length / SELECTED_ROOT_STRIDE);
168
+ const markerOffset = (i) => i * SELECTED_ROOT_STRIDE;
169
+ const ownedRangeStart = (i) => log[markerOffset(i)];
170
+ const ownedRangeEnd = (i) => log[markerOffset(i) + 1];
171
+ const markerStart = (i) => log[markerOffset(i) + 2];
172
+ const markerEnd = (i) => log[markerOffset(i) + 3];
173
+ const markerKind = (i) => log[markerOffset(i) + 4];
174
+ const entries = {
170
175
  length,
171
176
  labels,
172
- stride,
173
- start(i) {
174
- return log[entryOffset(i, stride)];
175
- },
176
- end(i) {
177
- return log[entryOffset(i, stride) + 1];
178
- },
179
- insertIndex(i) {
180
- return opts?.nodeLog ? log[entryOffset(i, stride) + 2] : void 0;
181
- },
182
- kindIndex(i) {
183
- if (!labels) return void 0;
184
- return log[entryOffset(i, stride) + baseStride];
185
- },
177
+ stride: SELECTED_ROOT_STRIDE,
178
+ start: markerStart,
179
+ end: markerEnd,
180
+ insertIndex: () => void 0,
181
+ kindIndex: markerKind,
186
182
  kind(i) {
187
- const ki = labels ? log[entryOffset(i, stride) + baseStride] : void 0;
188
- return ki !== void 0 ? labels[ki] : void 0;
183
+ return labels[markerKind(i)];
189
184
  },
190
185
  text(i, input) {
191
- const s = log[entryOffset(i, stride)];
192
- const e = log[entryOffset(i, stride) + 1];
193
- return input.slice(s, e);
186
+ return input.slice(markerStart(i), markerEnd(i));
194
187
  }
195
188
  };
196
- }
197
- function appendEntryRange(map, key, first, last) {
198
- let indices = map.get(key);
199
- if (!indices) {
200
- indices = [];
201
- map.set(key, indices);
202
- }
203
- for (let i = first; i <= last; i++) indices.push(i);
204
- }
205
- function buildGap(entries, start, end, first, last) {
206
- const entryIndices = [];
207
- for (let i = first; i <= last; i++) entryIndices.push(i);
208
- return {
209
- start,
210
- end,
211
- entryIndices,
212
- hasKind(kind) {
213
- for (const i of entryIndices) {
214
- if (entries.kind(i) === kind) return true;
215
- }
216
- return false;
217
- },
218
- text(input) {
219
- return input.slice(start, end);
189
+ const lowerBound = (offset, by) => {
190
+ let lo = 0;
191
+ let hi = length;
192
+ while (lo < hi) {
193
+ const mid = lo + hi >>> 1;
194
+ if (by(mid) < offset) lo = mid + 1;
195
+ else hi = mid;
220
196
  }
197
+ return lo;
221
198
  };
222
- }
223
- function buildRootMaps(entries) {
224
- const before = /* @__PURE__ */ new Map();
225
- const after = /* @__PURE__ */ new Map();
226
- const beforeGaps = /* @__PURE__ */ new Map();
227
- const afterGaps = /* @__PURE__ */ new Map();
228
- const gaps = [];
229
- if (entries.length === 0) return { before, after, beforeGaps, afterGaps, gaps };
230
- const appendGap = (first2, last, start2, end2) => {
231
- const gap = buildGap(entries, start2, end2, first2, last);
232
- gaps.push(gap);
233
- afterGaps.set(start2, gap);
234
- beforeGaps.set(end2, gap);
235
- appendEntryRange(after, start2, first2, last);
236
- appendEntryRange(before, end2, first2, last);
199
+ const gapRowsAt = (offset, direction) => {
200
+ const edge = direction === "before" ? ownedRangeEnd : ownedRangeStart;
201
+ let first = lowerBound(offset, edge);
202
+ if (first === length || edge(first) !== offset) return void 0;
203
+ const start = ownedRangeStart(first);
204
+ const end = ownedRangeEnd(first);
205
+ while (first > 0 && ownedRangeStart(first - 1) === start && ownedRangeEnd(first - 1) === end) first--;
206
+ let last = first + 1;
207
+ while (last < length && ownedRangeStart(last) === start && ownedRangeEnd(last) === end) last++;
208
+ return [first, last];
209
+ };
210
+ const indices = (first, last) => {
211
+ const out = [];
212
+ for (let i = first; i < last; i++) out.push(i);
213
+ return out;
214
+ };
215
+ const makeGap = (first, last) => {
216
+ const start = ownedRangeStart(first);
217
+ const end = ownedRangeEnd(first);
218
+ let entryIndices;
219
+ return {
220
+ start,
221
+ end,
222
+ get entryIndices() {
223
+ return entryIndices ??= indices(first, last);
224
+ },
225
+ hasKind(kind) {
226
+ for (let i = first; i < last; i++) {
227
+ if (labels[markerKind(i)] === kind) return true;
228
+ }
229
+ return false;
230
+ },
231
+ text(input) {
232
+ return input.slice(start, end);
233
+ }
234
+ };
237
235
  };
238
- let first = 0;
239
- let start = entries.start(0);
240
- let end = entries.end(0);
241
- for (let i = 1; i < entries.length; i++) {
242
- const nextStart = entries.start(i);
243
- const nextEnd = entries.end(i);
244
- if (nextStart === end) {
245
- end = nextEnd;
246
- continue;
247
- }
248
- appendGap(first, i - 1, start, end);
249
- first = i;
250
- start = nextStart;
251
- end = nextEnd;
252
- }
253
- appendGap(first, entries.length - 1, start, end);
254
- return { before, after, beforeGaps, afterGaps, gaps };
255
- }
256
- function buildRootTriviaIndex(log, labels) {
257
- const entries = triviaEntries(log, labels);
258
236
  let maps;
259
237
  const getMaps = () => {
260
- maps ??= buildRootMaps(entries);
238
+ if (maps !== void 0) return maps;
239
+ const before = /* @__PURE__ */ new Map();
240
+ const after = /* @__PURE__ */ new Map();
241
+ const beforeGaps = /* @__PURE__ */ new Map();
242
+ const afterGaps = /* @__PURE__ */ new Map();
243
+ const gaps = [];
244
+ for (let first = 0; first < length; ) {
245
+ let last = first + 1;
246
+ while (last < length && ownedRangeStart(last) === ownedRangeStart(first) && ownedRangeEnd(last) === ownedRangeEnd(first)) last++;
247
+ const gap = makeGap(first, last);
248
+ gaps.push(gap);
249
+ afterGaps.set(gap.start, gap);
250
+ beforeGaps.set(gap.end, gap);
251
+ after.set(gap.start, [...gap.entryIndices]);
252
+ before.set(gap.end, [...gap.entryIndices]);
253
+ first = last;
254
+ }
255
+ maps = { before, after, beforeGaps, afterGaps, gaps };
261
256
  return maps;
262
257
  };
263
258
  return {
@@ -270,16 +265,20 @@ function buildRootTriviaIndex(log, labels) {
270
265
  return getMaps().after;
271
266
  },
272
267
  entryIndicesBefore(offset) {
273
- return getMaps().before.get(offset) ?? EMPTY_INDICES;
268
+ const rows = gapRowsAt(offset, "before");
269
+ return rows ? indices(rows[0], rows[1]) : EMPTY_INDICES;
274
270
  },
275
271
  entryIndicesAfter(offset) {
276
- return getMaps().after.get(offset) ?? EMPTY_INDICES;
272
+ const rows = gapRowsAt(offset, "after");
273
+ return rows ? indices(rows[0], rows[1]) : EMPTY_INDICES;
277
274
  },
278
275
  gapBefore(offset) {
279
- return getMaps().beforeGaps.get(offset);
276
+ const rows = gapRowsAt(offset, "before");
277
+ return rows ? makeGap(rows[0], rows[1]) : void 0;
280
278
  },
281
279
  gapAfter(offset) {
282
- return getMaps().afterGaps.get(offset);
280
+ const rows = gapRowsAt(offset, "after");
281
+ return rows ? makeGap(rows[0], rows[1]) : void 0;
283
282
  },
284
283
  gaps() {
285
284
  return getMaps().gaps;
@@ -287,13 +286,21 @@ function buildRootTriviaIndex(log, labels) {
287
286
  gapsWithKind(kind) {
288
287
  const kinds = typeof kind === "string" ? [kind] : kind;
289
288
  const matches2 = [];
290
- for (const gap of getMaps().gaps) {
291
- for (const k of kinds) {
292
- if (gap.hasKind(k)) {
293
- matches2.push(gap);
294
- break;
289
+ for (let first = 0; first < length; ) {
290
+ let last = first + 1;
291
+ while (last < length && ownedRangeStart(last) === ownedRangeStart(first) && ownedRangeEnd(last) === ownedRangeEnd(first)) last++;
292
+ let matched = false;
293
+ for (let i = first; i < last && !matched; i++) {
294
+ const label2 = labels[markerKind(i)];
295
+ for (const kind2 of kinds) {
296
+ if (label2 === kind2) {
297
+ matched = true;
298
+ break;
299
+ }
295
300
  }
296
301
  }
302
+ if (matched) matches2.push(makeGap(first, last));
303
+ first = last;
297
304
  }
298
305
  return matches2.length === 0 ? EMPTY_GAPS : matches2;
299
306
  }
@@ -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 r._meta.triviaKindLabels ?? grammarTrivia?._meta.triviaKindLabels ?? (r._def.tag === "grammar" ? r._def.triviaParser?._meta.triviaKindLabels : void 0);
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 triviaLog = [];
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 label2 of rootTriviaSelection) {
398
+ if (!triviaKindLabels.includes(label2)) {
399
+ throw new TypeError(`run(): rootTrivia.select contains unknown trivia label ${JSON.stringify(label2)}.`);
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 } : { _triviaLog: triviaLog, _errors: errors, ...profile === void 0 ? {} : { _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
- triviaLog,
375
- ...triviaKindLabels === void 0 ? {} : { triviaKindLabels },
376
- triviaMap: buildRootTriviaIndex(triviaLog, triviaKindLabels),
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
- if (typeof entry !== "function") {
395
- throw new TypeError("run({ profile: true }) requires a compiled parser entry");
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
 
413
466
  // src/combinators/completions.ts
@@ -432,6 +485,10 @@ var WORDS_RE = new RegExp(`^${WORD_RE_SRC}(?:\\|${WORD_RE_SRC})*$`);
432
485
 
433
486
  // src/compiler/scannable-run.ts
434
487
  var META = new Set("()[]{}*+?|^$.".split(""));
488
+ var SELECTED_ROOT_OWNED_RANGE_PLACEHOLDER = Array.from(
489
+ { length: SELECTED_ROOT_STRIDE - 3 },
490
+ () => "0"
491
+ ).join(", ");
435
492
 
436
493
  // src/compiler/trivia-fast-path.ts
437
494
  var CAP_RECORD = [
@@ -440,6 +497,18 @@ var CAP_RECORD = [
440
497
  ` if (_cap === 1 && _ctx._cstTriviaLog !== undefined && _ctx.captureTrivia) _ctx._cstTriviaLog.push(_pos, _e, _ctx._cstRawChildren ? _ctx._cstRawChildren.length : 0)`,
441
498
  ` }`
442
499
  ].join("\n");
500
+ var SELECTED_ROOT_FINISH = [
501
+ ` if (_cap && _ctx._rootTriviaCapture !== false && _ctx._rootTriviaLog !== undefined && _ctx._rootTriviaLog.length !== _rootMark) {`,
502
+ ` for (let _ri = _rootMark; _ri < _ctx._rootTriviaLog.length; _ri += ${SELECTED_ROOT_STRIDE}) { _ctx._rootTriviaLog[_ri] = _pos; _ctx._rootTriviaLog[_ri + 1] = _e }`,
503
+ ` }`
504
+ ].join("\n");
505
+
506
+ // src/compiler/inline-build.ts
507
+ var ANN = String.raw`\s*\??\s*(?::[^,)=]+)?`;
508
+ var ANY_P = String.raw`\w+${ANN}`;
509
+ var MK_BUILD_RE = new RegExp(
510
+ String.raw`^\(\s*(\w+)${ANN}\s*,\s*${ANY_P}\s*,\s*(\w+)${ANN}\s*,\s*(\w+)${ANN}\s*,\s*(\w+)${ANN}\s*\)\s*=>\s*mk\s*\(\s*(['"])([^'"]+)\5\s*,\s*\1\s*,\s*\3\s*,\s*\2\s*,\s*\4\s*\)\s*$`
511
+ );
443
512
 
444
513
  // src/compiler/linker.ts
445
514
  function normalizeCstCollapse(collapse) {