parseman 0.51.1 → 0.52.0
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.map +1 -1
- package/dist/analysis/diagnostics.js +101 -35
- package/dist/analysis/diagnostics.js.map +1 -1
- package/dist/cli/index.js +103 -37
- package/dist/cli/index.js.map +1 -1
- package/dist/combinators/attempt.d.ts +11 -1
- package/dist/combinators/attempt.d.ts.map +1 -1
- package/dist/combinators/map.d.ts.map +1 -1
- package/dist/combinators/node.d.ts +6 -2
- package/dist/combinators/node.d.ts.map +1 -1
- package/dist/combinators/token.d.ts +8 -8
- package/dist/combinators/token.d.ts.map +1 -1
- package/dist/compiler/token-capability.js +4 -0
- package/dist/compiler/token-capability.js.map +1 -1
- package/dist/coverage.d.ts.map +1 -1
- package/dist/cst/trivia-kinds.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +107 -40
- package/dist/index.js.map +1 -1
- package/dist/plugin/evaluator.d.ts.map +1 -1
- package/dist/plugin/index.js +107 -41
- package/dist/plugin/index.js.map +1 -1
- package/dist/spec/index.js +55 -10
- 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 +404 -371
- package/dist/table/index.js.map +2 -2
- package/dist/table/ops.d.ts +9 -5
- package/dist/table/ops.d.ts.map +1 -1
- package/dist/table/site-labels.d.ts.map +1 -1
- package/dist/types.d.ts +9 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/analysis/commitment.ts +3 -1
- package/src/analysis/duplication.ts +1 -1
- package/src/analysis/rebuild.ts +3 -3
- package/src/combinators/attempt.ts +26 -3
- package/src/combinators/first-set.ts +5 -1
- package/src/combinators/map.ts +5 -1
- package/src/combinators/node.ts +12 -3
- package/src/combinators/token.ts +46 -3
- package/src/compiler/ir-serialize.ts +5 -5
- package/src/coverage.ts +3 -4
- package/src/cst/trivia-kinds.ts +6 -0
- package/src/index.ts +2 -1
- package/src/plugin/evaluator.ts +8 -5
- package/src/table/assemble.ts +30 -11
- package/src/table/child-slots.ts +2 -2
- package/src/table/emit-assembly.ts +13 -6
- package/src/table/encode-baseline.ts +8 -3
- package/src/table/encode.ts +16 -16
- package/src/table/exec-baseline.ts +30 -4
- package/src/table/exec.ts +14 -5
- package/src/table/ops.ts +10 -6
- package/src/table/scalar-terminal.ts +5 -5
- package/src/table/site-labels.ts +5 -3
- package/src/types.ts +9 -2
- package/src/version.ts +1 -1
package/dist/spec/index.js
CHANGED
|
@@ -221,6 +221,10 @@ function firstSetBody(p, seen, resolve, activeTrivia) {
|
|
|
221
221
|
case "node":
|
|
222
222
|
case "sepBy":
|
|
223
223
|
case "expect":
|
|
224
|
+
// A transaction accepts exactly what its inner accepts. Its own `_meta` is
|
|
225
|
+
// the inner's construction-time set, which reads `any` when the inner opens
|
|
226
|
+
// with a rule reference — resolve through it like any other wrapper.
|
|
227
|
+
case "attempt":
|
|
224
228
|
return fs(d.parser);
|
|
225
229
|
case "grammar":
|
|
226
230
|
return firstSetOf(
|
|
@@ -1360,6 +1364,10 @@ function peelLabel(p) {
|
|
|
1360
1364
|
return null;
|
|
1361
1365
|
}
|
|
1362
1366
|
function analyzeLabeledTrivia(trivia2) {
|
|
1367
|
+
if (trivia2._def.tag === "trivia") {
|
|
1368
|
+
const own = trivia2._meta.labeledTriviaSpec;
|
|
1369
|
+
if (own !== void 0) return own;
|
|
1370
|
+
}
|
|
1363
1371
|
if (trivia2 === labeledTrivia0) return labeledSpec0;
|
|
1364
1372
|
if (trivia2 === labeledTrivia1) return labeledSpec1;
|
|
1365
1373
|
if (trivia2 === labeledTrivia2) return labeledSpec2;
|
|
@@ -3980,13 +3988,24 @@ function dispatch(selector, ...arms) {
|
|
|
3980
3988
|
}
|
|
3981
3989
|
|
|
3982
3990
|
// src/combinators/attempt.ts
|
|
3983
|
-
function
|
|
3991
|
+
function containOption(options) {
|
|
3992
|
+
if (options === void 0) return false;
|
|
3993
|
+
for (const key of Object.keys(options)) {
|
|
3994
|
+
if (key !== "contain") throw new TypeError(`attempt(): unknown option ${JSON.stringify(key)}`);
|
|
3995
|
+
}
|
|
3996
|
+
if (options.contain !== void 0 && typeof options.contain !== "boolean") {
|
|
3997
|
+
throw new TypeError("attempt(): `contain` must be a boolean");
|
|
3998
|
+
}
|
|
3999
|
+
return options.contain === true;
|
|
4000
|
+
}
|
|
4001
|
+
function attempt(parser2, options) {
|
|
4002
|
+
const contain = containOption(options);
|
|
3984
4003
|
const guardable = parser2._meta.firstSet.kind !== "any" && !matchesEmpty(parser2);
|
|
3985
4004
|
let failExpected;
|
|
3986
4005
|
return {
|
|
3987
4006
|
_tag: "attempt",
|
|
3988
4007
|
_meta: parser2._meta,
|
|
3989
|
-
_def: { tag: "attempt", parser: parser2 },
|
|
4008
|
+
_def: contain ? { tag: "attempt", parser: parser2, contain: true } : { tag: "attempt", parser: parser2 },
|
|
3990
4009
|
parse(input, pos, ctx) {
|
|
3991
4010
|
if (guardable && ctx._probe === void 0 && !ctx._tolerant && !startsFirstSet(parser2, input, pos)) {
|
|
3992
4011
|
if (failExpected === void 0) {
|
|
@@ -4003,7 +4022,7 @@ function attempt(parser2) {
|
|
|
4003
4022
|
rollbackCstCapture(ctx, mark);
|
|
4004
4023
|
if (log !== void 0 && ctx._triviaLog && ctx._triviaLog.length !== log) ctx._triviaLog.length = log;
|
|
4005
4024
|
if (rootLog !== void 0 && ctx._rootTriviaLog && ctx._rootTriviaLog.length !== rootLog) ctx._rootTriviaLog.length = rootLog;
|
|
4006
|
-
if (result.committed) return result;
|
|
4025
|
+
if (result.committed && !contain) return result;
|
|
4007
4026
|
return { ok: false, expected: result.expected, span: { start: pos, end: pos } };
|
|
4008
4027
|
}
|
|
4009
4028
|
};
|
|
@@ -4759,7 +4778,7 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
4759
4778
|
throw new Error("node() options cannot combine project with unwrap or collapse");
|
|
4760
4779
|
}
|
|
4761
4780
|
const def = unwrap || collapse || project !== void 0 || captureTrivia || trailingTrivia || buildArity !== void 0 || tags !== void 0 && tags.length > 0 ? { ...baseDef, ...unwrap ? { unwrap: true } : {}, ...collapse ? { collapse: true } : {}, ...project !== void 0 ? { project } : {}, ...captureTrivia ? { captureTrivia: true } : {}, ...trailingTrivia ? { trailingTrivia: true } : {}, ...buildArity !== void 0 ? { buildArity } : {}, ...tags !== void 0 && tags.length > 0 ? { tags } : {} } : baseDef;
|
|
4762
|
-
const capturesTrivia = captureTrivia ||
|
|
4781
|
+
const capturesTrivia = captureTrivia || (build ? buildReadsTrivia(def) : project === void 0);
|
|
4763
4782
|
const clonesState = build ? buildReadsState(def) : project === void 0;
|
|
4764
4783
|
const hasOwnFields = parserHasOwnFields(combinator);
|
|
4765
4784
|
const capturesFields = hasOwnFields && (build ? buildReadsFields(def) : project === void 0);
|
|
@@ -4873,13 +4892,17 @@ function transform(combinator, fn) {
|
|
|
4873
4892
|
};
|
|
4874
4893
|
}
|
|
4875
4894
|
function trivia(combinator) {
|
|
4876
|
-
const
|
|
4895
|
+
const labeled = analyzeLabeledTrivia(combinator);
|
|
4896
|
+
const kindLabels = labeled?.labels;
|
|
4877
4897
|
return {
|
|
4878
4898
|
_tag: combinator._tag,
|
|
4879
4899
|
_meta: {
|
|
4880
4900
|
...combinator._meta,
|
|
4881
4901
|
isTrivia: true,
|
|
4882
4902
|
triviaScanner: fastTriviaScanner(combinator),
|
|
4903
|
+
// Every labeled scan of this trivia reads its spec; the module's four-slot
|
|
4904
|
+
// memo alone thrashes on a grammar with more than four trivia tables.
|
|
4905
|
+
labeledTriviaSpec: labeled,
|
|
4883
4906
|
...kindLabels ? { triviaKindLabels: kindLabels } : {}
|
|
4884
4907
|
},
|
|
4885
4908
|
_def: { tag: "trivia", parser: combinator },
|
|
@@ -4933,6 +4956,12 @@ function field(name, combinator) {
|
|
|
4933
4956
|
}
|
|
4934
4957
|
|
|
4935
4958
|
// src/combinators/token.ts
|
|
4959
|
+
function semanticLeafValue(_ctx, _input, _start, _end, value) {
|
|
4960
|
+
return value;
|
|
4961
|
+
}
|
|
4962
|
+
function sourceLeafValue(ctx, input, start, end, value) {
|
|
4963
|
+
return cstOutputHost(ctx.build) ? input.slice(start, end) : value;
|
|
4964
|
+
}
|
|
4936
4965
|
function token(root) {
|
|
4937
4966
|
const meta = {
|
|
4938
4967
|
firstSet: root._meta.firstSet,
|
|
@@ -4985,7 +5014,8 @@ function token(root) {
|
|
|
4985
5014
|
}
|
|
4986
5015
|
};
|
|
4987
5016
|
}
|
|
4988
|
-
function
|
|
5017
|
+
function makeLeaf(root, fn, sourceCstValue) {
|
|
5018
|
+
const cstValue = sourceCstValue ? sourceLeafValue : semanticLeafValue;
|
|
4989
5019
|
const meta = {
|
|
4990
5020
|
firstSet: root._meta.firstSet,
|
|
4991
5021
|
canMatchNewline: root._meta.canMatchNewline,
|
|
@@ -4994,7 +5024,12 @@ function leaf(root, fn) {
|
|
|
4994
5024
|
return {
|
|
4995
5025
|
_tag: "leaf",
|
|
4996
5026
|
_meta: meta,
|
|
4997
|
-
_def: {
|
|
5027
|
+
_def: {
|
|
5028
|
+
tag: "leaf",
|
|
5029
|
+
parser: root,
|
|
5030
|
+
fn,
|
|
5031
|
+
...sourceCstValue ? { cstValue: "source" } : {}
|
|
5032
|
+
},
|
|
4998
5033
|
parse(input, pos, ctx) {
|
|
4999
5034
|
const savedBuf = ctx._cstBuf;
|
|
5000
5035
|
const savedChildren = ctx._cstChildren;
|
|
@@ -5022,11 +5057,21 @@ function leaf(root, fn) {
|
|
|
5022
5057
|
}
|
|
5023
5058
|
if (!result.ok) return result;
|
|
5024
5059
|
const value = fn(result.value, result.span);
|
|
5025
|
-
if (wasCapturing) pushCstLeaf(ctx, {
|
|
5060
|
+
if (wasCapturing) pushCstLeaf(ctx, {
|
|
5061
|
+
_tag: "leaf",
|
|
5062
|
+
value: cstValue(ctx, input, pos, result.span.end, value),
|
|
5063
|
+
span: result.span
|
|
5064
|
+
});
|
|
5026
5065
|
return { ok: true, value, span: result.span };
|
|
5027
5066
|
}
|
|
5028
5067
|
};
|
|
5029
5068
|
}
|
|
5069
|
+
function leaf(root, fn) {
|
|
5070
|
+
return makeLeaf(root, fn, false);
|
|
5071
|
+
}
|
|
5072
|
+
function sourceLeaf(root, fn) {
|
|
5073
|
+
return makeLeaf(root, fn, true);
|
|
5074
|
+
}
|
|
5030
5075
|
|
|
5031
5076
|
// src/combinators/scanTo.ts
|
|
5032
5077
|
function resolveScanSkip(explicitSkip, raw, ctx) {
|
|
@@ -5311,7 +5356,7 @@ function evalRuleMapIR(ir) {
|
|
|
5311
5356
|
if (recognitionOnly) t._def.recognitionOnly = true;
|
|
5312
5357
|
return t;
|
|
5313
5358
|
};
|
|
5314
|
-
const _lf = (child, src) => {
|
|
5359
|
+
const _lf = (child, src, source = false) => {
|
|
5315
5360
|
let fn2;
|
|
5316
5361
|
try {
|
|
5317
5362
|
fn2 = (0, eval)(`(${src})`);
|
|
@@ -5320,7 +5365,7 @@ function evalRuleMapIR(ir) {
|
|
|
5320
5365
|
throw new Error("IR leaf fn not materialized");
|
|
5321
5366
|
};
|
|
5322
5367
|
}
|
|
5323
|
-
const l = leaf(child, fn2);
|
|
5368
|
+
const l = source ? sourceLeaf(child, fn2) : leaf(child, fn2);
|
|
5324
5369
|
l._def.fnSrc = src;
|
|
5325
5370
|
return l;
|
|
5326
5371
|
};
|