parseman 0.51.0 → 0.51.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/diagnostics.js +48 -15
- package/dist/analysis/diagnostics.js.map +1 -1
- package/dist/cli/index.js +50 -17
- package/dist/cli/index.js.map +1 -1
- package/dist/combinators/token.d.ts +8 -8
- package/dist/combinators/token.d.ts.map +1 -1
- package/dist/coverage.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +59 -21
- package/dist/index.js.map +1 -1
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.js +59 -22
- package/dist/plugin/index.js.map +1 -1
- package/dist/spec/index.js +27 -5
- package/dist/spec/index.js.map +1 -1
- package/dist/table/assemble.d.ts.map +1 -1
- package/dist/table/emit-assembly.d.ts.map +1 -1
- package/dist/table/encode-baseline.d.ts.map +1 -1
- package/dist/table/exec-baseline.d.ts.map +1 -1
- package/dist/table/exec.d.ts.map +1 -1
- package/dist/table/index.js +373 -362
- package/dist/table/index.js.map +2 -2
- package/dist/table/ops.d.ts +2 -0
- package/dist/table/ops.d.ts.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/analysis/duplication.ts +1 -1
- package/src/analysis/rebuild.ts +2 -2
- package/src/combinators/token.ts +46 -3
- package/src/compiler/ir-serialize.ts +11 -7
- package/src/coverage.ts +2 -3
- package/src/index.ts +1 -1
- package/src/plugin/evaluator.ts +7 -4
- package/src/table/assemble.ts +8 -3
- package/src/table/child-slots.ts +2 -2
- package/src/table/emit-assembly.ts +5 -3
- package/src/table/encode-baseline.ts +3 -2
- package/src/table/encode.ts +3 -3
- package/src/table/exec-baseline.ts +30 -4
- package/src/table/exec.ts +8 -3
- package/src/table/ops.ts +3 -1
- package/src/table/scalar-terminal.ts +5 -5
- package/src/table/site-labels.ts +2 -2
- package/src/types.ts +1 -1
- package/src/version.ts +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -5478,6 +5478,12 @@ function field(name, combinator) {
|
|
|
5478
5478
|
}
|
|
5479
5479
|
|
|
5480
5480
|
// src/combinators/token.ts
|
|
5481
|
+
function semanticLeafValue(_ctx, _input, _start, _end, value) {
|
|
5482
|
+
return value;
|
|
5483
|
+
}
|
|
5484
|
+
function sourceLeafValue(ctx, input, start, end, value) {
|
|
5485
|
+
return cstOutputHost(ctx.build) ? input.slice(start, end) : value;
|
|
5486
|
+
}
|
|
5481
5487
|
function token(root) {
|
|
5482
5488
|
const meta = {
|
|
5483
5489
|
firstSet: root._meta.firstSet,
|
|
@@ -5530,7 +5536,8 @@ function token(root) {
|
|
|
5530
5536
|
}
|
|
5531
5537
|
};
|
|
5532
5538
|
}
|
|
5533
|
-
function
|
|
5539
|
+
function makeLeaf(root, fn, sourceCstValue) {
|
|
5540
|
+
const cstValue = sourceCstValue ? sourceLeafValue : semanticLeafValue;
|
|
5534
5541
|
const meta = {
|
|
5535
5542
|
firstSet: root._meta.firstSet,
|
|
5536
5543
|
canMatchNewline: root._meta.canMatchNewline,
|
|
@@ -5539,7 +5546,12 @@ function leaf(root, fn) {
|
|
|
5539
5546
|
return {
|
|
5540
5547
|
_tag: "leaf",
|
|
5541
5548
|
_meta: meta,
|
|
5542
|
-
_def: {
|
|
5549
|
+
_def: {
|
|
5550
|
+
tag: "leaf",
|
|
5551
|
+
parser: root,
|
|
5552
|
+
fn,
|
|
5553
|
+
...sourceCstValue ? { cstValue: "source" } : {}
|
|
5554
|
+
},
|
|
5543
5555
|
parse(input, pos, ctx) {
|
|
5544
5556
|
const savedBuf = ctx._cstBuf;
|
|
5545
5557
|
const savedChildren = ctx._cstChildren;
|
|
@@ -5567,11 +5579,21 @@ function leaf(root, fn) {
|
|
|
5567
5579
|
}
|
|
5568
5580
|
if (!result.ok) return result;
|
|
5569
5581
|
const value = fn(result.value, result.span);
|
|
5570
|
-
if (wasCapturing) pushCstLeaf(ctx, {
|
|
5582
|
+
if (wasCapturing) pushCstLeaf(ctx, {
|
|
5583
|
+
_tag: "leaf",
|
|
5584
|
+
value: cstValue(ctx, input, pos, result.span.end, value),
|
|
5585
|
+
span: result.span
|
|
5586
|
+
});
|
|
5571
5587
|
return { ok: true, value, span: result.span };
|
|
5572
5588
|
}
|
|
5573
5589
|
};
|
|
5574
5590
|
}
|
|
5591
|
+
function leaf(root, fn) {
|
|
5592
|
+
return makeLeaf(root, fn, false);
|
|
5593
|
+
}
|
|
5594
|
+
function sourceLeaf(root, fn) {
|
|
5595
|
+
return makeLeaf(root, fn, true);
|
|
5596
|
+
}
|
|
5575
5597
|
|
|
5576
5598
|
// src/combinators/scanTo.ts
|
|
5577
5599
|
function resolveScanSkip(explicitSkip, raw, ctx) {
|
|
@@ -5856,7 +5878,7 @@ function evalRuleMapIR(ir) {
|
|
|
5856
5878
|
if (recognitionOnly) t2._def.recognitionOnly = true;
|
|
5857
5879
|
return t2;
|
|
5858
5880
|
};
|
|
5859
|
-
const _lf = (child, src) => {
|
|
5881
|
+
const _lf = (child, src, source = false) => {
|
|
5860
5882
|
let fn2;
|
|
5861
5883
|
try {
|
|
5862
5884
|
fn2 = (0, eval)(`(${src})`);
|
|
@@ -5865,7 +5887,7 @@ function evalRuleMapIR(ir) {
|
|
|
5865
5887
|
throw new Error("IR leaf fn not materialized");
|
|
5866
5888
|
};
|
|
5867
5889
|
}
|
|
5868
|
-
const l = leaf(child, fn2);
|
|
5890
|
+
const l = source ? sourceLeaf(child, fn2) : leaf(child, fn2);
|
|
5869
5891
|
l._def.fnSrc = src;
|
|
5870
5892
|
return l;
|
|
5871
5893
|
};
|
|
@@ -6349,6 +6371,7 @@ var OP_COV = 40;
|
|
|
6349
6371
|
var OP_SCOPE_PLAIN = 41;
|
|
6350
6372
|
var OP_LEX_BODY = 42;
|
|
6351
6373
|
var OP_LEX_PROGRAM = 43;
|
|
6374
|
+
var OP_SOURCE_LEAF = 44;
|
|
6352
6375
|
var OP_DISPATCH = 25;
|
|
6353
6376
|
var OP_ROUTED = 26;
|
|
6354
6377
|
var OP_NAMES = {
|
|
@@ -6367,6 +6390,7 @@ var OP_NAMES = {
|
|
|
6367
6390
|
[OP_NOT]: "NOT",
|
|
6368
6391
|
[OP_PEEK]: "PEEK",
|
|
6369
6392
|
[OP_LEAF]: "LEAF",
|
|
6393
|
+
[OP_SOURCE_LEAF]: "SOURCE_LEAF",
|
|
6370
6394
|
[OP_EMPTY]: "EMPTY",
|
|
6371
6395
|
[OP_LIT_TRACK]: "LIT_TRACK",
|
|
6372
6396
|
[OP_RX_TRACK]: "RX_TRACK",
|
|
@@ -8319,7 +8343,7 @@ var Encoder = class {
|
|
|
8319
8343
|
}
|
|
8320
8344
|
case "leaf": {
|
|
8321
8345
|
const child = this.node(d.parser).ip;
|
|
8322
|
-
return this.emit(OP_LEAF, this.fn(d.fn, d.fnSrc ?? null), child);
|
|
8346
|
+
return this.emit(d.cstValue === "source" ? OP_SOURCE_LEAF : OP_LEAF, this.fn(d.fn, d.fnSrc ?? null), child);
|
|
8323
8347
|
}
|
|
8324
8348
|
case "node": {
|
|
8325
8349
|
if (d.type === void 0) missingInferredType();
|
|
@@ -8544,6 +8568,7 @@ var Encoder = class {
|
|
|
8544
8568
|
case OP_WITHCTX:
|
|
8545
8569
|
case OP_XFORM:
|
|
8546
8570
|
case OP_LEAF:
|
|
8571
|
+
case OP_SOURCE_LEAF:
|
|
8547
8572
|
case OP_NODE:
|
|
8548
8573
|
case OP_NODE_TRACK:
|
|
8549
8574
|
return [ip + 2];
|
|
@@ -9753,6 +9778,7 @@ function childSlots(code, ip, out) {
|
|
|
9753
9778
|
case OP_NODE_TRACK:
|
|
9754
9779
|
case OP_FIELD:
|
|
9755
9780
|
case OP_LEAF:
|
|
9781
|
+
case OP_SOURCE_LEAF:
|
|
9756
9782
|
case OP_ARMGATE:
|
|
9757
9783
|
out.push(code[ip + 2]);
|
|
9758
9784
|
return true;
|
|
@@ -9861,7 +9887,7 @@ function transfer(code, ip, at, hostCst) {
|
|
|
9861
9887
|
if (at.tri === TRI_NONE && !at.buf) return at;
|
|
9862
9888
|
return { tri: TRI_NONE, buf: false, raw: RAW_UNKNOWN, cap: at.cap };
|
|
9863
9889
|
}
|
|
9864
|
-
if (op === OP_LEAF) {
|
|
9890
|
+
if (op === OP_LEAF || op === OP_SOURCE_LEAF) {
|
|
9865
9891
|
if (!at.buf) return at;
|
|
9866
9892
|
return { tri: at.tri, buf: false, raw: RAW_UNKNOWN, cap: at.cap };
|
|
9867
9893
|
}
|
|
@@ -9948,7 +9974,7 @@ function leadingScalarTerminal(code, ip, minDepth = 2, throughAttempt = true, th
|
|
|
9948
9974
|
depth++;
|
|
9949
9975
|
continue;
|
|
9950
9976
|
}
|
|
9951
|
-
if (op === OP_GATE || op === OP_SCOPE || op === OP_SCOPE_CAP || op === OP_SCOPE_PLAIN || op === OP_XFORM || op === OP_NODE || op === OP_FIELD || op === OP_LEAF) {
|
|
9977
|
+
if (op === OP_GATE || op === OP_SCOPE || op === OP_SCOPE_CAP || op === OP_SCOPE_PLAIN || op === OP_XFORM || op === OP_NODE || op === OP_FIELD || (op === OP_LEAF || op === OP_SOURCE_LEAF)) {
|
|
9952
9978
|
at = code[at + 2];
|
|
9953
9979
|
depth++;
|
|
9954
9980
|
continue;
|
|
@@ -9981,7 +10007,7 @@ function leadingScalarSequence(code, ip) {
|
|
|
9981
10007
|
at2 = code[at2 + 1];
|
|
9982
10008
|
continue;
|
|
9983
10009
|
}
|
|
9984
|
-
if (op === OP_GATE || op === OP_SCOPE_PLAIN || op === OP_XFORM || op === OP_NODE || op === OP_FIELD || op === OP_LEAF) {
|
|
10010
|
+
if (op === OP_GATE || op === OP_SCOPE_PLAIN || op === OP_XFORM || op === OP_NODE || op === OP_FIELD || (op === OP_LEAF || op === OP_SOURCE_LEAF)) {
|
|
9985
10011
|
at2 = code[at2 + 2];
|
|
9986
10012
|
continue;
|
|
9987
10013
|
}
|
|
@@ -10014,7 +10040,7 @@ function leadingScalarSequence(code, ip) {
|
|
|
10014
10040
|
at = code[at + 2];
|
|
10015
10041
|
continue;
|
|
10016
10042
|
}
|
|
10017
|
-
if (op === OP_GATE || op === OP_XFORM || op === OP_NODE || op === OP_FIELD || op === OP_LEAF) {
|
|
10043
|
+
if (op === OP_GATE || op === OP_XFORM || op === OP_NODE || op === OP_FIELD || (op === OP_LEAF || op === OP_SOURCE_LEAF)) {
|
|
10018
10044
|
at = code[at + 2];
|
|
10019
10045
|
continue;
|
|
10020
10046
|
}
|
|
@@ -10044,7 +10070,7 @@ function leadingLiteralFamily(code, constants, ip, minDepth = 2, limit = 4) {
|
|
|
10044
10070
|
if (op === OP_RULE || op === OP_LABEL || op === OP_TOKEN || op === OP_ATTEMPT || op === OP_PEEK) {
|
|
10045
10071
|
return walk(code[at + 1], depth + 1);
|
|
10046
10072
|
}
|
|
10047
|
-
if (op === OP_GATE || op === OP_SCOPE || op === OP_SCOPE_CAP || op === OP_SCOPE_PLAIN || op === OP_XFORM || op === OP_NODE || op === OP_FIELD || op === OP_LEAF) {
|
|
10073
|
+
if (op === OP_GATE || op === OP_SCOPE || op === OP_SCOPE_CAP || op === OP_SCOPE_PLAIN || op === OP_XFORM || op === OP_NODE || op === OP_FIELD || (op === OP_LEAF || op === OP_SOURCE_LEAF)) {
|
|
10048
10074
|
return walk(code[at + 2], depth + 1);
|
|
10049
10075
|
}
|
|
10050
10076
|
if (op === OP_SEQ || op === OP_SEQV) {
|
|
@@ -10930,8 +10956,10 @@ ${rootCap ? "ctx._rootTriviaCapture=sR\n" : ""}return v
|
|
|
10930
10956
|
}
|
|
10931
10957
|
/* ── boundaries ──────────────────────────────────────────────────────── */
|
|
10932
10958
|
case OP_TOKEN:
|
|
10933
|
-
case OP_LEAF:
|
|
10959
|
+
case OP_LEAF:
|
|
10960
|
+
case OP_SOURCE_LEAF: {
|
|
10934
10961
|
const isToken = op === OP_TOKEN;
|
|
10962
|
+
const capturesSource = isToken || op === OP_SOURCE_LEAF && hostCst;
|
|
10935
10963
|
const fn = isToken ? void 0 : fnRef(code[ip + 1]);
|
|
10936
10964
|
const child = link(isToken ? code[ip + 1] : code[ip + 2]);
|
|
10937
10965
|
const wasCap = L.buf ? "true" : "(ctx._cstBuf!==undefined||ctx._cstLeaves!==undefined)";
|
|
@@ -10964,7 +10992,7 @@ ctx._triviaLog=sOtl
|
|
|
10964
10992
|
if(v===FAIL)return FAIL
|
|
10965
10993
|
const e=EC.e
|
|
10966
10994
|
const out=${isToken ? "input.slice(pos,e)" : `${fn}(v,{start:pos,end:e})`}
|
|
10967
|
-
if(wasCap)pushCstLeaf(ctx,{_tag:'leaf',value:out,span:{start:pos,end:e}})
|
|
10995
|
+
if(wasCap)pushCstLeaf(ctx,{_tag:'leaf',value:${capturesSource ? "input.slice(pos,e)" : "out"},span:{start:pos,end:e}})
|
|
10968
10996
|
EC.e=e
|
|
10969
10997
|
return out
|
|
10970
10998
|
}`;
|
|
@@ -13373,7 +13401,8 @@ function assemble(t2, prog, cfg) {
|
|
|
13373
13401
|
return value;
|
|
13374
13402
|
};
|
|
13375
13403
|
}
|
|
13376
|
-
case OP_LEAF:
|
|
13404
|
+
case OP_LEAF:
|
|
13405
|
+
case OP_SOURCE_LEAF: {
|
|
13377
13406
|
const fn = fns[code[ip + 1]];
|
|
13378
13407
|
const child = link(code[ip + 2]);
|
|
13379
13408
|
return (input, pos, ctx) => {
|
|
@@ -13401,7 +13430,11 @@ function assemble(t2, prog, cfg) {
|
|
|
13401
13430
|
if (v === FAIL) return FAIL;
|
|
13402
13431
|
const end = EC.e;
|
|
13403
13432
|
const out = fn(v, { start: pos, end });
|
|
13404
|
-
if (wasCapturing) pushCstLeaf(ctx, {
|
|
13433
|
+
if (wasCapturing) pushCstLeaf(ctx, {
|
|
13434
|
+
_tag: "leaf",
|
|
13435
|
+
value: op === OP_SOURCE_LEAF && hostCst ? input.slice(pos, end) : out,
|
|
13436
|
+
span: { start: pos, end }
|
|
13437
|
+
});
|
|
13405
13438
|
EC.e = end;
|
|
13406
13439
|
return out;
|
|
13407
13440
|
};
|
|
@@ -15431,7 +15464,7 @@ function payloadKey(p, d) {
|
|
|
15431
15464
|
case "transform":
|
|
15432
15465
|
return `transform\0${fnKey(d.fnSrc, d.fn)}\0${d.recognitionOnly === true}`;
|
|
15433
15466
|
case "leaf":
|
|
15434
|
-
return `leaf\0${fnKey(d.fnSrc, d.fn)}`;
|
|
15467
|
+
return `leaf\0${d.cstValue ?? "value"}\0${fnKey(d.fnSrc, d.fn)}`;
|
|
15435
15468
|
case "many":
|
|
15436
15469
|
case "oneOrMore":
|
|
15437
15470
|
return `${d.tag}\0${d.min}\0${d.max ?? ""}`;
|
|
@@ -18006,7 +18039,7 @@ function rebuildCombinator(root, replacements) {
|
|
|
18006
18039
|
out = token(one(d.parser));
|
|
18007
18040
|
break;
|
|
18008
18041
|
case "leaf":
|
|
18009
|
-
out = leaf(one(d.parser), d.fn);
|
|
18042
|
+
out = d.cstValue === "source" ? sourceLeaf(one(d.parser), d.fn) : leaf(one(d.parser), d.fn);
|
|
18010
18043
|
break;
|
|
18011
18044
|
// A LABELLED expect reproduces `d.expected` exactly (`expect` sets it to `[label]`).
|
|
18012
18045
|
// An unlabelled one RE-DERIVES it from the rebuilt inner parser, so it can differ
|