parseman 0.50.3 → 0.50.5
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 +24 -10
- package/dist/analysis/diagnostics.js.map +2 -2
- package/dist/cli/index.js +24 -10
- package/dist/cli/index.js.map +2 -2
- package/dist/combinators/first-set.d.ts.map +1 -1
- package/dist/compiler/token-capability.js +22 -8
- package/dist/compiler/token-capability.js.map +1 -1
- package/dist/index.js +55 -13
- package/dist/index.js.map +1 -1
- package/dist/plugin/index.js +55 -13
- package/dist/plugin/index.js.map +1 -1
- package/dist/spec/index.js +22 -8
- package/dist/spec/index.js.map +1 -1
- package/dist/table/encode.d.ts.map +1 -1
- package/dist/table/index.js +24 -10
- package/dist/table/index.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/combinators/first-set.ts +33 -7
- package/src/compiler/ir-serialize.ts +41 -2
- package/src/table/encode.ts +14 -2
- package/src/version.ts +1 -1
|
@@ -35,10 +35,20 @@ function classifyFinalChoice(arms, resolve) {
|
|
|
35
35
|
}
|
|
36
36
|
return { exclusive, firstSets, nullable: nullable2 };
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function winnerForRef(p, resolve) {
|
|
39
39
|
if (resolve === void 0) return void 0;
|
|
40
40
|
const name = p._ruleName;
|
|
41
|
-
|
|
41
|
+
const w = name === void 0 ? void 0 : resolve(name);
|
|
42
|
+
if (w === void 0 || w === p) return void 0;
|
|
43
|
+
let cur = w;
|
|
44
|
+
for (const seen = /* @__PURE__ */ new Set(); !seen.has(cur); ) {
|
|
45
|
+
if (cur === p) return void 0;
|
|
46
|
+
seen.add(cur);
|
|
47
|
+
const cd = cur._def;
|
|
48
|
+
if (cd.tag !== "grammar" && cd.tag !== "trivia") return w;
|
|
49
|
+
cur = cd.parser;
|
|
50
|
+
}
|
|
51
|
+
return w;
|
|
42
52
|
}
|
|
43
53
|
function union(a, b) {
|
|
44
54
|
if (a.kind === "any" || b.kind === "any") return { kind: "any" };
|
|
@@ -136,13 +146,15 @@ function matchesEmptyBody(p, seen, resolve) {
|
|
|
136
146
|
case "grammar":
|
|
137
147
|
case "recover":
|
|
138
148
|
return me(d.parser);
|
|
139
|
-
case "lazy":
|
|
149
|
+
case "lazy": {
|
|
150
|
+
const w = winnerForRef(p, resolve);
|
|
151
|
+
if (w !== void 0) return me(w);
|
|
140
152
|
try {
|
|
141
153
|
return me(d.thunk());
|
|
142
154
|
} catch {
|
|
143
|
-
|
|
144
|
-
return t2 ? me(t2) : true;
|
|
155
|
+
return true;
|
|
145
156
|
}
|
|
157
|
+
}
|
|
146
158
|
default:
|
|
147
159
|
return true;
|
|
148
160
|
}
|
|
@@ -206,13 +218,15 @@ function firstSetBody(p, seen, resolve) {
|
|
|
206
218
|
// terminals: no refs, cached set is exact
|
|
207
219
|
case "dispatch":
|
|
208
220
|
return fs(d.selector);
|
|
209
|
-
case "lazy":
|
|
221
|
+
case "lazy": {
|
|
222
|
+
const w = winnerForRef(p, resolve);
|
|
223
|
+
if (w !== void 0) return fs(w);
|
|
210
224
|
try {
|
|
211
225
|
return fs(d.thunk());
|
|
212
226
|
} catch {
|
|
213
|
-
|
|
214
|
-
return t2 ? fs(t2) : any();
|
|
227
|
+
return any();
|
|
215
228
|
}
|
|
229
|
+
}
|
|
216
230
|
case "choice": {
|
|
217
231
|
let out = empty();
|
|
218
232
|
for (const arm of d.parsers) out = union(out, fs(arm));
|
|
@@ -7042,7 +7056,7 @@ var Encoder = class {
|
|
|
7042
7056
|
d.tags === void 0 ? -1 : this.constant(d.tags)
|
|
7043
7057
|
);
|
|
7044
7058
|
if (matchesEmpty(d.parser)) return body;
|
|
7045
|
-
const fs = d.parser._meta.firstSet;
|
|
7059
|
+
const fs = d.parser._def.tag === "lazy" ? firstSetOf(d.parser, /* @__PURE__ */ new Set(), this.refResolver()) : d.parser._meta.firstSet;
|
|
7046
7060
|
if (fs.kind === "any") return body;
|
|
7047
7061
|
const cls = this.charClass(fs);
|
|
7048
7062
|
if (cls < 0) return body;
|
|
@@ -7156,7 +7170,7 @@ var Encoder = class {
|
|
|
7156
7170
|
case "attempt": {
|
|
7157
7171
|
const inner = this.emit(OP_ATTEMPT, this.node(d.parser).ip);
|
|
7158
7172
|
if (!this.failureNeedsRollback(d.parser, void 0)) this.failureRollbackCleanSites.add(inner);
|
|
7159
|
-
const fs = d.parser._meta.firstSet;
|
|
7173
|
+
const fs = d.parser._def.tag === "lazy" ? firstSetOf(d.parser, /* @__PURE__ */ new Set(), this.refResolver()) : d.parser._meta.firstSet;
|
|
7160
7174
|
if (fs.kind === "any" || matchesEmpty(d.parser)) return inner;
|
|
7161
7175
|
const cls = this.charClass(fs);
|
|
7162
7176
|
if (cls < 0) return inner;
|