parseman 0.60.2 → 0.60.3
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 +1 -1
- package/dist/analysis/commitment.d.ts.map +1 -1
- package/dist/analysis/diagnostics.js +128 -43
- package/dist/analysis/diagnostics.js.map +2 -2
- package/dist/cli/index.js +128 -43
- package/dist/cli/index.js.map +2 -2
- package/dist/index.js +128 -43
- package/dist/index.js.map +2 -2
- package/dist/plugin/index.js +128 -43
- package/dist/plugin/index.js.map +2 -2
- package/dist/table/assemble.d.ts +11 -0
- package/dist/table/assemble.d.ts.map +1 -1
- package/dist/table/emit-assembly.d.ts +1 -0
- package/dist/table/emit-assembly.d.ts.map +1 -1
- package/dist/table/encode.d.ts.map +1 -1
- package/dist/table/exec.d.ts.map +1 -1
- package/dist/table/index.js +128 -43
- package/dist/table/index.js.map +2 -2
- package/dist/table/program.d.ts +9 -0
- package/dist/table/program.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/analysis/commitment.ts +29 -15
- package/src/table/assemble.ts +35 -10
- package/src/table/emit-assembly.ts +41 -11
- package/src/table/encode.ts +57 -9
- package/src/table/exec.ts +5 -2
- package/src/table/program.ts +19 -0
- package/src/version.ts +1 -1
package/dist/plugin/index.js
CHANGED
|
@@ -6217,7 +6217,9 @@ function ownTableProgram(prog, resolved, caches = {}) {
|
|
|
6217
6217
|
resolved,
|
|
6218
6218
|
choiceRollbackMasks: caches.choiceRollbackMasks ?? runtime?.choiceRollbackMasks,
|
|
6219
6219
|
nonCommittingChoiceSites: caches.nonCommittingChoiceSites ?? runtime?.nonCommittingChoiceSites,
|
|
6220
|
-
failureRollbackCleanSites: caches.failureRollbackCleanSites ?? runtime?.failureRollbackCleanSites
|
|
6220
|
+
failureRollbackCleanSites: caches.failureRollbackCleanSites ?? runtime?.failureRollbackCleanSites,
|
|
6221
|
+
choiceLogRollbackMasks: caches.choiceLogRollbackMasks ?? runtime?.choiceLogRollbackMasks,
|
|
6222
|
+
failureLogRollbackSites: caches.failureLogRollbackSites ?? runtime?.failureLogRollbackSites
|
|
6221
6223
|
}
|
|
6222
6224
|
};
|
|
6223
6225
|
}
|
|
@@ -6230,6 +6232,12 @@ function choiceCannotCommit(prog, ip) {
|
|
|
6230
6232
|
function failureRollbackClean(prog, ip) {
|
|
6231
6233
|
return prog[TABLE_RUNTIME]?.failureRollbackCleanSites?.has(ip) === true;
|
|
6232
6234
|
}
|
|
6235
|
+
function choiceLogRollbackMask(prog, ip) {
|
|
6236
|
+
return prog[TABLE_RUNTIME]?.choiceLogRollbackMasks?.get(ip) ?? 0;
|
|
6237
|
+
}
|
|
6238
|
+
function failureLogRollback(prog, ip) {
|
|
6239
|
+
return prog[TABLE_RUNTIME]?.failureLogRollbackSites?.has(ip) === true;
|
|
6240
|
+
}
|
|
6233
6241
|
var WIDE_CLASS_PREFIX_LO = 65535;
|
|
6234
6242
|
var WIDE_CLASS_PREFIX_HI = 0;
|
|
6235
6243
|
function validateClassRange(lo, hi) {
|
|
@@ -6492,7 +6500,7 @@ function mayFail(p, seen = /* @__PURE__ */ new Set()) {
|
|
|
6492
6500
|
return true;
|
|
6493
6501
|
}
|
|
6494
6502
|
}
|
|
6495
|
-
function mayLeavePartialCapture(p, seen = /* @__PURE__ */ new Set(), triviaActive = true) {
|
|
6503
|
+
function mayLeavePartialCapture(p, seen = /* @__PURE__ */ new Set(), triviaActive = true, throughNodes = false) {
|
|
6496
6504
|
if (seen.has(p)) return false;
|
|
6497
6505
|
seen.add(p);
|
|
6498
6506
|
const d = p._def;
|
|
@@ -6517,17 +6525,26 @@ function mayLeavePartialCapture(p, seen = /* @__PURE__ */ new Set(), triviaActiv
|
|
|
6517
6525
|
return false;
|
|
6518
6526
|
// A run's prefixes are probed detached; only its body can capture.
|
|
6519
6527
|
case "lines":
|
|
6520
|
-
return mayLeavePartialCapture(d.body, seen, triviaActive);
|
|
6521
|
-
// node() captures into its own
|
|
6522
|
-
// failure
|
|
6528
|
+
return mayLeavePartialCapture(d.body, seen, triviaActive, throughNodes);
|
|
6529
|
+
// node() captures its children into a frame of its own and drops it on
|
|
6530
|
+
// failure. The trivia logs (`_triviaLog`, `_rootTriviaLog`) are not part of
|
|
6531
|
+
// that frame: trivia its body scanned before failing stays recorded. With
|
|
6532
|
+
// `throughNodes` (a program that installs trivia somewhere) a node leaves
|
|
6533
|
+
// what its body leaves; without, it leaves nothing.
|
|
6523
6534
|
case "node":
|
|
6524
|
-
return
|
|
6525
|
-
// choice/firstMatch already roll back each failed arm; on overall
|
|
6526
|
-
// nothing committed remains.
|
|
6535
|
+
return throughNodes && mayLeavePartialCapture(d.parser, seen, triviaActive, throughNodes);
|
|
6536
|
+
// choice/firstMatch already roll back each failed arm's captures; on overall
|
|
6537
|
+
// failure nothing committed remains. The trivia logs are the exception: a
|
|
6538
|
+
// choice the table lowers as an exclusive dispatch runs its one selected arm
|
|
6539
|
+
// with no mark of its own (`emit-assembly.ts`, `table.exclusive`), so the
|
|
6540
|
+
// rows that arm's trivia scans recorded stay when it fails. With
|
|
6541
|
+
// `throughNodes` a choice leaves what one of its arms leaves, unless
|
|
6542
|
+
// `throughNodes` is the encoder's answer that this choice marks and restores
|
|
6543
|
+
// each arm it enters.
|
|
6527
6544
|
case "choice":
|
|
6528
|
-
return false;
|
|
6545
|
+
return throughNodes !== false && !(typeof throughNodes === "function" && throughNodes(p)) && d.parsers.some((arm) => mayLeavePartialCapture(arm, new Set(seen), triviaActive, throughNodes));
|
|
6529
6546
|
case "dispatch":
|
|
6530
|
-
return capturesLeaf(d.selector, new Set(seen)) || d.cases.some((x) => mayLeavePartialCapture(x.parser, new Set(seen), triviaActive) || capturesLeaf(x.parser, new Set(seen))) || (d.matchers ? d.matchers.some((x) => mayLeavePartialCapture(x.parser, new Set(seen), triviaActive) || capturesLeaf(x.parser, new Set(seen))) : false) || (d.otherwise ? mayLeavePartialCapture(d.otherwise, new Set(seen), triviaActive) || capturesLeaf(d.otherwise, new Set(seen)) : false);
|
|
6547
|
+
return capturesLeaf(d.selector, new Set(seen)) || d.cases.some((x) => mayLeavePartialCapture(x.parser, new Set(seen), triviaActive, throughNodes) || capturesLeaf(x.parser, new Set(seen))) || (d.matchers ? d.matchers.some((x) => mayLeavePartialCapture(x.parser, new Set(seen), triviaActive, throughNodes) || capturesLeaf(x.parser, new Set(seen))) : false) || (d.otherwise ? mayLeavePartialCapture(d.otherwise, new Set(seen), triviaActive, throughNodes) || capturesLeaf(d.otherwise, new Set(seen)) : false);
|
|
6531
6548
|
case "attempt":
|
|
6532
6549
|
return false;
|
|
6533
6550
|
// optional never fails; many/oneOrMore only "fail" with zero captured items.
|
|
@@ -6569,7 +6586,7 @@ function mayLeavePartialCapture(p, seen = /* @__PURE__ */ new Set(), triviaActiv
|
|
|
6569
6586
|
const part = parts[i];
|
|
6570
6587
|
if (i > 0 && triviaActive) captured = true;
|
|
6571
6588
|
if (captured && mayFail(part)) return true;
|
|
6572
|
-
if (mayLeavePartialCapture(part, seen, triviaActive)) return true;
|
|
6589
|
+
if (mayLeavePartialCapture(part, seen, triviaActive, throughNodes)) return true;
|
|
6573
6590
|
if (capturesLeaf(part) || hasNodeDef(part)) captured = true;
|
|
6574
6591
|
}
|
|
6575
6592
|
return false;
|
|
@@ -6581,12 +6598,12 @@ function mayLeavePartialCapture(p, seen = /* @__PURE__ */ new Set(), triviaActiv
|
|
|
6581
6598
|
case "expect":
|
|
6582
6599
|
case "withCtx":
|
|
6583
6600
|
case "grammar":
|
|
6584
|
-
return mayLeavePartialCapture(d.parser, seen, triviaActive);
|
|
6601
|
+
return mayLeavePartialCapture(d.parser, seen, triviaActive, throughNodes);
|
|
6585
6602
|
case "recover":
|
|
6586
|
-
return mayLeavePartialCapture(d.parser, seen, triviaActive);
|
|
6603
|
+
return mayLeavePartialCapture(d.parser, seen, triviaActive, throughNodes);
|
|
6587
6604
|
case "lazy": {
|
|
6588
6605
|
try {
|
|
6589
|
-
return mayLeavePartialCapture(d.thunk(), seen, triviaActive);
|
|
6606
|
+
return mayLeavePartialCapture(d.thunk(), seen, triviaActive, throughNodes);
|
|
6590
6607
|
} catch {
|
|
6591
6608
|
return true;
|
|
6592
6609
|
}
|
|
@@ -7589,6 +7606,32 @@ var Encoder = class {
|
|
|
7589
7606
|
choiceRollbackMasks = /* @__PURE__ */ new Map();
|
|
7590
7607
|
nonCommittingChoiceSites = /* @__PURE__ */ new Set();
|
|
7591
7608
|
failureRollbackCleanSites = /* @__PURE__ */ new Set();
|
|
7609
|
+
/**
|
|
7610
|
+
* THE TRIVIA LOGS A FAILED NODE LEAVES. A node drops its own capture frame when
|
|
7611
|
+
* it fails, but the trivia its body recorded into `_triviaLog`/`_rootTriviaLog`
|
|
7612
|
+
* is not part of that frame. So a child the census above counts as clean can
|
|
7613
|
+
* still leave trivia rows when it reaches a node whose body can fail after a
|
|
7614
|
+
* trivia scan (`mayLeavePartialCapture`'s `throughNodes`). These are the arms
|
|
7615
|
+
* and sites that need only the two logs restored. A program with no trivia of
|
|
7616
|
+
* its own records rows only under trivia its caller supplies, so its emitted
|
|
7617
|
+
* assembly takes these marks only for such a parse (`RunCfg.inheritedTrivia`).
|
|
7618
|
+
*/
|
|
7619
|
+
choiceLogRollbackMasks = /* @__PURE__ */ new Map();
|
|
7620
|
+
failureLogRollbackSites = /* @__PURE__ */ new Set();
|
|
7621
|
+
/**
|
|
7622
|
+
* HOW EACH CHOICE WAS LOWERED, for the census above. A choice on the ordered
|
|
7623
|
+
* path whose arms cannot commit a failure restores the logs after every arm
|
|
7624
|
+
* it enters (its full mark, or its own two-log mark), so it leaves no rows.
|
|
7625
|
+
* An exclusive dispatch runs its one arm with no mark, and an ordered choice
|
|
7626
|
+
* returns a committed arm's failure before restoring, so either leaves what an
|
|
7627
|
+
* arm leaves. A choice in neither set, or in both, is taken to leave rows. Both
|
|
7628
|
+
* sets are complete only once every rule is encoded, so the trivia-log census
|
|
7629
|
+
* runs then (`logCensus`).
|
|
7630
|
+
*/
|
|
7631
|
+
restoringChoices = /* @__PURE__ */ new Set();
|
|
7632
|
+
leakingChoices = /* @__PURE__ */ new Set();
|
|
7633
|
+
logCensus = [];
|
|
7634
|
+
restoresArms = (choice2) => this.restoringChoices.has(choice2) && !this.leakingChoices.has(choice2);
|
|
7592
7635
|
/**
|
|
7593
7636
|
* `reachesSideWriter`'s answers, shared by every `failureNeedsRollback` call
|
|
7594
7637
|
* for the lifetime of this `Encoder`. Every entry is exact — it depends only on
|
|
@@ -8163,11 +8206,19 @@ var Encoder = class {
|
|
|
8163
8206
|
* not run repeat recovery, but these rows can still publish through a caller's
|
|
8164
8207
|
* context.
|
|
8165
8208
|
*/
|
|
8166
|
-
failureNeedsRollback(p, autoNot) {
|
|
8209
|
+
failureNeedsRollback(p, autoNot, throughNodes) {
|
|
8167
8210
|
const refName = p._ruleName;
|
|
8168
8211
|
const winner = refName === void 0 ? void 0 : this.winners?.[refName];
|
|
8169
8212
|
const root = winner !== void 0 && !winnerWrapsReference2(winner, p) ? winner : p;
|
|
8170
|
-
return mayLeavePartialCapture(root, /* @__PURE__ */ new Set(), true) || this.reachesSideWriter(root) || (autoNot?.length ?? 0) > 0 && capturesLeaf(root);
|
|
8213
|
+
return mayLeavePartialCapture(root, /* @__PURE__ */ new Set(), true, throughNodes) || this.reachesSideWriter(root) || (autoNot?.length ?? 0) > 0 && capturesLeaf(root);
|
|
8214
|
+
}
|
|
8215
|
+
/** The rollback census of an `optional()` or `attempt()` row at `ip` over `child`. */
|
|
8216
|
+
censusTransaction(child, ip) {
|
|
8217
|
+
if (this.failureNeedsRollback(child, void 0, false)) return;
|
|
8218
|
+
this.failureRollbackCleanSites.add(ip);
|
|
8219
|
+
this.logCensus.push(() => {
|
|
8220
|
+
if (this.failureNeedsRollback(child, void 0, this.restoresArms)) this.failureLogRollbackSites.add(ip);
|
|
8221
|
+
});
|
|
8171
8222
|
}
|
|
8172
8223
|
/**
|
|
8173
8224
|
* Whether a field, recovered error, interpreted scanner or unresolvable shape
|
|
@@ -8789,13 +8840,11 @@ var Encoder = class {
|
|
|
8789
8840
|
}
|
|
8790
8841
|
const dispIdx = this.disp.length;
|
|
8791
8842
|
this.disp.push(classes);
|
|
8843
|
+
const exclusive = dispatchIsExclusive(classes, this.cc);
|
|
8792
8844
|
let rollbackMask = kids.length > 31 ? -1 : 0;
|
|
8793
8845
|
if (rollbackMask === 0) {
|
|
8794
8846
|
for (let i = 0; i < arms.length; i++) {
|
|
8795
|
-
|
|
8796
|
-
if (this.failureNeedsRollback(arms[i], d.autoNot[src])) {
|
|
8797
|
-
rollbackMask |= 1 << i;
|
|
8798
|
-
}
|
|
8847
|
+
if (this.failureNeedsRollback(arms[i], d.autoNot[order[i]], false)) rollbackMask |= 1 << i;
|
|
8799
8848
|
}
|
|
8800
8849
|
}
|
|
8801
8850
|
const head = this.emitHead(OP_CHOICE, 3 + 2 * kids.length);
|
|
@@ -8807,9 +8856,19 @@ var Encoder = class {
|
|
|
8807
8856
|
this.code[head + 4 + kids.length + i] = this.expected(deriveExpected(arms[i]));
|
|
8808
8857
|
}
|
|
8809
8858
|
this.choiceRollbackMasks.set(head, rollbackMask);
|
|
8810
|
-
if (
|
|
8811
|
-
|
|
8859
|
+
if (rollbackMask !== -1) {
|
|
8860
|
+
const full = rollbackMask;
|
|
8861
|
+
this.logCensus.push(() => {
|
|
8862
|
+
let logMask = 0;
|
|
8863
|
+
for (let i = 0; i < arms.length; i++) {
|
|
8864
|
+
if ((full & 1 << i) === 0 && this.failureNeedsRollback(arms[i], d.autoNot[order[i]], this.restoresArms)) logMask |= 1 << i;
|
|
8865
|
+
}
|
|
8866
|
+
if (logMask !== 0) this.choiceLogRollbackMasks.set(head, logMask);
|
|
8867
|
+
});
|
|
8812
8868
|
}
|
|
8869
|
+
const nonCommitting = arms.every((arm) => !mayCommitFailure(arm, rr, this.commitFailureMemo));
|
|
8870
|
+
if (nonCommitting) this.nonCommittingChoiceSites.add(head);
|
|
8871
|
+
(!exclusive && nonCommitting ? this.restoringChoices : this.leakingChoices).add(p);
|
|
8813
8872
|
return head;
|
|
8814
8873
|
}
|
|
8815
8874
|
case "many":
|
|
@@ -8845,7 +8904,7 @@ var Encoder = class {
|
|
|
8845
8904
|
}
|
|
8846
8905
|
case "optional": {
|
|
8847
8906
|
const head = this.emit(OP_OPT, this.lookaheadGate(d.parser, this.node(d.parser).ip));
|
|
8848
|
-
|
|
8907
|
+
this.censusTransaction(d.parser, head);
|
|
8849
8908
|
return head;
|
|
8850
8909
|
}
|
|
8851
8910
|
case "transform": {
|
|
@@ -9016,7 +9075,7 @@ var Encoder = class {
|
|
|
9016
9075
|
// lowering was correct only for a choice arm.
|
|
9017
9076
|
case "attempt": {
|
|
9018
9077
|
const inner = this.emit(OP_ATTEMPT, this.node(d.parser).ip, d.contain === true ? 1 : 0);
|
|
9019
|
-
|
|
9078
|
+
this.censusTransaction(d.parser, inner);
|
|
9020
9079
|
const fs3 = this.gateFirstSet(d.parser, d.guarded === true, false);
|
|
9021
9080
|
if (fs3.kind === "any" || matchesEmpty(d.parser, /* @__PURE__ */ new Set(), this.refResolver())) return inner;
|
|
9022
9081
|
const cls = this.charClass(fs3);
|
|
@@ -9180,6 +9239,7 @@ var Encoder = class {
|
|
|
9180
9239
|
finish() {
|
|
9181
9240
|
if (this.code.length === 0) this.emit(OP_EMPTY);
|
|
9182
9241
|
this.collapseIndirection();
|
|
9242
|
+
for (const census of this.logCensus) census();
|
|
9183
9243
|
return ownTableProgram({
|
|
9184
9244
|
code: this.code,
|
|
9185
9245
|
k: this.k,
|
|
@@ -9204,6 +9264,8 @@ var Encoder = class {
|
|
|
9204
9264
|
}, void 0, {
|
|
9205
9265
|
choiceRollbackMasks: this.choiceRollbackMasks,
|
|
9206
9266
|
failureRollbackCleanSites: this.failureRollbackCleanSites,
|
|
9267
|
+
choiceLogRollbackMasks: this.choiceLogRollbackMasks,
|
|
9268
|
+
failureLogRollbackSites: this.failureLogRollbackSites,
|
|
9207
9269
|
nonCommittingChoiceSites: this.nonCommittingChoiceSites
|
|
9208
9270
|
});
|
|
9209
9271
|
}
|
|
@@ -11090,6 +11152,13 @@ if(ctx._errors!==undefined&&ctx._errors.length!==${t}er)ctx._errors.length=${t}e
|
|
|
11090
11152
|
if (!s.fd && !s.er) return `if(${t}n)rollbackTriviaAt(ctx,${t}raw,${t}tl,${t}lv,undefined,undefined,${t}lg,${t}rt)`;
|
|
11091
11153
|
return `if(${t}n){rollbackTriviaAt(ctx,${t}raw,${t}tl,${t}lv,${s.fd ? `${t}fd` : "undefined"},${s.er ? `${t}er` : "undefined"},${t}lg,${t}rt)}`;
|
|
11092
11154
|
}
|
|
11155
|
+
function emitLogMark(t) {
|
|
11156
|
+
return `const ${t}lg=ctx._triviaLog!==undefined?ctx._triviaLog.length:0,${t}rt=ctx._rootTriviaLog!==undefined?ctx._rootTriviaLog.length:0`;
|
|
11157
|
+
}
|
|
11158
|
+
function emitLogRollback(t) {
|
|
11159
|
+
return `{const g=ctx._triviaLog;if(g!==undefined)while(g.length>${t}lg)g.pop()}
|
|
11160
|
+
{const r=ctx._rootTriviaLog;if(r!==undefined)while(r.length>${t}rt)r.pop()}`;
|
|
11161
|
+
}
|
|
11093
11162
|
function emitTerm(callee, dst, t, l, skip, miss) {
|
|
11094
11163
|
const fast = `const ${t}v=${callee}(input,cur,ctx)
|
|
11095
11164
|
if(${t}v===FAIL)return FAIL
|
|
@@ -11173,6 +11242,7 @@ function emitAssemblySource(t, prog, cfg, extraIps = [], staticBuild = false, se
|
|
|
11173
11242
|
const { code, k, fx, disp, dsp, triviaLabelled } = t;
|
|
11174
11243
|
const swapLegal = !cfg.trackLines;
|
|
11175
11244
|
const hostCst = cfg.hostCst;
|
|
11245
|
+
const LOGS = (prog.triviaSpecs?.length ?? 0) > 0 || cfg.inheritedTrivia === true;
|
|
11176
11246
|
const REC2 = prog.rec === 1 && cfg.tolerant;
|
|
11177
11247
|
if (cfg.coverage) throw new Unemittable("a coverage assembly");
|
|
11178
11248
|
const roots = [...Object.values(prog.rules), ...extraIps];
|
|
@@ -11941,12 +12011,13 @@ return v
|
|
|
11941
12011
|
case OP_ATTEMPT: {
|
|
11942
12012
|
const child = link(code[ip + 1]);
|
|
11943
12013
|
const clean = !REC2 && failureRollbackClean(prog, ip);
|
|
12014
|
+
const logs = clean && LOGS && failureLogRollback(prog, ip);
|
|
11944
12015
|
const p = tmp();
|
|
11945
12016
|
return `${head}
|
|
11946
|
-
${clean ? "" : emitMark(p, L.buf, L.raw, sinks)}
|
|
12017
|
+
${clean ? logs ? emitLogMark(p) : "" : emitMark(p, L.buf, L.raw, sinks)}
|
|
11947
12018
|
const v=${child}(input,pos,ctx)
|
|
11948
12019
|
if(v!==FAIL)return v
|
|
11949
|
-
${clean ? "" : emitRollback(p, L.buf, L.raw, sinks)}
|
|
12020
|
+
${clean ? logs ? emitLogRollback(p) : "" : emitRollback(p, L.buf, L.raw, sinks)}
|
|
11950
12021
|
${code[ip + 2] === 1 ? "ctx._fc=false" : "if(ctx._fc===true)return FAIL"}
|
|
11951
12022
|
ctx._fe=pos
|
|
11952
12023
|
return FAIL
|
|
@@ -11972,6 +12043,7 @@ return FAIL
|
|
|
11972
12043
|
${lookaheadMiss(code[ip + 1], "EC.e=pos;return null")}${emitMark(p, L.buf, L.raw, sinks)}
|
|
11973
12044
|
${cfg.probe ? "const pb=ctx._probe?.best\n" : ""}const v=${child}(input,pos,ctx)
|
|
11974
12045
|
${emitRollback(p, L.buf, L.raw, sinks)}
|
|
12046
|
+
ctx._fc=false
|
|
11975
12047
|
${cfg.probe ? "if(ctx._probe!==undefined)ctx._probe.best=pb??null\n" : ""}if(v===FAIL){EC.e=pos;return null}
|
|
11976
12048
|
ctx._fe=pos
|
|
11977
12049
|
ctx._fx=${xf}
|
|
@@ -11996,6 +12068,7 @@ return null
|
|
|
11996
12068
|
${lookaheadMiss(code[ip + 1], `ctx._fe=pos;ctx._fx=${xf};return FAIL`)}${emitMark(p, L.buf, L.raw, sinks)}
|
|
11997
12069
|
${cfg.probe ? "const pb=ctx._probe?.best\n" : ""}const v=${child}(input,pos,ctx)
|
|
11998
12070
|
${emitRollback(p, L.buf, L.raw, sinks)}
|
|
12071
|
+
ctx._fc=false
|
|
11999
12072
|
${cfg.probe ? "if(ctx._probe!==undefined)ctx._probe.best=pb??null\n" : ""}if(v===FAIL){ctx._fe=pos;ctx._fx=${xf};return FAIL}
|
|
12000
12073
|
EC.e=pos
|
|
12001
12074
|
return null
|
|
@@ -12004,14 +12077,15 @@ return null
|
|
|
12004
12077
|
case OP_OPT: {
|
|
12005
12078
|
const child = link(code[ip + 1]);
|
|
12006
12079
|
const clean = !REC2 && failureRollbackClean(prog, ip);
|
|
12080
|
+
const logs = clean && LOGS && failureLogRollback(prog, ip);
|
|
12007
12081
|
const p = tmp();
|
|
12008
12082
|
return `${head}
|
|
12009
|
-
${lookaheadMiss(code[ip + 1], "EC.e=pos;return null")}${clean ? "" : emitMark(p, L.buf, L.raw, sinks)}
|
|
12083
|
+
${lookaheadMiss(code[ip + 1], "EC.e=pos;return null")}${clean ? logs ? emitLogMark(p) : "" : emitMark(p, L.buf, L.raw, sinks)}
|
|
12010
12084
|
ctx._fc=false
|
|
12011
12085
|
const v=${child}(input,pos,ctx)
|
|
12012
12086
|
if(v===FAIL){
|
|
12013
12087
|
if(ctx._fc===true)return FAIL
|
|
12014
|
-
${clean ? "" : emitRollback(p, L.buf, L.raw, sinks)}
|
|
12088
|
+
${clean ? logs ? emitLogRollback(p) : "" : emitRollback(p, L.buf, L.raw, sinks)}
|
|
12015
12089
|
EC.e=pos
|
|
12016
12090
|
return null
|
|
12017
12091
|
}
|
|
@@ -12161,6 +12235,10 @@ return FAIL
|
|
|
12161
12235
|
const encodedRollbackMask = choiceRollbackMask(prog, ip) ?? -1;
|
|
12162
12236
|
const rollbackMask = REC2 ? -1 : encodedRollbackMask;
|
|
12163
12237
|
const hasRollback = rollbackMask !== 0;
|
|
12238
|
+
const logMask = rollbackMask === -1 || !LOGS ? 0 : choiceLogRollbackMask(prog, ip);
|
|
12239
|
+
const choiceMark = hasRollback ? emitMark(p, L.buf, L.raw, sinks) : "";
|
|
12240
|
+
const armMark = (i) => !hasRollback && (logMask & 1 << i) !== 0 ? `${emitLogMark(p)}
|
|
12241
|
+
` : "";
|
|
12164
12242
|
const startFailureExact = arms.every((_arm, i) => {
|
|
12165
12243
|
const terminal = leadingScalarTerminal(code, code[base + i], 0, false);
|
|
12166
12244
|
if (terminal < 0) return false;
|
|
@@ -12172,7 +12250,7 @@ return FAIL
|
|
|
12172
12250
|
if (op2 === OP_LIT) return typeof spec === "string" && spec.length > 0;
|
|
12173
12251
|
return op2 === OP_RX && spec instanceof RegExp && !regexCanMatchEmpty(spec.source);
|
|
12174
12252
|
});
|
|
12175
|
-
const rollbackFor = (i) => rollbackMask === -1 || (rollbackMask & 1 << i) !== 0 ? emitRollback(p, L.buf, L.raw, sinks) : "";
|
|
12253
|
+
const rollbackFor = (i) => rollbackMask === -1 || (rollbackMask & 1 << i) !== 0 ? emitRollback(p, L.buf, L.raw, sinks) : (logMask & 1 << i) === 0 ? "" : hasRollback ? emitRollback(p, L.buf, L.raw, sinks) : emitLogRollback(p);
|
|
12176
12254
|
if (choiceCannotCommit(prog, ip) && !startFailureExact) {
|
|
12177
12255
|
const deepAt = Array.from({ length: n }, () => tmp());
|
|
12178
12256
|
const deepFx = Array.from({ length: n }, () => tmp());
|
|
@@ -12198,7 +12276,7 @@ ${remember2(i, "at", pretest.sequence.expected.map((value, at) => `${decision}==
|
|
|
12198
12276
|
}`;
|
|
12199
12277
|
return `${decision === "" ? "" : `let ${decision}=${pretest?.sequence === void 0 ? -1 : 0}
|
|
12200
12278
|
`}if(${gate2}){
|
|
12201
|
-
ctx._fc=false
|
|
12279
|
+
${armMark(i)}ctx._fc=false
|
|
12202
12280
|
{const v=${arm}(input,pos,ctx)
|
|
12203
12281
|
if(v!==FAIL)return v}
|
|
12204
12282
|
{const at=ctx._fe??pos
|
|
@@ -12217,7 +12295,7 @@ ctx._fe=pos;ctx._fx=acc??${choiceFx}
|
|
|
12217
12295
|
return FAIL`;
|
|
12218
12296
|
return `${head}
|
|
12219
12297
|
const c=${directAsciiMask ? "input.charCodeAt(pos)" : "lead(input,pos)"}
|
|
12220
|
-
${
|
|
12298
|
+
${choiceMark}
|
|
12221
12299
|
${deepAt.map((at, i) => `let ${at},${deepFx[i]}`).join("\n")}
|
|
12222
12300
|
${maskable ? `if(c<128){
|
|
12223
12301
|
const bits=${maskName}[${directAsciiMask ? "c" : "c<0?128:c"}]
|
|
@@ -12264,7 +12342,7 @@ if(at===best${startFailureExact ? "&&at>pos" : ""})acc=_accSet(${pretest.sequenc
|
|
|
12264
12342
|
}`;
|
|
12265
12343
|
return `${decision === "" ? "" : `let ${decision}=${pretest?.sequence === void 0 ? -1 : 0}
|
|
12266
12344
|
`}if((bits&${1 << i})!==0${condition}){
|
|
12267
|
-
ctx._fc=false
|
|
12345
|
+
${armMark(i)}ctx._fc=false
|
|
12268
12346
|
{const v=${arm}(input,pos,ctx)
|
|
12269
12347
|
if(v!==FAIL)return v}
|
|
12270
12348
|
${startFailureExact ? "" : `if(best===pos)acc=${catchName}(${i},prev,acc)
|
|
@@ -12295,7 +12373,7 @@ if(at===best${startFailureExact ? "&&at>pos" : ""})acc=_accSet(${pretest.token.e
|
|
|
12295
12373
|
}${startFailureExact ? "" : `else if(best===pos)acc=_accSet(${expected[i]},acc)`}`;
|
|
12296
12374
|
return `${decision === "" ? "" : `let ${decision}=${pretest?.sequence === void 0 ? -1 : 0}
|
|
12297
12375
|
`}if((${gateRefs[i]}===null||classHas(${gateRefs[i]},c))${condition}){
|
|
12298
|
-
ctx._fc=false
|
|
12376
|
+
${armMark(i)}ctx._fc=false
|
|
12299
12377
|
{const v=${arm}(input,pos,ctx)
|
|
12300
12378
|
if(v!==FAIL)return v}
|
|
12301
12379
|
{const at=ctx._fe??pos
|
|
@@ -12307,7 +12385,7 @@ ${rollbackFor(i)}
|
|
|
12307
12385
|
}).join("\n");
|
|
12308
12386
|
return `${head}
|
|
12309
12387
|
const c=${directAsciiMask ? "input.charCodeAt(pos)" : "lead(input,pos)"}
|
|
12310
|
-
${
|
|
12388
|
+
${choiceMark}
|
|
12311
12389
|
let acc
|
|
12312
12390
|
let best=pos
|
|
12313
12391
|
${maskable ? `if(c<128){
|
|
@@ -13387,7 +13465,7 @@ function clearOf(ranges, input, from, to) {
|
|
|
13387
13465
|
}
|
|
13388
13466
|
|
|
13389
13467
|
// src/version.ts
|
|
13390
|
-
var PARSEMAN_VERSION = "0.60.
|
|
13468
|
+
var PARSEMAN_VERSION = "0.60.3";
|
|
13391
13469
|
|
|
13392
13470
|
// src/table/assemble.ts
|
|
13393
13471
|
import { PlainBuf as PlainBuf2, PlainField, PlainLeaf as PlainLeaf9, PlainNode as PlainNode2, PlainSpan as PlainSpan10 } from "../cst/plain.js";
|
|
@@ -13659,11 +13737,11 @@ function linkMatcher(m) {
|
|
|
13659
13737
|
}
|
|
13660
13738
|
var NO_COVERAGE = (_id) => {
|
|
13661
13739
|
};
|
|
13662
|
-
function cfgKeyOf(hostCst, trackLines, tolerant, coverage, probe, hostReadsChildren = true) {
|
|
13663
|
-
return (hostCst ? 1 : 0) | (trackLines ? 2 : 0) | (tolerant ? 4 : 0) | (coverage ? 8 : 0) | (probe ? 16 : 0) | (hostReadsChildren ? 0 : 32);
|
|
13740
|
+
function cfgKeyOf(hostCst, trackLines, tolerant, coverage, probe, hostReadsChildren = true, inheritedTrivia = false) {
|
|
13741
|
+
return (hostCst ? 1 : 0) | (trackLines ? 2 : 0) | (tolerant ? 4 : 0) | (coverage ? 8 : 0) | (probe ? 16 : 0) | (hostReadsChildren ? 0 : 32) | (inheritedTrivia ? 64 : 0);
|
|
13664
13742
|
}
|
|
13665
13743
|
function cfgKey(c) {
|
|
13666
|
-
return cfgKeyOf(c.hostCst, c.trackLines, c.tolerant, c.coverage, c.probe, c.hostReadsChildren);
|
|
13744
|
+
return cfgKeyOf(c.hostCst, c.trackLines, c.tolerant, c.coverage, c.probe, c.hostReadsChildren, c.inheritedTrivia);
|
|
13667
13745
|
}
|
|
13668
13746
|
function assertFactoryArity(pre) {
|
|
13669
13747
|
if (pre.arity === EMITTED_PARAMS.length) return;
|
|
@@ -15038,6 +15116,7 @@ function assemble(t, prog, cfg) {
|
|
|
15038
15116
|
const probeBest = PROBE ? ctx._probe?.best : void 0;
|
|
15039
15117
|
const v = child(input, pos, ctx);
|
|
15040
15118
|
if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
|
|
15119
|
+
ctx._fc = false;
|
|
15041
15120
|
if (PROBE && ctx._probe !== void 0) ctx._probe.best = probeBest ?? null;
|
|
15042
15121
|
if (v === FAIL) {
|
|
15043
15122
|
EC.e = pos;
|
|
@@ -15083,6 +15162,7 @@ function assemble(t, prog, cfg) {
|
|
|
15083
15162
|
const probeBest = PROBE ? ctx._probe?.best : void 0;
|
|
15084
15163
|
const v = child(input, pos, ctx);
|
|
15085
15164
|
if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
|
|
15165
|
+
ctx._fc = false;
|
|
15086
15166
|
if (PROBE && ctx._probe !== void 0) ctx._probe.best = probeBest ?? null;
|
|
15087
15167
|
if (v === FAIL) {
|
|
15088
15168
|
ctx._fe = pos;
|
|
@@ -16941,7 +17021,7 @@ function assemble(t, prog, cfg) {
|
|
|
16941
17021
|
if (emitted !== void 0) throw new ServedByBuild();
|
|
16942
17022
|
if (prog.asm !== void 0) {
|
|
16943
17023
|
throw new Unemittable(
|
|
16944
|
-
`option set ${cfgKey(cfg)} (hostCst=${cfg.hostCst} trackLines=${cfg.trackLines} tolerant=${cfg.tolerant} coverage=${cfg.coverage} probe=${cfg.probe}), which this build did not pre-compile. The Function constructor is NOT used for an artifact that carries assemblies \u2014 see \`EmitOptions.assemblies\` to add this option set to the build`
|
|
17024
|
+
`option set ${cfgKey(cfg)} (hostCst=${cfg.hostCst} trackLines=${cfg.trackLines} tolerant=${cfg.tolerant} coverage=${cfg.coverage} probe=${cfg.probe} inheritedTrivia=${cfg.inheritedTrivia === true}), which this build did not pre-compile. The Function constructor is NOT used for an artifact that carries assemblies \u2014 see \`EmitOptions.assemblies\` to add this option set to the build`
|
|
16945
17025
|
);
|
|
16946
17026
|
}
|
|
16947
17027
|
if (!EMIT_ENABLED) throw new Unemittable("PM_TABLE_EMIT=0 (measurement toggle)");
|
|
@@ -17151,7 +17231,9 @@ function countSiteVisits(prog, parse2, fns = prog.fns) {
|
|
|
17151
17231
|
var AssemblyCache = class {
|
|
17152
17232
|
t;
|
|
17153
17233
|
prog;
|
|
17154
|
-
byCfg = Array.from({ length:
|
|
17234
|
+
byCfg = Array.from({ length: 128 });
|
|
17235
|
+
/** Whether this program installs no trivia of its own (`RunCfg.inheritedTrivia`). */
|
|
17236
|
+
noOwnTrivia;
|
|
17155
17237
|
/**
|
|
17156
17238
|
* Monomorphic predicate inline cache. An assembly depends on the predicate
|
|
17157
17239
|
* FUNCTION and the scalar cfg key, not on the host object that carries it, so
|
|
@@ -17164,6 +17246,7 @@ var AssemblyCache = class {
|
|
|
17164
17246
|
constructor(prog, resolved = resolveTable(prog)) {
|
|
17165
17247
|
this.prog = prog;
|
|
17166
17248
|
this.t = resolved;
|
|
17249
|
+
this.noOwnTrivia = prog.triviaSpecs === void 0 || prog.triviaSpecs.length === 0;
|
|
17167
17250
|
}
|
|
17168
17251
|
for(cfg) {
|
|
17169
17252
|
const key = cfgKey(cfg);
|
|
@@ -17227,13 +17310,14 @@ var AssemblyCache = class {
|
|
|
17227
17310
|
const tolerant = ctx._tolerant === true;
|
|
17228
17311
|
const coverage = ctx._grammarCoverage !== void 0;
|
|
17229
17312
|
const probe = ctx._probe !== void 0;
|
|
17230
|
-
const
|
|
17313
|
+
const inheritedTrivia = this.noOwnTrivia && ctx.trivia !== void 0;
|
|
17314
|
+
const key = cfgKeyOf(hostCst, trackLines, tolerant, coverage, probe, hostReadsChildren, inheritedTrivia);
|
|
17231
17315
|
let cache = this.byCfg;
|
|
17232
17316
|
if (hostCaptureTrivia !== void 0) {
|
|
17233
17317
|
if (this.hostPredicate === hostCaptureTrivia) {
|
|
17234
17318
|
cache = this.hostAssemblies;
|
|
17235
17319
|
} else {
|
|
17236
|
-
cache = Array.from({ length:
|
|
17320
|
+
cache = Array.from({ length: 128 });
|
|
17237
17321
|
this.hostPredicate = hostCaptureTrivia;
|
|
17238
17322
|
this.hostAssemblies = cache;
|
|
17239
17323
|
}
|
|
@@ -17247,7 +17331,8 @@ var AssemblyCache = class {
|
|
|
17247
17331
|
trackLines,
|
|
17248
17332
|
tolerant,
|
|
17249
17333
|
coverage,
|
|
17250
|
-
probe
|
|
17334
|
+
probe,
|
|
17335
|
+
inheritedTrivia
|
|
17251
17336
|
});
|
|
17252
17337
|
cache[key] = made;
|
|
17253
17338
|
return made;
|