parseman 0.61.0 → 0.61.2

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.
@@ -84,7 +84,9 @@ export type AssemblyProfile = {
84
84
  /** The rule each corpus file is parsed from, e.g. `'Stylesheet'`. A grammar
85
85
  * without this rule keeps the static ranking. */
86
86
  readonly entry: string;
87
- /** Paths of representative inputs. */
87
+ /** Paths of representative inputs. At least one must have content, and each that
88
+ * does has to parse in full without recovery, or the build fails. A file with only
89
+ * whitespace counts as empty. */
88
90
  readonly files: readonly string[];
89
91
  };
90
92
  declare const _default: import("unplugin").UnpluginInstance<ParsecraftPluginOptions, boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AAyBA,OAAO,WAAW,MAAM,cAAc,CAAA;AActC,OAAO,EAAsC,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAA;AA6BxF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAA;AACzE;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,kBAAkB,EAAE,CAAA;CAAE,CAAA;AAChH,kDAAkD;AAClD,MAAM,MAAM,WAAW,GAAG,GAAG,CAAC,MAAM,EAAE,eAAe,EAAE,CAAC,CAAA;AACxD,eAAO,MAAM,sBAAsB,mBAAmB,CAAA;AAQtD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGnD;AA+BD,MAAM,MAAM,uBAAuB,GAAG;IACpC,8DAA8D;IAC9D,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA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AAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,aAAa,cAA6B,EAC1C,kBAAkB,UAAQ,EAC1B,QAAQ,UAAQ,EAChB,eAAe,UAAQ,EACvB,eAAe,CAAC,EAAE,eAAe,EACjC,cAAc,SAA0B,EACxC,WAAW,CAAC,EAAE,WAAW,GACxB,oBAAoB,GAAG,IAAI,CAW7B"}
@@ -5619,7 +5619,7 @@ function sourceLeaf(root, fn) {
5619
5619
  }
5620
5620
 
5621
5621
  // src/version.ts
5622
- var PARSEMAN_VERSION = "0.61.0";
5622
+ var PARSEMAN_VERSION = "0.61.2";
5623
5623
 
5624
5624
  // src/table/lex-body.ts
