parseman 0.60.1 → 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.d.ts +18 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +240 -87
- 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/plugin/index.ts +189 -63
- 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;
|
|
@@ -22741,26 +22826,36 @@ function evalIR(ir, rulesImpl) {
|
|
|
22741
22826
|
import { createHash } from "node:crypto";
|
|
22742
22827
|
var TABLE_RUNTIME_SPECIFIER = "parseman/table";
|
|
22743
22828
|
var CARRIED_SIDECAR_SUFFIX = ".parseman.json";
|
|
22829
|
+
function artifactDigest(code) {
|
|
22830
|
+
const body = code.replace(/\n?\/\/# sourceMappingURL=[^\n]*\n?$/, "");
|
|
22831
|
+
return createHash("sha256").update(body).digest("hex").slice(0, 32);
|
|
22832
|
+
}
|
|
22744
22833
|
var _sidecarCache = /* @__PURE__ */ new Map();
|
|
22745
22834
|
function readCarriedSidecar(artifact) {
|
|
22746
22835
|
const file = artifact + CARRIED_SIDECAR_SUFFIX;
|
|
22747
22836
|
let mtimeMs;
|
|
22837
|
+
let artifactMtimeMs;
|
|
22748
22838
|
try {
|
|
22749
22839
|
mtimeMs = fs2.statSync(file).mtimeMs;
|
|
22840
|
+
artifactMtimeMs = fs2.statSync(artifact).mtimeMs;
|
|
22750
22841
|
} catch {
|
|
22751
22842
|
return null;
|
|
22752
22843
|
}
|
|
22753
22844
|
const hit = _sidecarCache.get(file);
|
|
22754
|
-
if (hit && hit.mtimeMs === mtimeMs) return hit.
|
|
22755
|
-
let
|
|
22845
|
+
if (hit && hit.mtimeMs === mtimeMs && hit.artifactMtimeMs === artifactMtimeMs) return hit.read;
|
|
22846
|
+
let read = null;
|
|
22756
22847
|
try {
|
|
22757
22848
|
const parsed = JSON.parse(fs2.readFileSync(file, "utf8"));
|
|
22758
22849
|
const exports = typeof parsed === "object" && parsed !== null ? parsed.exports : void 0;
|
|
22759
|
-
if (typeof exports === "object" && exports !== null)
|
|
22850
|
+
if (typeof exports === "object" && exports !== null) {
|
|
22851
|
+
const sidecar = parsed;
|
|
22852
|
+
const stale = typeof sidecar.artifact === "string" && sidecar.artifact !== artifactDigest(fs2.readFileSync(artifact, "utf8"));
|
|
22853
|
+
read = { sidecar, stale };
|
|
22854
|
+
}
|
|
22760
22855
|
} catch {
|
|
22761
22856
|
}
|
|
22762
|
-
_sidecarCache.set(file, { mtimeMs,
|
|
22763
|
-
return
|
|
22857
|
+
_sidecarCache.set(file, { mtimeMs, artifactMtimeMs, read });
|
|
22858
|
+
return read;
|
|
22764
22859
|
}
|
|
22765
22860
|
var corpusCache = /* @__PURE__ */ new Map();
|
|
22766
22861
|
function corpusTexts(profile) {
|
|
@@ -22880,58 +22975,95 @@ function parseModuleCached(filePath) {
|
|
|
22880
22975
|
_moduleParseCache.set(filePath, { mtimeMs, parsed });
|
|
22881
22976
|
return parsed;
|
|
22882
22977
|
}
|
|
22883
|
-
function
|
|
22978
|
+
function exportOrigin(body, exported) {
|
|
22979
|
+
const stars = [];
|
|
22884
22980
|
for (const st of body) {
|
|
22981
|
+
if (st.type === "ExportAllDeclaration") {
|
|
22982
|
+
const from = st.source?.value;
|
|
22983
|
+
if (st.exported == null && from !== void 0) stars.push(from);
|
|
22984
|
+
continue;
|
|
22985
|
+
}
|
|
22885
22986
|
if (st.type !== "ExportNamedDeclaration") continue;
|
|
22987
|
+
const decl = st.declaration;
|
|
22988
|
+
if (decl != null) {
|
|
22989
|
+
const ids = decl.type === "VariableDeclaration" ? (decl.declarations ?? []).map((d) => d.id?.name) : [decl.id?.name];
|
|
22990
|
+
if (ids.includes(exported)) return "local";
|
|
22991
|
+
}
|
|
22886
22992
|
for (const sp of st.specifiers ?? []) {
|
|
22887
22993
|
const exp = sp.exported;
|
|
22888
22994
|
if ((exp?.name ?? exp?.value) !== exported) continue;
|
|
22889
22995
|
const local = sp.local;
|
|
22890
22996
|
const name = local?.name ?? local?.value;
|
|
22891
|
-
if (name === void 0) return
|
|
22997
|
+
if (name === void 0) return "local";
|
|
22892
22998
|
const from = st.source?.value;
|
|
22893
|
-
|
|
22894
|
-
|
|
22895
|
-
|
|
22896
|
-
|
|
22897
|
-
}
|
|
22898
|
-
|
|
22899
|
-
|
|
22900
|
-
|
|
22901
|
-
|
|
22902
|
-
|
|
22903
|
-
|
|
22904
|
-
|
|
22905
|
-
|
|
22906
|
-
|
|
22907
|
-
|
|
22908
|
-
|
|
22999
|
+
if (from !== void 0) return { from, imported: name };
|
|
23000
|
+
const imported = extractImportBindings(body).get(name);
|
|
23001
|
+
return imported === void 0 ? "local" : { from: imported.source, imported: imported.imported };
|
|
23002
|
+
}
|
|
23003
|
+
}
|
|
23004
|
+
return { stars };
|
|
23005
|
+
}
|
|
23006
|
+
async function followCarried(sinks, moduleId, name, depth = 0) {
|
|
23007
|
+
if (depth > 64) return void 0;
|
|
23008
|
+
const own = sinks.get(moduleId)?.get(name);
|
|
23009
|
+
if (own !== void 0) return { items: own, recorder: moduleId };
|
|
23010
|
+
const code = this.getModuleInfo(moduleId)?.code;
|
|
23011
|
+
if (!code) return void 0;
|
|
23012
|
+
const parsed = parseSync5(moduleId, code);
|
|
23013
|
+
if (parsed.errors.length > 0) return void 0;
|
|
23014
|
+
const origin = exportOrigin(parsed.program.body, name);
|
|
23015
|
+
if (origin === "local") return null;
|
|
23016
|
+
const follow = async (source, imported) => {
|
|
23017
|
+
const resolved = await this.resolve(source, moduleId);
|
|
22909
23018
|
if (resolved === null || resolved.external) return void 0;
|
|
22910
|
-
|
|
22911
|
-
|
|
23019
|
+
return followCarried.call(this, sinks, resolved.id, imported, depth + 1);
|
|
23020
|
+
};
|
|
23021
|
+
if ("from" in origin) return follow(origin.from, origin.imported);
|
|
23022
|
+
let found;
|
|
23023
|
+
let unknown = false;
|
|
23024
|
+
for (const source of origin.stars) {
|
|
23025
|
+
const got = await follow(source, name);
|
|
23026
|
+
if (got === void 0) unknown = true;
|
|
23027
|
+
else if (got !== null) {
|
|
23028
|
+
if (found !== void 0 && found.items !== got.items) return null;
|
|
23029
|
+
found = got;
|
|
23030
|
+
}
|
|
22912
23031
|
}
|
|
22913
|
-
return void 0;
|
|
23032
|
+
return found ?? (unknown || origin.stars.length === 0 ? void 0 : null);
|
|
22914
23033
|
}
|
|
22915
23034
|
async function emitCarriedSidecars(sinks, bundle) {
|
|
22916
|
-
const
|
|
22917
|
-
|
|
23035
|
+
const write = async (rec) => {
|
|
23036
|
+
const out = [];
|
|
23037
|
+
for (const item of rec.items) {
|
|
23038
|
+
if ("ir" in item) {
|
|
23039
|
+
out.push(item);
|
|
23040
|
+
continue;
|
|
23041
|
+
}
|
|
23042
|
+
const resolved = item.expanded === void 0 ? null : await this.resolve(item.from, rec.recorder);
|
|
23043
|
+
if (resolved !== null && !resolved.external) out.push(...item.expanded);
|
|
23044
|
+
else out.push({ from: item.from, name: item.name });
|
|
23045
|
+
}
|
|
23046
|
+
return out;
|
|
23047
|
+
};
|
|
22918
23048
|
for (const chunk of Object.values(bundle)) {
|
|
22919
23049
|
if (chunk.type !== "chunk") continue;
|
|
22920
23050
|
const exports = {};
|
|
22921
23051
|
for (const name of chunk.exports ?? []) {
|
|
22922
23052
|
const followed = chunk.facadeModuleId ? await followCarried.call(this, sinks, chunk.facadeModuleId, name) : void 0;
|
|
23053
|
+
if (followed === null) continue;
|
|
22923
23054
|
if (followed !== void 0) {
|
|
22924
|
-
exports[name] = followed;
|
|
23055
|
+
exports[name] = await write(followed);
|
|
22925
23056
|
continue;
|
|
22926
23057
|
}
|
|
22927
|
-
const
|
|
22928
|
-
if (
|
|
22929
|
-
const own = ids.filter((m) => chunk.moduleIds?.includes(m));
|
|
22930
|
-
const moduleId = own.length === 1 ? own[0] : own.length === 0 && ids.length === 1 ? ids[0] : void 0;
|
|
22931
|
-
if (moduleId !== void 0) exports[name] = sinks.get(moduleId).get(name);
|
|
23058
|
+
const own = (chunk.moduleIds ?? []).filter((m) => sinks.get(m)?.has(name) === true);
|
|
23059
|
+
if (own.length === 1) exports[name] = await write({ items: sinks.get(own[0]).get(name), recorder: own[0] });
|
|
22932
23060
|
}
|
|
22933
23061
|
if (Object.keys(exports).length === 0) continue;
|
|
22934
|
-
const sidecar = {
|
|
23062
|
+
const sidecar = {
|
|
23063
|
+
parseman: PARSEMAN_VERSION,
|
|
23064
|
+
...chunk.code === void 0 ? {} : { artifact: artifactDigest(chunk.code) },
|
|
23065
|
+
exports
|
|
23066
|
+
};
|
|
22935
23067
|
this.emitFile({ type: "asset", fileName: chunk.fileName + CARRIED_SIDECAR_SUFFIX, source: JSON.stringify(sidecar) });
|
|
22936
23068
|
}
|
|
22937
23069
|
}
|
|
@@ -22939,8 +23071,11 @@ var SIDECAR_FRAMEWORKS = /* @__PURE__ */ new Set(["rollup", "rolldown", "vite"])
|
|
|
22939
23071
|
var plugin_default = createUnplugin((opts = {}, meta) => {
|
|
22940
23072
|
const sinks = SIDECAR_FRAMEWORKS.has(meta.framework) ? /* @__PURE__ */ new Map() : void 0;
|
|
22941
23073
|
const generateBundle = sinks === void 0 ? void 0 : {
|
|
22942
|
-
generateBundle
|
|
22943
|
-
|
|
23074
|
+
generateBundle: {
|
|
23075
|
+
order: "post",
|
|
23076
|
+
handler(_options, bundle) {
|
|
23077
|
+
return emitCarriedSidecars.call(this, sinks, bundle);
|
|
23078
|
+
}
|
|
22944
23079
|
}
|
|
22945
23080
|
};
|
|
22946
23081
|
return {
|
|
@@ -22954,16 +23089,14 @@ var plugin_default = createUnplugin((opts = {}, meta) => {
|
|
|
22954
23089
|
return /\.[jt]sx?$/.test(id) && !id.includes("node_modules");
|
|
22955
23090
|
},
|
|
22956
23091
|
transform(code, id) {
|
|
23092
|
+
sinks?.delete(id);
|
|
22957
23093
|
if (!code.includes("parseman")) return null;
|
|
22958
23094
|
if (!code.includes("macro")) return null;
|
|
22959
23095
|
for (const file of opts.assemblyProfile?.files ?? []) this?.addWatchFile?.(file);
|
|
22960
23096
|
const moduleAliases = /* @__PURE__ */ new Set([PARSEMAN_MODULE, ...opts.moduleAliases ?? []]);
|
|
22961
23097
|
const sink = sinks && /* @__PURE__ */ new Map();
|
|
22962
23098
|
const result = transformMacro(code, id, moduleAliases, opts.warnUnloweredRegex === true, opts.recovery === true, opts.grammarCoverage === true, opts.assemblyProfile, opts.assemblyBudget, sink);
|
|
22963
|
-
if (sinks && sink)
|
|
22964
|
-
if (sink.size > 0) sinks.set(id, sink);
|
|
22965
|
-
else sinks.delete(id);
|
|
22966
|
-
}
|
|
23099
|
+
if (sinks && sink && sink.size > 0) sinks.set(id, sink);
|
|
22967
23100
|
if (result?.warnings.length) {
|
|
22968
23101
|
for (const w of result.warnings) {
|
|
22969
23102
|
if (typeof this?.warn === "function") this.warn(`[parseman] ${w}`);
|
|
@@ -23737,7 +23870,12 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
23737
23870
|
unresolved.why ??= `${exportName} in ${file}: ${why}`;
|
|
23738
23871
|
return null;
|
|
23739
23872
|
};
|
|
23740
|
-
const
|
|
23873
|
+
const sidecarRead = module.source || local ? null : readCarriedSidecar(file);
|
|
23874
|
+
if (sidecarRead?.stale === true) {
|
|
23875
|
+
return fail(`${path2.basename(file)}${CARRIED_SIDECAR_SUFFIX} was written for a different build of ${path2.basename(file)} (the artifact digest it records does not match). Rebuild the package so the two are written together`);
|
|
23876
|
+
}
|
|
23877
|
+
const sidecarExports = sidecarRead?.sidecar.exports;
|
|
23878
|
+
const sidecarItems = sidecarExports !== void 0 && Object.hasOwn(sidecarExports, exportName) ? sidecarExports[exportName] : void 0;
|
|
23741
23879
|
if (sidecarItems !== void 0) {
|
|
23742
23880
|
const list = [];
|
|
23743
23881
|
for (const item of sidecarItems) {
|
|
@@ -23760,7 +23898,20 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
23760
23898
|
const initNode = localFor ? topLevelInit(mod.body, localFor) : null;
|
|
23761
23899
|
const literalRange = initNode ? findCarriedPiecesLiteral(initNode) : null;
|
|
23762
23900
|
if (!literalRange) {
|
|
23763
|
-
|
|
23901
|
+
if (initNode !== null && !module.source && mod.src.slice(initNode.start, initNode.end).includes("tableRules(")) {
|
|
23902
|
+
return fail(`is a compiled grammar with no carried pieces \u2014 no inline literal, and no entry in ${path2.basename(file)}${CARRIED_SIDECAR_SUFFIX}. Rebuild it with this parseman, and keep that file beside the artifact`);
|
|
23903
|
+
}
|
|
23904
|
+
if (module.source || local) return null;
|
|
23905
|
+
const origin = exportOrigin(mod.body, exportName);
|
|
23906
|
+
const targets = origin === "local" ? [] : "from" in origin ? [{ source: origin.from, imported: origin.imported }] : origin.stars.map((source) => ({ source, imported: exportName }));
|
|
23907
|
+
for (const target of targets) {
|
|
23908
|
+
const sub = resolveGrammarModule(file, target.source);
|
|
23909
|
+
if (sub === null || seen.has(sub.file)) continue;
|
|
23910
|
+
const pieces = resolveModulePieces(sub, target.imported, new Set(seen).add(sub.file), unresolved);
|
|
23911
|
+
if (pieces !== null) return pieces;
|
|
23912
|
+
}
|
|
23913
|
+
if (unresolved.why === void 0 && !mod.src.includes(TABLE_RUNTIME_SPECIFIER)) return null;
|
|
23914
|
+
return fail(`is exported by a compiled grammar artifact, but no carried pieces could be found for it \u2014 no inline literal, no entry in ${path2.basename(file)}${CARRIED_SIDECAR_SUFFIX}, and no re-export of it that has either. Rebuild it with this parseman, and keep each chunk's .parseman.json beside it`);
|
|
23764
23915
|
}
|
|
23765
23916
|
const literal2 = mod.src.slice(literalRange.start, literalRange.end);
|
|
23766
23917
|
const imports = extractImportBindings(mod.body);
|
|
@@ -23822,7 +23973,8 @@ ${names.map((n) => ` - ${n}`).join("\n")}` : " (it is not a static combinator/v
|
|
|
23822
23973
|
const b = importBindings.get(it.__spreadLocal);
|
|
23823
23974
|
if (b === void 0) return false;
|
|
23824
23975
|
if (!b.source.startsWith(".") && !path2.isAbsolute(b.source)) {
|
|
23825
|
-
|
|
23976
|
+
const expanded = importedPieces(it.__spreadLocal);
|
|
23977
|
+
out.push({ from: b.source, name: b.imported, ...expanded === null ? {} : { expanded } });
|
|
23826
23978
|
continue;
|
|
23827
23979
|
}
|
|
23828
23980
|
const pieces = importedPieces(it.__spreadLocal);
|
|
@@ -24567,6 +24719,7 @@ ${lines2.join("\n")}`);
|
|
|
24567
24719
|
}
|
|
24568
24720
|
export {
|
|
24569
24721
|
CARRIED_SIDECAR_SUFFIX,
|
|
24722
|
+
artifactDigest,
|
|
24570
24723
|
plugin_default as default,
|
|
24571
24724
|
transformMacro
|
|
24572
24725
|
};
|