parseman 0.55.0 → 0.55.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.
- package/dist/analysis/commitment.d.ts +27 -2
- package/dist/analysis/commitment.d.ts.map +1 -1
- package/dist/analysis/diagnostics.js +110 -80
- package/dist/analysis/diagnostics.js.map +2 -2
- package/dist/cli/index.js +110 -80
- package/dist/cli/index.js.map +2 -2
- package/dist/index.js +111 -81
- package/dist/index.js.map +2 -2
- package/dist/plugin/index.js +111 -81
- package/dist/plugin/index.js.map +2 -2
- package/dist/table/encode.d.ts.map +1 -1
- package/dist/table/index.js +110 -80
- package/dist/table/index.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/analysis/commitment.ts +107 -20
- package/src/table/encode.ts +47 -70
- package/src/version.ts +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -3703,19 +3703,22 @@ function hasDirectBuildDef(p, seen = /* @__PURE__ */ new Set()) {
|
|
|
3703
3703
|
return false;
|
|
3704
3704
|
}
|
|
3705
3705
|
}
|
|
3706
|
-
function mayCommitFailure(p,
|
|
3707
|
-
|
|
3708
|
-
|
|
3706
|
+
function mayCommitFailure(p, resolve2, memo = /* @__PURE__ */ new Map()) {
|
|
3707
|
+
return reachesMarked(p, (node2) => commitFailureSuccessors(node2, resolve2), memo);
|
|
3708
|
+
}
|
|
3709
|
+
var NO_EDGES = [];
|
|
3710
|
+
function commitFailureSuccessors(p, resolve2) {
|
|
3709
3711
|
const d = p._def;
|
|
3710
3712
|
switch (d.tag) {
|
|
3711
3713
|
case "dispatch":
|
|
3714
|
+
case "unknown":
|
|
3712
3715
|
return true;
|
|
3713
3716
|
case "choice":
|
|
3714
3717
|
case "sequence":
|
|
3715
|
-
return d.parsers
|
|
3718
|
+
return d.parsers;
|
|
3716
3719
|
// A contained transaction reports every failure uncommitted.
|
|
3717
3720
|
case "attempt":
|
|
3718
|
-
return d.contain
|
|
3721
|
+
return d.contain === true ? NO_EDGES : [d.parser];
|
|
3719
3722
|
case "many":
|
|
3720
3723
|
case "oneOrMore":
|
|
3721
3724
|
case "optional":
|
|
@@ -3724,31 +3727,77 @@ function mayCommitFailure(p, seen = /* @__PURE__ */ new Set(), resolve2) {
|
|
|
3724
3727
|
case "field":
|
|
3725
3728
|
case "grammar":
|
|
3726
3729
|
case "node":
|
|
3727
|
-
return mayCommitFailure(d.parser, seen, resolve2);
|
|
3728
|
-
case "sepBy":
|
|
3729
|
-
return mayCommitFailure(d.parser, seen, resolve2) || mayCommitFailure(d.separator, seen, resolve2);
|
|
3730
3730
|
case "token":
|
|
3731
3731
|
case "leaf":
|
|
3732
|
-
return mayCommitFailure(d.parser, seen, resolve2);
|
|
3733
3732
|
case "withCtx":
|
|
3734
|
-
return
|
|
3733
|
+
return [d.parser];
|
|
3734
|
+
case "sepBy":
|
|
3735
|
+
return [d.parser, d.separator];
|
|
3735
3736
|
case "scanTo":
|
|
3736
|
-
return
|
|
3737
|
+
return [
|
|
3738
|
+
d.sentinel,
|
|
3739
|
+
...d.skip,
|
|
3740
|
+
...d.recoverAt === void 0 ? NO_EDGES : [d.recoverAt],
|
|
3741
|
+
...d.stopAt === void 0 ? NO_EDGES : [d.stopAt]
|
|
3742
|
+
];
|
|
3737
3743
|
case "lazy": {
|
|
3738
3744
|
try {
|
|
3739
|
-
return
|
|
3745
|
+
return [d.thunk()];
|
|
3740
3746
|
} catch {
|
|
3741
3747
|
const name = p._ruleName;
|
|
3742
3748
|
const target = name === void 0 ? void 0 : resolve2?.(name);
|
|
3743
|
-
return target === void 0 ? true :
|
|
3749
|
+
return target === void 0 ? true : [target];
|
|
3744
3750
|
}
|
|
3745
3751
|
}
|
|
3746
|
-
case "unknown":
|
|
3747
|
-
return true;
|
|
3748
3752
|
default:
|
|
3749
|
-
return
|
|
3753
|
+
return NO_EDGES;
|
|
3750
3754
|
}
|
|
3751
3755
|
}
|
|
3756
|
+
function reachesMarked(root, successors, memo) {
|
|
3757
|
+
const known = memo.get(root);
|
|
3758
|
+
if (known !== void 0) return known;
|
|
3759
|
+
const order = /* @__PURE__ */ new Map();
|
|
3760
|
+
const low = [];
|
|
3761
|
+
const found = [];
|
|
3762
|
+
const stack = [];
|
|
3763
|
+
const visit = (node2) => {
|
|
3764
|
+
const at = low.length;
|
|
3765
|
+
order.set(node2, at);
|
|
3766
|
+
low.push(at);
|
|
3767
|
+
found.push(false);
|
|
3768
|
+
stack.push(node2);
|
|
3769
|
+
const next = successors(node2);
|
|
3770
|
+
if (next === true) found[at] = true;
|
|
3771
|
+
else {
|
|
3772
|
+
for (const child of next) {
|
|
3773
|
+
if (found[at]) break;
|
|
3774
|
+
const hit = memo.get(child);
|
|
3775
|
+
if (hit !== void 0) {
|
|
3776
|
+
if (hit) found[at] = true;
|
|
3777
|
+
continue;
|
|
3778
|
+
}
|
|
3779
|
+
const seen = order.get(child);
|
|
3780
|
+
if (seen !== void 0) {
|
|
3781
|
+
if (seen < low[at]) low[at] = seen;
|
|
3782
|
+
continue;
|
|
3783
|
+
}
|
|
3784
|
+
const k = visit(child);
|
|
3785
|
+
if (low[k] < low[at]) low[at] = low[k];
|
|
3786
|
+
if (found[k]) found[at] = true;
|
|
3787
|
+
}
|
|
3788
|
+
}
|
|
3789
|
+
if (low[at] === at) {
|
|
3790
|
+
const answer = found[at];
|
|
3791
|
+
let member;
|
|
3792
|
+
do {
|
|
3793
|
+
member = stack.pop();
|
|
3794
|
+
memo.set(member, answer);
|
|
3795
|
+
} while (member !== node2);
|
|
3796
|
+
}
|
|
3797
|
+
return at;
|
|
3798
|
+
};
|
|
3799
|
+
return found[visit(root)];
|
|
3800
|
+
}
|
|
3752
3801
|
|
|
3753
3802
|
// src/combinators/scalar.ts
|
|
3754
3803
|
var SCALAR_TAG = /^(?:literal|regex|keywords|sequence|choice|many|oneOrMore|optional|transform|trivia|grammar|sepBy|lazy)$/;
|
|
@@ -6107,21 +6156,20 @@ var Encoder = class {
|
|
|
6107
6156
|
nonCommittingChoiceSites = /* @__PURE__ */ new Set();
|
|
6108
6157
|
failureRollbackCleanSites = /* @__PURE__ */ new Set();
|
|
6109
6158
|
/**
|
|
6110
|
-
* `
|
|
6111
|
-
* for the lifetime of this `Encoder`.
|
|
6112
|
-
*
|
|
6113
|
-
*
|
|
6114
|
-
*
|
|
6115
|
-
* (as a local inside `failureNeedsRollback`) was correct but discarded that
|
|
6116
|
-
* fact after every arm, so a grammar with many ordered-choice arms / optional
|
|
6117
|
-
* / attempt sites re-walked the SAME shared rule graph from scratch for each
|
|
6118
|
-
* site — O(sites × graph size) instead of O(graph size). Measured on the
|
|
6119
|
-
* scss-parser grammar (composed CSS-base superset, the deepest/largest of the
|
|
6120
|
-
* four grammars): 47-50s for one `compileRuleMap` with the per-call memo,
|
|
6121
|
-
* versus the whole macro transform completing in under a second once this
|
|
6122
|
-
* memo is hoisted here.
|
|
6159
|
+
* `reachesSideWriter`'s answers, shared by every `failureNeedsRollback` call
|
|
6160
|
+
* for the lifetime of this `Encoder`. Every entry is exact — it depends only on
|
|
6161
|
+
* the node's own reachable subgraph, never on which root's walk asked — so each
|
|
6162
|
+
* combinator is walked once per encode however many choice arms, optionals and
|
|
6163
|
+
* attempt sites reach it.
|
|
6123
6164
|
*/
|
|
6124
6165
|
sideWriterMemo = /* @__PURE__ */ new Map();
|
|
6166
|
+
/**
|
|
6167
|
+
* `mayCommitFailure`'s answers, shared by every choice site for the lifetime
|
|
6168
|
+
* of this `Encoder` — exact for the graph and the `winners` resolver it is
|
|
6169
|
+
* encoding, so the rule graph is walked once per encode rather than once per
|
|
6170
|
+
* choice site.
|
|
6171
|
+
*/
|
|
6172
|
+
commitFailureMemo = /* @__PURE__ */ new Map();
|
|
6125
6173
|
labels = void 0;
|
|
6126
6174
|
/** Trivia table in scope at the row being encoded — codegen's `ctx.activeTrivia`. */
|
|
6127
6175
|
activeTrivia = void 0;
|
|
@@ -6552,63 +6600,45 @@ var Encoder = class {
|
|
|
6552
6600
|
* writer census covers the side sinks that proof deliberately does not model:
|
|
6553
6601
|
* fields, recovered errors, and interpreted scanners. Strict assemblies do
|
|
6554
6602
|
* not run repeat recovery, but these rows can still publish through a caller's
|
|
6555
|
-
* context.
|
|
6556
|
-
* discover a writer the first traversal did not already reach.
|
|
6603
|
+
* context.
|
|
6557
6604
|
*/
|
|
6558
6605
|
failureNeedsRollback(p, autoNot) {
|
|
6559
6606
|
const refName = p._ruleName;
|
|
6560
6607
|
const winner = refName === void 0 ? void 0 : this.winners?.[refName];
|
|
6561
6608
|
const root = winner !== void 0 && !winnerWrapsReference2(winner, p) ? winner : p;
|
|
6562
|
-
|
|
6563
|
-
|
|
6564
|
-
|
|
6565
|
-
|
|
6566
|
-
|
|
6567
|
-
|
|
6568
|
-
|
|
6569
|
-
|
|
6570
|
-
|
|
6571
|
-
|
|
6572
|
-
|
|
6573
|
-
|
|
6574
|
-
|
|
6575
|
-
|
|
6576
|
-
|
|
6577
|
-
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
6581
|
-
|
|
6582
|
-
|
|
6583
|
-
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
|
|
6590
|
-
}
|
|
6591
|
-
break;
|
|
6592
|
-
}
|
|
6593
|
-
default: {
|
|
6594
|
-
let complete = true;
|
|
6595
|
-
result = { found: false, complete: true };
|
|
6596
|
-
for (const child of childrenOf(def)) {
|
|
6597
|
-
const childResult = hasSideWriter(child);
|
|
6598
|
-
if (childResult.found) {
|
|
6599
|
-
result = { found: true, complete: true };
|
|
6600
|
-
break;
|
|
6601
|
-
}
|
|
6602
|
-
complete &&= childResult.complete;
|
|
6603
|
-
}
|
|
6604
|
-
if (!result.found) result = { found: false, complete };
|
|
6609
|
+
return mayLeavePartialCapture(root, /* @__PURE__ */ new Set(), true) || this.reachesSideWriter(root) || (autoNot?.length ?? 0) > 0 && capturesLeaf(root);
|
|
6610
|
+
}
|
|
6611
|
+
/**
|
|
6612
|
+
* Whether a field, recovered error, interpreted scanner or unresolvable shape
|
|
6613
|
+
* is reachable from `root` — the writer census of `failureNeedsRollback`,
|
|
6614
|
+
* entering each combinator once per `Encoder` (see `reachesMarked`).
|
|
6615
|
+
*/
|
|
6616
|
+
reachesSideWriter(root) {
|
|
6617
|
+
return reachesMarked(root, (node2) => this.sideWriterSuccessors(node2), this.sideWriterMemo);
|
|
6618
|
+
}
|
|
6619
|
+
/** The census's edges out of `node`, or `true` when `node` is itself a writer. */
|
|
6620
|
+
sideWriterSuccessors(node2) {
|
|
6621
|
+
const def = node2._def;
|
|
6622
|
+
switch (def.tag) {
|
|
6623
|
+
case "field":
|
|
6624
|
+
case "expect":
|
|
6625
|
+
case "recover":
|
|
6626
|
+
case "scanTo":
|
|
6627
|
+
case "unknown":
|
|
6628
|
+
return true;
|
|
6629
|
+
case "lazy": {
|
|
6630
|
+
const name = node2._ruleName;
|
|
6631
|
+
const winner = name === void 0 ? void 0 : this.winners?.[name];
|
|
6632
|
+
if (winner !== void 0 && !winnerWrapsReference2(winner, node2)) return [winner];
|
|
6633
|
+
try {
|
|
6634
|
+
return [def.thunk()];
|
|
6635
|
+
} catch {
|
|
6636
|
+
return true;
|
|
6605
6637
|
}
|
|
6606
6638
|
}
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
|
|
6610
|
-
};
|
|
6611
|
-
return mayLeavePartialCapture(root, /* @__PURE__ */ new Set(), true) || hasSideWriter(root).found || (autoNot?.length ?? 0) > 0 && capturesLeaf(root);
|
|
6639
|
+
default:
|
|
6640
|
+
return childrenOf(def);
|
|
6641
|
+
}
|
|
6612
6642
|
}
|
|
6613
6643
|
/** A first set becomes a char class string, or −1 for `any`. */
|
|
6614
6644
|
charClass(fs) {
|
|
@@ -6939,7 +6969,7 @@ var Encoder = class {
|
|
|
6939
6969
|
this.code[head + 4 + kids.length + i] = this.expected(deriveExpected(arms[i]));
|
|
6940
6970
|
}
|
|
6941
6971
|
this.choiceRollbackMasks.set(head, rollbackMask);
|
|
6942
|
-
if (arms.every((arm) => !mayCommitFailure(arm,
|
|
6972
|
+
if (arms.every((arm) => !mayCommitFailure(arm, rr, this.commitFailureMemo))) {
|
|
6943
6973
|
this.nonCommittingChoiceSites.add(head);
|
|
6944
6974
|
}
|
|
6945
6975
|
return head;
|