5625
5625
  function buildLexBodyRecognizer(spec, constants) {
@@ -10428,6 +10428,12 @@ function emitShapeMatch(shape, start, mint, ind, firstChar) {
10428
10428
 
10429
10429
  // src/table/child-slots.ts
10430
10430
  function childSlots(code, ip, out) {
10431
+ const from = out.length;
10432
+ if (!childSlotOffsets(code, ip, out)) return false;
10433
+ for (let i = from; i < out.length; i++) out[i] = code[out[i]];
10434
+ return true;
10435
+ }
10436
+ function childSlotOffsets(code, ip, out) {
10431
10437
  switch (code[ip]) {
10432
10438
  // ZERO-WIDTH / TERMINAL ROWS — no successor. `OP_GUARD` and `OP_ADJ` are both
10433
10439
  // childless tests. `OP_LIVE` holds a hand-written combinator in `prog.fns`; its
@@ -10460,7 +10466,7 @@ function childSlots(code, ip, out) {
10460
10466
  case OP_COV:
10461
10467
  case OP_REJECT:
10462
10468
  case OP_GAPGATE:
10463
- out.push(code[ip + 1]);
10469
+ out.push(ip + 1);
10464
10470
  return true;
10465
10471
  // Single child at `ip + 2`.
10466
10472
  case OP_GATE:
@@ -10477,55 +10483,55 @@ function childSlots(code, ip, out) {
10477
10483
  case OP_ARMGATE:
10478
10484
  case OP_RGATE:
10479
10485
  case OP_RGATE2:
10480
- out.push(code[ip + 2]);
10486
+ out.push(ip + 2);
10481
10487
  return true;
10482
10488
  // `STRICT strict tolerant` — both encodings are reachable; an assembly keeps one.
10483
10489
  case OP_STRICT:
10484
- out.push(code[ip + 1], code[ip + 2]);
10490
+ out.push(ip + 1, ip + 2);
10485
10491
  return true;
10486
10492
  // `ROUTED fallback` — the operand is an offset or −1. The routed token itself is
10487
10493
  // data the enclosing `dispatch()` already consumed, so the only edge is the
10488
10494
  // fallback.
10489
10495
  case OP_ROUTED:
10490
- if (code[ip + 1] >= 0) out.push(code[ip + 1]);
10496
+ if (code[ip + 1] >= 0) out.push(ip + 1);
10491
10497
  return true;
10492
10498
  // `DISPATCH sel d other otherRouted n a1 … an` — the SELECTOR is a child on
10493
10499
  // exactly the same footing as the arms: it runs inside whatever node and scope
10494
10500
  // this site sits in.
10495
10501
  case OP_DISPATCH: {
10496
- out.push(code[ip + 1]);
10497
- if (code[ip + 3] >= 0) out.push(code[ip + 3]);
10502
+ out.push(ip + 1);
10503
+ if (code[ip + 3] >= 0) out.push(ip + 3);
10498
10504
  const n = code[ip + 5];
10499
- for (let i = 0; i < n; i++) out.push(code[ip + 6 + i]);
10505
+ for (let i = 0; i < n; i++) out.push(ip + 6 + i);
10500
10506
  return true;
10501
10507
  }
10502
10508
  case OP_SEQ:
10503
10509
  case OP_SEQV: {
10504
10510
  const n = code[ip + 1];
10505
- for (let i = 0; i < n; i++) out.push(code[ip + 2 + i]);
10511
+ for (let i = 0; i < n; i++) out.push(ip + 2 + i);
10506
10512
  return true;
10507
10513
  }
10508
10514
  case OP_SEQX: {
10509
10515
  const n = code[ip + 2];
10510
- for (let i = 0; i < n; i++) out.push(code[ip + 3 + i]);
10516
+ for (let i = 0; i < n; i++) out.push(ip + 3 + i);
10511
10517
  return true;
10512
10518
  }
10513
10519
  case OP_CHOICE: {
10514
10520
  const n = code[ip + 2];
10515
- for (let i = 0; i < n; i++) out.push(code[ip + 4 + i]);
10521
+ for (let i = 0; i < n; i++) out.push(ip + 4 + i);
10516
10522
  return true;
10517
10523
  }
10518
10524
  // Arms are stride-2 from `ip + 4` — the gate word sits beside each arm offset.
10519
10525
  case OP_GREEDY: {
10520
- out.push(code[ip + 1]);
10526
+ out.push(ip + 1);
10521
10527
  const n = code[ip + 2];
10522
- for (let i = 0; i < n; i++) out.push(code[ip + 4 + 2 * i]);
10528
+ for (let i = 0; i < n; i++) out.push(ip + 4 + 2 * i);
10523
10529
  return true;
10524
10530
  }
10525
10531
  case OP_REP:
10526
10532
  case OP_REPV:
10527
- out.push(code[ip + 1]);
10528
- if (code[ip + 4] >= 0) out.push(code[ip + 4]);
10533
+ out.push(ip + 1);
10534
+ if (code[ip + 4] >= 0) out.push(ip + 4);
10529
10535
  return true;
10530
10536
  default:
10531
10537
  return false;
@@ -24326,23 +24332,45 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
24326
24332
  };
24327
24333
  const profileOf = (compiled) => {
24328
24334
  if (assemblyProfile === void 0 || compiled.hostMode !== "ast" || compiled.prog.lines === 1 || !(assemblyProfile.entry in compiled.prog.rules)) return void 0;
24329
- let parsed = 0;
24335
+ const refuse = (why) => {
24336
+ throw new Error(`${id} \u2014 assemblyProfile: ${why}`);
24337
+ };
24338
+ if (corpusTexts(assemblyProfile).every((text) => text.trim() === "")) refuse("`files` has no non-empty file");
24339
+ let thrower;
24330
24340
  const fns = compiled.prog.fns.map((fn) => {
24331
24341
  const type = fn?.[INERT_BUILDER];
24332
- return type === void 0 ? fn : (children3, _fields, span) => ({ type, span, children: children3 });
24342
+ if (type !== void 0) return (children3, _fields, span) => ({ type, span, children: children3 });
24343
+ return typeof fn !== "function" ? fn : new Proxy(fn, {
24344
+ apply(target, self, args) {
24345
+ try {
24346
+ return Reflect.apply(target, self, args);
24347
+ } catch (e) {
24348
+ thrower ??= target;
24349
+ throw e;
24350
+ }
24351
+ }
24352
+ });
24333
24353
  });
24334
- const counts = countSiteVisits(compiled.prog, (rules3) => {
24354
+ return countSiteVisits(compiled.prog, (rules3) => {
24335
24355
  const entry = rules3[assemblyProfile.entry];
24336
- for (const text of corpusTexts(assemblyProfile)) {
24356
+ corpusTexts(assemblyProfile).forEach((text, i) => {
24357
+ const file = assemblyProfile.files[i];
24358
+ if (text.trim() === "") return;
24359
+ let result2;
24337
24360
  try {
24338
- if (run(entry, text).ok) parsed++;
24339
- } catch {
24361
+ result2 = run(entry, text);
24362
+ } catch (e) {
24363
+ const source = String(thrower).replace(/\s+/g, " ").slice(0, 200);
24364
+ throw new Error(`${id} \u2014 assemblyProfile: ${thrower === void 0 ? "the parse" : `gate or reducer \`${source}\``} threw on ${file}: ${String(e)}`, { cause: e });
24340
24365
  }
24341
- }
24366
+ if (!result2.ok || result2.unconsumedFrom !== null) {
24367
+ refuse(`${file} does not parse from rule "${assemblyProfile.entry}": it stops at offset ${result2.ok ? result2.unconsumedFrom : result2.span.end}`);
24368
+ }
24369
+ if (result2.errors.length > 0) {
24370
+ refuse(`${file} parses only by recovering from ${result2.errors.length} error(s), first at offset ${result2.errors[0].span.start}`);
24371
+ }
24372
+ });
24342
24373
  }, fns);
24343
- if (parsed > 0) return counts;
24344
- warnings.push(`${id} \u2014 assemblyProfile: no corpus file parsed from rule "${assemblyProfile.entry}"; using the static ranking`);
24345
- return void 0;
24346
24374
  };
24347
24375
  const assembledReplacement = (compiled, metadata, select) => select.size === 0 ? compiled.replacementWithMetadata(metadata) : supercompileRuleMapReplacement(compiled.prog, compiled.replacementWithMetadata(metadata, { select }), select);
24348
24376
  const compileComposeLeafCall = (init) => {