parseman 0.55.0 → 0.55.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/table/encode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,UAAU,EAAuB,MAAM,aAAa,CAAA;AAyBhF,OAAO,KAAK,EAAmE,YAAY,EAAc,MAAM,cAAc,CAAA;AAS7H,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AA0B9E,8EAA8E;AAC9E,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,YAAY,GAAG,EAAE,MAAM,EAAqE;CAC7F;AAED,8EAA8E;AAC9E,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;IACjC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;IAC7B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAA;CACxC,CAAA;AAmvDD,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC5C,QAAQ,GAAE,aAAkB,GAC3B,YAAY,CAEd;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC5C,QAAQ,GAAE,aAAkB,GAC3B;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAA;CAAE,CA+BnD"}
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/table/encode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,UAAU,EAAuB,MAAM,aAAa,CAAA;AAyBhF,OAAO,KAAK,EAAmE,YAAY,EAAc,MAAM,cAAc,CAAA;AAS7H,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AA0B9E,8EAA8E;AAC9E,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,YAAY,GAAG,EAAE,MAAM,EAAqE;CAC7F;AAED,8EAA8E;AAC9E,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;IACjC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;IAC7B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAA;CACxC,CAAA;AA2wDD,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC5C,QAAQ,GAAE,aAAkB,GAC3B,YAAY,CAEd;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC5C,QAAQ,GAAE,aAAkB,GAC3B;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAA;CAAE,CA+BnD"}
@@ -12421,19 +12421,11 @@ var Encoder = class {
12421
12421
  nonCommittingChoiceSites = /* @__PURE__ */ new Set();
12422
12422
  failureRollbackCleanSites = /* @__PURE__ */ new Set();
12423
12423
  /**
12424
- * `hasSideWriter` memo for `failureNeedsRollback`, shared across every call
12425
- * for the lifetime of this `Encoder`. A cached entry is written only when
12426
- * `complete` is true, which means the answer is a path-independent fact
12427
- * about that combinator node — it does not depend on which root's traversal
12428
- * asked, only on the node's own reachable subgraph. Scoping the memo per call
12429
- * (as a local inside `failureNeedsRollback`) was correct but discarded that
12430
- * fact after every arm, so a grammar with many ordered-choice arms / optional
12431
- * / attempt sites re-walked the SAME shared rule graph from scratch for each
12432
- * site — O(sites × graph size) instead of O(graph size). Measured on the
12433
- * scss-parser grammar (composed CSS-base superset, the deepest/largest of the
12434
- * four grammars): 47-50s for one `compileRuleMap` with the per-call memo,
12435
- * versus the whole macro transform completing in under a second once this
12436
- * memo is hoisted here.
12424
+ * `reachesSideWriter`'s answers, shared by every `failureNeedsRollback` call
12425
+ * for the lifetime of this `Encoder`. Every entry is exact — it depends only on
12426
+ * the node's own reachable subgraph, never on which root's walk asked — so each
12427
+ * combinator is walked once per encode however many choice arms, optionals and
12428
+ * attempt sites reach it.
12437
12429
  */
12438
12430
  sideWriterMemo = /* @__PURE__ */ new Map();
12439
12431
  labels = void 0;
@@ -12866,63 +12858,96 @@ var Encoder = class {
12866
12858
  * writer census covers the side sinks that proof deliberately does not model:
12867
12859
  * fields, recovered errors, and interpreted scanners. Strict assemblies do
12868
12860
  * not run repeat recovery, but these rows can still publish through a caller's
12869
- * context. Cycles are safe to stop: revisiting the same combinator cannot
12870
- * discover a writer the first traversal did not already reach.
12861
+ * context.
12871
12862
  */
12872
12863
  failureNeedsRollback(p, autoNot) {
12873
12864
  const refName = p._ruleName;
12874
12865
  const winner = refName === void 0 ? void 0 : this.winners?.[refName];
12875
12866
  const root = winner !== void 0 && !winnerWrapsReference2(winner, p) ? winner : p;
12876
- const sideWriterMemo = this.sideWriterMemo;
12877
- const seen = /* @__PURE__ */ new Set();
12878
- const hasSideWriter = (current) => {
12879
- const cached = sideWriterMemo.get(current);
12880
- if (cached !== void 0) return { found: cached, complete: true };
12881
- if (seen.has(current)) return { found: false, complete: false };
12882
- seen.add(current);
12883
- const def = current._def;
12884
- let result;
12885
- switch (def.tag) {
12886
- case "field":
12887
- case "expect":
12888
- case "recover":
12889
- case "scanTo":
12890
- case "unknown":
12891
- result = { found: true, complete: true };
12892
- break;
12893
- case "lazy": {
12894
- const name = current._ruleName;
12895
- const resolvedWinner = name === void 0 ? void 0 : this.winners?.[name];
12896
- if (resolvedWinner !== void 0 && !winnerWrapsReference2(resolvedWinner, current)) {
12897
- result = hasSideWriter(resolvedWinner);
12898
- break;
12899
- }
12900
- try {
12901
- result = hasSideWriter(def.thunk());
12902
- } catch {
12903
- result = { found: true, complete: true };
12867
+ return mayLeavePartialCapture(root, /* @__PURE__ */ new Set(), true) || this.reachesSideWriter(root) || (autoNot?.length ?? 0) > 0 && capturesLeaf(root);
12868
+ }
12869
+ /**
12870
+ * Whether a field, recovered error, interpreted scanner or unresolvable shape
12871
+ * is reachable from `root` — the writer census of `failureNeedsRollback`.
12872
+ *
12873
+ * Reachability over a cyclic graph, decided with Tarjan's strongly connected
12874
+ * components so that every node the walk enters leaves with its exact answer
12875
+ * memoized: the members of one component reach each other, so they share one
12876
+ * answer, settled when the walk returns to the component's first node. A DFS
12877
+ * that instead cuts a cycle at its own ancestor path learns nothing it can
12878
+ * keep about a node whose walk hit the cut, and re-walks that node along
12879
+ * every path that reaches it — exponential over recursive value rules (linking
12880
+ * jess's SCSS grammar cost ~290G instructions). This walk enters each node
12881
+ * once per `Encoder`.
12882
+ */
12883
+ reachesSideWriter(root) {
12884
+ const memo = this.sideWriterMemo;
12885
+ const known = memo.get(root);
12886
+ if (known !== void 0) return known;
12887
+ const order = /* @__PURE__ */ new Map();
12888
+ const low = [];
12889
+ const found = [];
12890
+ const stack = [];
12891
+ const visit = (node) => {
12892
+ const at = low.length;
12893
+ order.set(node, at);
12894
+ low.push(at);
12895
+ found.push(false);
12896
+ stack.push(node);
12897
+ const next = this.sideWriterSuccessors(node);
12898
+ if (next === true) found[at] = true;
12899
+ else {
12900
+ for (const child of next) {
12901
+ const hit = memo.get(child);
12902
+ if (hit !== void 0) {
12903
+ if (hit) found[at] = true;
12904
+ continue;
12904
12905
  }
12905
- break;
12906
- }
12907
- default: {
12908
- let complete = true;
12909
- result = { found: false, complete: true };
12910
- for (const child of childrenOf(def)) {
12911
- const childResult = hasSideWriter(child);
12912
- if (childResult.found) {
12913
- result = { found: true, complete: true };
12914
- break;
12915
- }
12916
- complete &&= childResult.complete;
12906
+ const seen = order.get(child);
12907
+ if (seen !== void 0) {
12908
+ if (seen < low[at]) low[at] = seen;
12909
+ continue;
12917
12910
  }
12918
- if (!result.found) result = { found: false, complete };
12911
+ const k = visit(child);
12912
+ if (low[k] < low[at]) low[at] = low[k];
12913
+ if (found[k]) found[at] = true;
12919
12914
  }
12920
12915
  }
12921
- seen.delete(current);
12922
- if (result.found || result.complete) sideWriterMemo.set(current, result.found);
12923
- return result;
12916
+ if (low[at] === at) {
12917
+ const answer = found[at];
12918
+ let member;
12919
+ do {
12920
+ member = stack.pop();
12921
+ memo.set(member, answer);
12922
+ } while (member !== node);
12923
+ }
12924
+ return at;
12924
12925
  };
12925
- return mayLeavePartialCapture(root, /* @__PURE__ */ new Set(), true) || hasSideWriter(root).found || (autoNot?.length ?? 0) > 0 && capturesLeaf(root);
12926
+ return found[visit(root)];
12927
+ }
12928
+ /** The census's edges out of `node`, or `true` when `node` is itself a writer. */
12929
+ sideWriterSuccessors(node) {
12930
+ const def = node._def;
12931
+ switch (def.tag) {
12932
+ case "field":
12933
+ case "expect":
12934
+ case "recover":
12935
+ case "scanTo":
12936
+ case "unknown":
12937
+ return true;
12938
+ case "lazy": {
12939
+ const name = node._ruleName;
12940
+ const winner = name === void 0 ? void 0 : this.winners?.[name];
12941
+ if (winner !== void 0 && !winnerWrapsReference2(winner, node)) return [winner];
12942
+ try {
12943
+ return [def.thunk()];
12944
+ } catch {
12945
+ return true;
12946
+ }
12947
+ }
12948
+ default:
12949
+ return childrenOf(def);
12950
+ }
12926
12951
  }
12927
12952
  /** A first set becomes a char class string, or −1 for `any`. */
12928
12953
  charClass(fs) {