parseman 0.29.0 → 0.30.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/combinators/attempt.d.ts.map +1 -1
- package/dist/combinators/choice.d.ts +11 -0
- package/dist/combinators/choice.d.ts.map +1 -1
- package/dist/combinators/expect.d.ts.map +1 -1
- package/dist/combinators/first-set.d.ts +7 -0
- package/dist/combinators/first-set.d.ts.map +1 -1
- package/dist/combinators/node.d.ts.map +1 -1
- package/dist/combinators/repeat.d.ts.map +1 -1
- package/dist/compiler/codegen.d.ts +1 -0
- package/dist/compiler/codegen.d.ts.map +1 -1
- package/dist/index.cjs +147 -15
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +147 -15
- package/dist/index.js.map +2 -2
- package/dist/plugin/index.cjs +147 -15
- package/dist/plugin/index.cjs.map +3 -3
- package/dist/plugin/index.js +147 -15
- package/dist/plugin/index.js.map +3 -3
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attempt.d.ts","sourceRoot":"","sources":["../../src/combinators/attempt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA6B,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"attempt.d.ts","sourceRoot":"","sources":["../../src/combinators/attempt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA6B,MAAM,aAAa,CAAA;AAKxE;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CA2B/D"}
|
|
@@ -4,6 +4,17 @@ type UnionArms<T extends (Combinator<unknown> | GatedArm<unknown>)[]> = {
|
|
|
4
4
|
[K in keyof T]: ArmParser<T[K]>;
|
|
5
5
|
}[number] extends Combinator<infer U> ? U : never;
|
|
6
6
|
export declare function choice<T extends [Combinator<unknown> | GatedArm<unknown>, ...(Combinator<unknown> | GatedArm<unknown>)[]]>(...args: T): Combinator<UnionArms<T>>;
|
|
7
|
+
/**
|
|
8
|
+
* Peel wrappers that neither consume input nor skip trivia before their inner
|
|
9
|
+
* sequence -- `node`, `parser`/`grammar`, `transform`, `label` -- down to the core
|
|
10
|
+
* `sequence` and return its FIRST term (the candidate shared prefix), or null when
|
|
11
|
+
* the arm is not a wrapped-or-bare sequence with >=2 terms. Because none of these
|
|
12
|
+
* wrappers advance the position before the sequence's first term, the term is parsed
|
|
13
|
+
* at the arm's entry position in every arm, so the once-recognized prefix can be
|
|
14
|
+
* replayed there. `attempt`/`optional`/`many`/`choice`/etc. are NOT peeled, so such
|
|
15
|
+
* arms are conservatively excluded.
|
|
16
|
+
*/
|
|
17
|
+
export declare function leadingTermOfArm(arm: Combinator<unknown>): Combinator<unknown> | null;
|
|
7
18
|
/** Walk transform wrappers to find an inner literal's string value. */
|
|
8
19
|
export declare function getCoreLiteralValue(p: Combinator<unknown>): string | null;
|
|
9
20
|
/** Walk transform wrappers to find an inner regex's source/flags. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"choice.d.ts","sourceRoot":"","sources":["../../src/combinators/choice.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAC+B,QAAQ,EAClD,MAAM,aAAa,CAAA;AAKpB,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,KAAK,CAAA;AACvH,KAAK,SAAS,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI;KACrE,CAAC,IAAI,MAAM,CAAC,GAAG,SA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EACxH,GAAG,IAAI,EAAE,CAAC,GACT,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CA2J1B;AA4FD;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,IAAI,CAWrF;AA6CD,uEAAuE;AACvE,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAKzE;AAED,qEAAqE;AACrE,wBAAgB,eAAe,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAMhG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/combinators/expect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,UAAU,EAAE,MAAM,aAAa,CAAA;AAGhG,YAAY,EAAE,UAAU,EAAE,CAAA;AAE1B;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/combinators/expect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,UAAU,EAAE,MAAM,aAAa,CAAA;AAGhG,YAAY,EAAE,UAAU,EAAE,CAAA;AAE1B;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,MAAM,EAAE,CAsC/D;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,GAAG,UAAU,CAAC,CA2B/F;AAED,+DAA+D;AAC/D,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE"}
|
|
@@ -2,6 +2,13 @@ import type { FirstSet, Combinator } from '../types.ts';
|
|
|
2
2
|
export declare function union(a: FirstSet, b: FirstSet): FirstSet;
|
|
3
3
|
export declare function intersects(a: FirstSet, b: FirstSet): boolean;
|
|
4
4
|
export declare function fromChar(code: number): FirstSet;
|
|
5
|
+
/**
|
|
6
|
+
* True when `combinator`'s first set admits the code point at `input[pos]` (or its
|
|
7
|
+
* first set is `any`). The runtime counterpart of codegen's `firstSetCond` guard —
|
|
8
|
+
* used by the interpreter's first-set fail-fast in `optional`/`many`/`attempt`/
|
|
9
|
+
* `node` to reject a doomed sub-parse before doing any setup. Returns `false` at EOF.
|
|
10
|
+
*/
|
|
11
|
+
export declare function startsFirstSet(combinator: Combinator<unknown>, input: string, pos: number): boolean;
|
|
5
12
|
export declare function fromRange(lo: number, hi: number): FirstSet;
|
|
6
13
|
export declare function any(): FirstSet;
|
|
7
14
|
export declare function empty(): FirstSet;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"first-set.d.ts","sourceRoot":"","sources":["../../src/combinators/first-set.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,QAAQ,EAAE,UAAU,EAAa,MAAM,aAAa,CAAA;AAE7E,wBAAgB,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAKxD;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,GAAG,OAAO,CAS5D;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAE/C;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,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AAI,QAAQ,CAEhC;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,GAAG,OAAO,CAqCxG;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,UAAU,CAAC,OAAO,CAAC,EAAE,GAAG,QAAQ,CAOlF;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,GAAG,QAAQ,CAsCvG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/combinators/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAoD,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/combinators/node.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAoD,MAAM,aAAa,CAAA;AAQzG;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CACzB,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,EAChC,MAAM,EAAE,QAAQ,GAAG,SAAS,EAC5B,IAAI,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EACpC,WAAW,EAAE,aAAa,CAAC,OAAO,CAAC,EACnC,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,KAAK,EAAE,OAAO,KACX,CAAC,CAAA;AAEN;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,WAAW,GAAG;IAAE,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IAAC,cAAc,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAqBrH,wBAAgB,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA;AACjH,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repeat.d.ts","sourceRoot":"","sources":["../../src/combinators/repeat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"repeat.d.ts","sourceRoot":"","sources":["../../src/combinators/repeat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAyC,MAAM,aAAa,CAAA;AAqEpF,wBAAgB,IAAI,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAkDlE;AAED,wBAAgB,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CA8CvE;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC,CAwB3E;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,CAAC,CAwFhG"}
|
|
@@ -39,6 +39,7 @@ export declare function beginLoweringCapture(): void;
|
|
|
39
39
|
export declare function endLoweringCapture(): string[];
|
|
40
40
|
export declare function firstSetCond(codeVar: string, fs: FirstSet): string;
|
|
41
41
|
export declare function __setForceDisjointIf(on: boolean): void;
|
|
42
|
+
export declare function __setForceNoSharedPrefix(on: boolean): void;
|
|
42
43
|
export type CompiledParser<T> = {
|
|
43
44
|
parse(input: string, pos?: number): ParseResult<T>;
|
|
44
45
|
/** Like parse(), but with a caller-supplied ParseContext (e.g. `_triviaLog` for CST grammars). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codegen.d.ts","sourceRoot":"","sources":["../../src/compiler/codegen.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAa,QAAQ,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAA4B,MAAM,aAAa,CAAA;AAKnI;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,GAAG;IAAE,QAAQ,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAAA;AACnE,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,IAAI,GAAE,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAa,GAAG,cAAc,CAmCxH;AAED,OAAO,EAAoB,KAAK,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAsBtF;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,uTAC0R,CAAA;AActT,8EAA8E;AAC9E,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED,+EAA+E;AAC/E,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAI7C;
|
|
1
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AC,QAAQ,CAAC,EAAE,mBAAmB,CAAA;CAAE,GACtH,cAAc,GAAG,IAAI,CA8MvB"}
|
package/dist/index.cjs
CHANGED
|
@@ -117,6 +117,15 @@ function intersects(a, b) {
|
|
|
117
117
|
function fromChar(code) {
|
|
118
118
|
return { kind: "ranges", ranges: [{ lo: code, hi: code }] };
|
|
119
119
|
}
|
|
120
|
+
function startsFirstSet(combinator, input, pos) {
|
|
121
|
+
const fs = combinator._meta.firstSet;
|
|
122
|
+
if (fs.kind === "any") return true;
|
|
123
|
+
if (fs.kind === "empty") return false;
|
|
124
|
+
const code = input.codePointAt(pos);
|
|
125
|
+
if (code === void 0) return false;
|
|
126
|
+
for (const r of fs.ranges) if (code >= r.lo && code <= r.hi) return true;
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
120
129
|
function fromRange(lo, hi) {
|
|
121
130
|
return { kind: "ranges", ranges: [{ lo, hi }] };
|
|
122
131
|
}
|
|
@@ -1043,6 +1052,17 @@ function deriveExpected(c) {
|
|
|
1043
1052
|
return def.parsers.length > 0 ? deriveExpected(def.parsers[0]) : [];
|
|
1044
1053
|
case "attempt":
|
|
1045
1054
|
return deriveExpected(def.parser);
|
|
1055
|
+
// Delegating wrappers whose first-token failure is their inner parser's — must
|
|
1056
|
+
// pass through so a start-failure (and the first-set-miss fast-path in attempt/
|
|
1057
|
+
// node, which reads this) names the real expected token, not the wrapper tag.
|
|
1058
|
+
case "field":
|
|
1059
|
+
case "withCtx":
|
|
1060
|
+
case "recover":
|
|
1061
|
+
return deriveExpected(def.parser);
|
|
1062
|
+
case "skip":
|
|
1063
|
+
return deriveExpected(def.main);
|
|
1064
|
+
case "expect":
|
|
1065
|
+
return def.expected;
|
|
1046
1066
|
case "node":
|
|
1047
1067
|
case "grammar":
|
|
1048
1068
|
case "trivia":
|
|
@@ -1106,7 +1126,7 @@ function choice(...args) {
|
|
|
1106
1126
|
disjoint
|
|
1107
1127
|
};
|
|
1108
1128
|
const strategy = disjoint || hasGates ? null : detectStrategy(parsers);
|
|
1109
|
-
const autoNot = !disjoint && !hasGates && strategy?.tag === "firstMatch" ? computeAutoNot(parsers) : parsers.map(() => null);
|
|
1129
|
+
const autoNot = !disjoint && !hasGates && (strategy?.tag === "firstMatch" || strategy?.tag === "sharedPrefix") ? computeAutoNot(parsers) : parsers.map(() => null);
|
|
1110
1130
|
let greedyLitMap = null;
|
|
1111
1131
|
let sortedParsers = null;
|
|
1112
1132
|
const asciiDispatch = disjoint ? buildAsciiDispatch(parsers) : null;
|
|
@@ -1232,8 +1252,47 @@ function detectStrategy(parsers) {
|
|
|
1232
1252
|
);
|
|
1233
1253
|
return { tag: "literalsLongestFirst", sortedIndices };
|
|
1234
1254
|
}
|
|
1255
|
+
const shared = detectSharedPrefix(parsers);
|
|
1256
|
+
if (shared !== null) return shared;
|
|
1235
1257
|
return { tag: "firstMatch" };
|
|
1236
1258
|
}
|
|
1259
|
+
function bareLeadingTermKey(term) {
|
|
1260
|
+
const d = term._def;
|
|
1261
|
+
if (d.tag === "literal" && !d.caseInsensitive) return `L:${d.value}`;
|
|
1262
|
+
if (d.tag === "regex") return `R:${d.source}\0${d.flags}`;
|
|
1263
|
+
return null;
|
|
1264
|
+
}
|
|
1265
|
+
function detectSharedPrefix(parsers) {
|
|
1266
|
+
if (parsers.length < 2) return null;
|
|
1267
|
+
let key = null;
|
|
1268
|
+
let prefix = null;
|
|
1269
|
+
const members = [];
|
|
1270
|
+
for (let i = 0; i < parsers.length; i++) {
|
|
1271
|
+
const term0 = leadingTermOfArm(parsers[i]);
|
|
1272
|
+
if (term0 === null) return null;
|
|
1273
|
+
const k = bareLeadingTermKey(term0);
|
|
1274
|
+
if (k === null) return null;
|
|
1275
|
+
if (key === null) {
|
|
1276
|
+
key = k;
|
|
1277
|
+
prefix = term0;
|
|
1278
|
+
} else if (k !== key) return null;
|
|
1279
|
+
members.push(i);
|
|
1280
|
+
}
|
|
1281
|
+
if (prefix === null || members.length < 2) return null;
|
|
1282
|
+
return { tag: "sharedPrefix", prefix, members };
|
|
1283
|
+
}
|
|
1284
|
+
function leadingTermOfArm(arm) {
|
|
1285
|
+
let d = arm._def;
|
|
1286
|
+
for (; ; ) {
|
|
1287
|
+
if (d.tag === "node" || d.tag === "grammar" || d.tag === "transform" || d.tag === "label") {
|
|
1288
|
+
d = d.parser._def;
|
|
1289
|
+
continue;
|
|
1290
|
+
}
|
|
1291
|
+
break;
|
|
1292
|
+
}
|
|
1293
|
+
if (d.tag !== "sequence" || d.parsers.length < 2) return null;
|
|
1294
|
+
return d.parsers[0];
|
|
1295
|
+
}
|
|
1237
1296
|
function computeAutoNot(parsers) {
|
|
1238
1297
|
return parsers.map((p, i) => {
|
|
1239
1298
|
const litVal = getCoreLiteralValue(p);
|
|
@@ -1827,11 +1886,20 @@ function sequence(...parsers) {
|
|
|
1827
1886
|
|
|
1828
1887
|
// src/combinators/attempt.ts
|
|
1829
1888
|
function attempt(parser2) {
|
|
1889
|
+
const guardable = parser2._meta.firstSet.kind !== "any" && !matchesEmpty(parser2);
|
|
1890
|
+
let failExpected;
|
|
1830
1891
|
return {
|
|
1831
1892
|
_tag: "attempt",
|
|
1832
1893
|
_meta: parser2._meta,
|
|
1833
1894
|
_def: { tag: "attempt", parser: parser2 },
|
|
1834
1895
|
parse(input, pos, ctx) {
|
|
1896
|
+
if (guardable && ctx._probe === void 0 && !ctx._tolerant && !startsFirstSet(parser2, input, pos)) {
|
|
1897
|
+
if (failExpected === void 0) {
|
|
1898
|
+
const e = deriveExpected(parser2);
|
|
1899
|
+
failExpected = e.length > 0 ? e : [parser2._tag];
|
|
1900
|
+
}
|
|
1901
|
+
return { ok: false, expected: failExpected, span: { start: pos, end: pos } };
|
|
1902
|
+
}
|
|
1835
1903
|
const mark = saveCstMark(ctx);
|
|
1836
1904
|
const log = ctx._triviaLog?.length;
|
|
1837
1905
|
const result = parser2.parse(input, pos, ctx);
|
|
@@ -1844,7 +1912,7 @@ function attempt(parser2) {
|
|
|
1844
1912
|
}
|
|
1845
1913
|
|
|
1846
1914
|
// src/combinators/repeat.ts
|
|
1847
|
-
function repItem(combinator, input, cur, ctx) {
|
|
1915
|
+
function repItem(combinator, input, cur, ctx, guardable) {
|
|
1848
1916
|
const mark = saveTriviaMark(ctx);
|
|
1849
1917
|
let pos = cur;
|
|
1850
1918
|
if (ctx.trivia) {
|
|
@@ -1860,6 +1928,10 @@ function repItem(combinator, input, cur, ctx) {
|
|
|
1860
1928
|
rollbackTrivia(ctx, mark);
|
|
1861
1929
|
return "stop";
|
|
1862
1930
|
}
|
|
1931
|
+
if (guardable && ctx._probe === void 0 && !ctx._tolerant && !startsFirstSet(combinator, input, pos)) {
|
|
1932
|
+
rollbackTrivia(ctx, mark);
|
|
1933
|
+
return "stop";
|
|
1934
|
+
}
|
|
1863
1935
|
const result = combinator.parse(input, pos, ctx);
|
|
1864
1936
|
if (!result.ok) {
|
|
1865
1937
|
rollbackTrivia(ctx, mark);
|
|
@@ -1879,6 +1951,7 @@ function many(combinator) {
|
|
|
1879
1951
|
};
|
|
1880
1952
|
const def = { tag: "many", parser: combinator, min: 0 };
|
|
1881
1953
|
let expected;
|
|
1954
|
+
const guardable = combinator._meta.firstSet.kind !== "any" && !matchesEmpty(combinator);
|
|
1882
1955
|
return {
|
|
1883
1956
|
_tag: "many",
|
|
1884
1957
|
_meta: meta,
|
|
@@ -1887,7 +1960,7 @@ function many(combinator) {
|
|
|
1887
1960
|
const values = def.valueUnused ? void 0 : [];
|
|
1888
1961
|
let cur = pos;
|
|
1889
1962
|
while (cur < input.length) {
|
|
1890
|
-
const item = repItem(combinator, input, cur, ctx);
|
|
1963
|
+
const item = repItem(combinator, input, cur, ctx, guardable);
|
|
1891
1964
|
if (item === "stop") break;
|
|
1892
1965
|
if ("fail" in item) {
|
|
1893
1966
|
const sync = ctx._tolerant ? ctx._sync : void 0;
|
|
@@ -1915,6 +1988,7 @@ function oneOrMore(combinator) {
|
|
|
1915
1988
|
};
|
|
1916
1989
|
const def = { tag: "oneOrMore", parser: combinator, min: 1 };
|
|
1917
1990
|
let expected;
|
|
1991
|
+
const guardable = combinator._meta.firstSet.kind !== "any" && !matchesEmpty(combinator);
|
|
1918
1992
|
return {
|
|
1919
1993
|
_tag: "oneOrMore",
|
|
1920
1994
|
_meta: meta,
|
|
@@ -1925,7 +1999,7 @@ function oneOrMore(combinator) {
|
|
|
1925
1999
|
const values = def.valueUnused ? void 0 : [first.value];
|
|
1926
2000
|
let cur = first.span.end;
|
|
1927
2001
|
while (cur < input.length) {
|
|
1928
|
-
const item = repItem(combinator, input, cur, ctx);
|
|
2002
|
+
const item = repItem(combinator, input, cur, ctx, guardable);
|
|
1929
2003
|
if (item === "stop") break;
|
|
1930
2004
|
if ("fail" in item) {
|
|
1931
2005
|
const sync = ctx._tolerant ? ctx._sync : void 0;
|
|
@@ -1968,15 +2042,6 @@ function optional(combinator) {
|
|
|
1968
2042
|
}
|
|
1969
2043
|
};
|
|
1970
2044
|
}
|
|
1971
|
-
function startsFirstSet(combinator, input, pos) {
|
|
1972
|
-
const fs = combinator._meta.firstSet;
|
|
1973
|
-
if (fs.kind === "any") return true;
|
|
1974
|
-
if (fs.kind === "empty") return false;
|
|
1975
|
-
const code = input.codePointAt(pos);
|
|
1976
|
-
if (code === void 0) return false;
|
|
1977
|
-
for (const r of fs.ranges) if (code >= r.lo && code <= r.hi) return true;
|
|
1978
|
-
return false;
|
|
1979
|
-
}
|
|
1980
2045
|
function sepBy(combinator, separator) {
|
|
1981
2046
|
const meta = {
|
|
1982
2047
|
firstSet: combinator._meta.firstSet,
|
|
@@ -2510,11 +2575,20 @@ function node(typeOrCombinator, combinatorOrBuild, buildOrOpts, maybeOpts) {
|
|
|
2510
2575
|
const capturesTrivia = captureTrivia || trailingTrivia || (build ? buildReadsTrivia(def) : true);
|
|
2511
2576
|
const clonesState = build ? buildReadsState(def) : true;
|
|
2512
2577
|
const capturesFields = parserHasOwnFields(combinator) && (build ? buildReadsFields(def) : true);
|
|
2578
|
+
const guardable = combinator._meta.firstSet.kind !== "any" && !matchesEmpty(combinator);
|
|
2579
|
+
let failExpected;
|
|
2513
2580
|
return {
|
|
2514
2581
|
_tag: "node",
|
|
2515
2582
|
_meta: meta,
|
|
2516
2583
|
_def: def,
|
|
2517
2584
|
parse(input, pos, ctx) {
|
|
2585
|
+
if (guardable && ctx._probe === void 0 && !ctx._tolerant && !startsFirstSet(combinator, input, pos)) {
|
|
2586
|
+
if (failExpected === void 0) {
|
|
2587
|
+
const e = deriveExpected(combinator);
|
|
2588
|
+
failExpected = e.length > 0 ? e : [combinator._tag];
|
|
2589
|
+
}
|
|
2590
|
+
return { ok: false, expected: failExpected, span: { start: pos, end: pos } };
|
|
2591
|
+
}
|
|
2518
2592
|
const saved = beginCstNodeCapture(ctx);
|
|
2519
2593
|
const savedFields = ctx._fields;
|
|
2520
2594
|
ctx._fields = capturesFields ? [] : void 0;
|
|
@@ -4527,6 +4601,7 @@ var SWITCH_RANGE_LIMIT = 4;
|
|
|
4527
4601
|
var SWITCH_MAX_CASES = 48;
|
|
4528
4602
|
var SWITCH_MIN_CASES = 3;
|
|
4529
4603
|
var _forceDisjointIf = false;
|
|
4604
|
+
var _forceNoSharedPrefix = false;
|
|
4530
4605
|
function planDisjointDispatch(parsers) {
|
|
4531
4606
|
const cases = [];
|
|
4532
4607
|
let total = 0;
|
|
@@ -5162,7 +5237,7 @@ function emitLiteralsLongestFirst(def, sortedIndices, allExpected, ctx, pos, cov
|
|
|
5162
5237
|
stmts.push(...emitElseFail(ctx, failArrBody(ctx, allExpected, pos)));
|
|
5163
5238
|
return { stmts, valueVar: valV, endVar: endV };
|
|
5164
5239
|
}
|
|
5165
|
-
function emitFirstMatch(def, ctx, pos, coverageBase) {
|
|
5240
|
+
function emitFirstMatch(def, ctx, pos, coverageBase, preStmts, armGuardPrefix) {
|
|
5166
5241
|
const resValV = v(ctx, "_crv");
|
|
5167
5242
|
const resEndV = v(ctx, "_cre");
|
|
5168
5243
|
const resOkV = v(ctx, "_crok");
|
|
@@ -5176,6 +5251,7 @@ function emitFirstMatch(def, ctx, pos, coverageBase) {
|
|
|
5176
5251
|
...autoRejectedV === void 0 ? [] : [`${ind0}const ${autoRejectedV} = []`],
|
|
5177
5252
|
`${ind0}const ${codeV} = ${pos} < input.length ? (input.codePointAt(${pos}) ?? -1) : -1`
|
|
5178
5253
|
];
|
|
5254
|
+
if (preStmts) stmts.push(...preStmts);
|
|
5179
5255
|
for (let i = 0; i < def.parsers.length; i++) {
|
|
5180
5256
|
const p = def.parsers[i];
|
|
5181
5257
|
const gate = def.gates[i];
|
|
@@ -5183,11 +5259,12 @@ function emitFirstMatch(def, ctx, pos, coverageBase) {
|
|
|
5183
5259
|
const atStart = failsAtStart(p);
|
|
5184
5260
|
const staticFx = armStaticExpected(ctx, p);
|
|
5185
5261
|
const deferRuleName = ctx.deferFirstSetRefs ? p._ruleName : void 0;
|
|
5186
|
-
const
|
|
5262
|
+
const baseFsGuard = deferRuleName !== void 0 ? `/*@FS:${deferRuleName}:${codeV}@*/true` : needsFirstSetGuard(p) ? firstSetCond(codeV, p._meta.firstSet) : (() => {
|
|
5187
5263
|
if (p._meta.firstSet.kind !== "any" || matchesEmpty(p)) return null;
|
|
5188
5264
|
const deep = firstSetOf(p);
|
|
5189
5265
|
return deep.kind === "ranges" ? firstSetCond(codeV, deep) : null;
|
|
5190
5266
|
})();
|
|
5267
|
+
const fsGuard = armGuardPrefix === void 0 ? baseFsGuard : baseFsGuard === null ? armGuardPrefix : `${armGuardPrefix} && (${baseFsGuard})`;
|
|
5191
5268
|
let gateCond = null;
|
|
5192
5269
|
if (gate) {
|
|
5193
5270
|
const gateIdx = ctx.mapFns.length;
|
|
@@ -5256,11 +5333,64 @@ function emitFirstMatch(def, ctx, pos, coverageBase) {
|
|
|
5256
5333
|
stmts.push(...emitIfFail(ctx, `!${resOkV}`, failArrBody(ctx, concatExpr, pos, false)));
|
|
5257
5334
|
return { stmts, valueVar: resValV, endVar: resEndV };
|
|
5258
5335
|
}
|
|
5336
|
+
function emitsAsNamedFn(p, ctx) {
|
|
5337
|
+
if (p._def.tag === "lazy") return true;
|
|
5338
|
+
if (ctx.ruleNames?.has(p)) return true;
|
|
5339
|
+
if (ctx.namedParsers.has(p)) return true;
|
|
5340
|
+
const usage = ctx.lazyUsage;
|
|
5341
|
+
return !!usage && !ctx.noHoist && !ctx.capAsTrivia && isHoistableTag(p._def.tag) && (usage.counts.get(p) ?? 0) > 1 && (usage.sizes.get(p) ?? 0) >= HOIST_MIN_SUBTREE;
|
|
5342
|
+
}
|
|
5343
|
+
function armReplayInScope(arm, ctx) {
|
|
5344
|
+
let p = arm;
|
|
5345
|
+
for (; ; ) {
|
|
5346
|
+
if (emitsAsNamedFn(p, ctx)) return false;
|
|
5347
|
+
const d = p._def;
|
|
5348
|
+
if (d.tag === "node" || d.tag === "grammar" || d.tag === "transform" || d.tag === "label") {
|
|
5349
|
+
p = d.parser;
|
|
5350
|
+
continue;
|
|
5351
|
+
}
|
|
5352
|
+
return d.tag === "sequence";
|
|
5353
|
+
}
|
|
5354
|
+
}
|
|
5355
|
+
function emitSharedPrefix(def, strategy, ctx, pos) {
|
|
5356
|
+
const { prefix, members } = strategy;
|
|
5357
|
+
const savedCapturing = ctx.capturing;
|
|
5358
|
+
ctx.capturing = false;
|
|
5359
|
+
const pfx = emitFallible(prefix, ctx, pos, false);
|
|
5360
|
+
ctx.capturing = savedCapturing;
|
|
5361
|
+
const map = ctx.replayPrefix ??= /* @__PURE__ */ new Map();
|
|
5362
|
+
const keys = [];
|
|
5363
|
+
for (const i of members) {
|
|
5364
|
+
const term0 = leadingTermOfArm(def.parsers[i]);
|
|
5365
|
+
if (term0 === null) continue;
|
|
5366
|
+
map.set(term0, { valVar: pfx.valVar, endVar: pfx.endVar });
|
|
5367
|
+
keys.push(term0);
|
|
5368
|
+
}
|
|
5369
|
+
const r = emitFirstMatch(def, ctx, pos, void 0, pfx.stmts, pfx.okVar);
|
|
5370
|
+
for (const k of keys) map.delete(k);
|
|
5371
|
+
return r;
|
|
5372
|
+
}
|
|
5373
|
+
function emitReplayPrefixLeaf(ctx, pos, replay) {
|
|
5374
|
+
const vv = v(ctx);
|
|
5375
|
+
return {
|
|
5376
|
+
stmts: [
|
|
5377
|
+
`${ind(ctx)}const ${vv} = ${replay.valVar}`,
|
|
5378
|
+
...emitLeafCapture(ctx, vv, pos, replay.endVar)
|
|
5379
|
+
],
|
|
5380
|
+
valueVar: vv,
|
|
5381
|
+
endVar: replay.endVar
|
|
5382
|
+
};
|
|
5383
|
+
}
|
|
5259
5384
|
function emitNonDisjoint(def, strategy, allExpected, ctx, pos, coverageBase) {
|
|
5260
5385
|
if (strategy.tag === "greedyClassify")
|
|
5261
5386
|
return emitGreedyClassify(def, strategy.superIndex, ctx, pos, coverageBase);
|
|
5262
5387
|
if (strategy.tag === "literalsLongestFirst")
|
|
5263
5388
|
return emitLiteralsLongestFirst(def, strategy.sortedIndices, allExpected, ctx, pos, coverageBase);
|
|
5389
|
+
if (strategy.tag === "sharedPrefix") {
|
|
5390
|
+
if (!_forceNoSharedPrefix && coverageBase === void 0 && !ctx.recovery && strategy.members.every((i) => armReplayInScope(def.parsers[i], ctx)))
|
|
5391
|
+
return emitSharedPrefix(def, strategy, ctx, pos);
|
|
5392
|
+
return emitFirstMatch(def, ctx, pos, coverageBase);
|
|
5393
|
+
}
|
|
5264
5394
|
return emitFirstMatch(def, ctx, pos, coverageBase);
|
|
5265
5395
|
}
|
|
5266
5396
|
function pushMapFn(ctx, fn, src) {
|
|
@@ -5974,6 +6104,8 @@ function emitExpect(def, ctx, pos) {
|
|
|
5974
6104
|
return { stmts, valueVar: valVar, endVar };
|
|
5975
6105
|
}
|
|
5976
6106
|
function emit(p, ctx, pos) {
|
|
6107
|
+
const replay = ctx.replayPrefix?.get(p);
|
|
6108
|
+
if (replay !== void 0) return emitReplayPrefixLeaf(ctx, pos, replay);
|
|
5977
6109
|
const dispatch = (emissionPos = pos) => {
|
|
5978
6110
|
const savedRule = ctx.activeCoverageRuleId;
|
|
5979
6111
|
const rule = ctx.coverage?.plan.rules.get(p);
|