parseman 0.50.6 → 0.50.7
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 +49 -46
- package/dist/analysis/diagnostics.js.map +2 -2
- package/dist/cli/index.js +49 -46
- package/dist/cli/index.js.map +2 -2
- package/dist/combinators/first-set.d.ts +2 -26
- package/dist/combinators/first-set.d.ts.map +1 -1
- package/dist/compiler/token-capability.js +38 -27
- package/dist/compiler/token-capability.js.map +1 -1
- package/dist/index.js +50 -47
- package/dist/index.js.map +2 -2
- package/dist/plugin/index.js +50 -47
- package/dist/plugin/index.js.map +2 -2
- package/dist/spec/index.js +37 -36
- package/dist/spec/index.js.map +2 -2
- package/dist/table/encode.d.ts.map +1 -1
- package/dist/table/index.js +49 -46
- package/dist/table/index.js.map +2 -2
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/combinators/first-set.ts +58 -36
- package/src/table/encode.ts +10 -8
- package/src/version.ts +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -7,14 +7,14 @@ import { pathToFileURL } from "node:url";
|
|
|
7
7
|
import { register } from "node:module";
|
|
8
8
|
|
|
9
9
|
// src/combinators/first-set.ts
|
|
10
|
-
function classifyFinalChoice(arms, resolve2) {
|
|
10
|
+
function classifyFinalChoice(arms, resolve2, activeTrivia) {
|
|
11
11
|
const firstSets = [];
|
|
12
12
|
const nullable2 = [];
|
|
13
13
|
let exclusive = true;
|
|
14
14
|
for (const arm of arms) {
|
|
15
15
|
const empty2 = matchesEmpty(arm, /* @__PURE__ */ new Set(), resolve2);
|
|
16
16
|
nullable2.push(empty2);
|
|
17
|
-
firstSets.push(empty2 ? { kind: "any" } : firstSetOf(arm, /* @__PURE__ */ new Set(), resolve2));
|
|
17
|
+
firstSets.push(empty2 ? { kind: "any" } : firstSetOf(arm, /* @__PURE__ */ new Set(), resolve2, activeTrivia));
|
|
18
18
|
if (empty2) exclusive = false;
|
|
19
19
|
}
|
|
20
20
|
if (exclusive) {
|
|
@@ -75,7 +75,7 @@ function intersects(a, b) {
|
|
|
75
75
|
return false;
|
|
76
76
|
}
|
|
77
77
|
function fromChar(code) {
|
|
78
|
-
return
|
|
78
|
+
return fromRange(code, code);
|
|
79
79
|
}
|
|
80
80
|
function startsFirstSet(combinator, input, pos) {
|
|
81
81
|
const fs = combinator._meta.firstSet;
|
|
@@ -168,11 +168,10 @@ function matchesEmptyBody(p, seen, resolve2) {
|
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
function isZeroWidthAssertion(p) {
|
|
171
|
-
|
|
172
|
-
return tag === "not" || tag === "adjacency";
|
|
171
|
+
return p._tag === "not" || p._tag === "adjacency";
|
|
173
172
|
}
|
|
174
173
|
function isPositiveLookahead(p) {
|
|
175
|
-
return p.
|
|
174
|
+
return p._tag === "peek";
|
|
176
175
|
}
|
|
177
176
|
function narrowBy(acc, constraint) {
|
|
178
177
|
if (constraint.kind === "any") return acc;
|
|
@@ -188,34 +187,42 @@ function narrowBy(acc, constraint) {
|
|
|
188
187
|
return ranges.length === 0 ? { kind: "empty" } : { kind: "ranges", ranges };
|
|
189
188
|
}
|
|
190
189
|
function applyAssertion(fs, assertion) {
|
|
191
|
-
|
|
192
|
-
if (fs.kind === "empty") return assertion;
|
|
193
|
-
return narrowBy(fs, assertion) ?? fs;
|
|
190
|
+
return assertion === null ? fs : fs.kind === "empty" ? assertion : narrowBy(fs, assertion);
|
|
194
191
|
}
|
|
195
|
-
function
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
192
|
+
function sequenceSet(parsers, fs, empties, trivia2) {
|
|
193
|
+
const afterBoundary = (i) => {
|
|
194
|
+
const rest = at(i);
|
|
195
|
+
return trivia2 ? union(rest, fs(trivia2)) : rest;
|
|
196
|
+
};
|
|
197
|
+
const at = (i) => {
|
|
198
|
+
const p = parsers[i];
|
|
199
199
|
if (isPositiveLookahead(p)) {
|
|
200
|
-
|
|
201
|
-
|
|
200
|
+
const constraint = fs(p);
|
|
201
|
+
return i + 1 === parsers.length ? constraint : applyAssertion(afterBoundary(i + 1), constraint);
|
|
202
202
|
}
|
|
203
|
-
if (
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
203
|
+
if (isZeroWidthAssertion(p)) {
|
|
204
|
+
return i + 1 === parsers.length ? empty() : afterBoundary(i + 1);
|
|
205
|
+
}
|
|
206
|
+
const first = fs(p);
|
|
207
|
+
if (!empties(p) || i + 1 === parsers.length) return first;
|
|
208
|
+
return union(first, afterBoundary(i + 1));
|
|
209
|
+
};
|
|
210
|
+
return at(0);
|
|
211
|
+
}
|
|
212
|
+
function sequenceFirstSet(parsers) {
|
|
213
|
+
return sequenceSet(parsers, (p) => p._meta.firstSet, matchesEmpty);
|
|
207
214
|
}
|
|
208
|
-
function firstSetOf(p, seen = /* @__PURE__ */ new Set(), resolve2) {
|
|
215
|
+
function firstSetOf(p, seen = /* @__PURE__ */ new Set(), resolve2, activeTrivia) {
|
|
209
216
|
if (seen.has(p)) return any();
|
|
210
217
|
seen.add(p);
|
|
211
218
|
try {
|
|
212
|
-
return firstSetBody(p, seen, resolve2);
|
|
219
|
+
return firstSetBody(p, seen, resolve2, activeTrivia);
|
|
213
220
|
} finally {
|
|
214
221
|
seen.delete(p);
|
|
215
222
|
}
|
|
216
223
|
}
|
|
217
|
-
function firstSetBody(p, seen, resolve2) {
|
|
218
|
-
const fs = (c) => firstSetOf(c, seen, resolve2);
|
|
224
|
+
function firstSetBody(p, seen, resolve2, activeTrivia) {
|
|
225
|
+
const fs = (c) => firstSetOf(c, seen, resolve2, activeTrivia);
|
|
219
226
|
const empties = (c) => matchesEmpty(c, /* @__PURE__ */ new Set(), resolve2);
|
|
220
227
|
const d = p._def;
|
|
221
228
|
switch (d.tag) {
|
|
@@ -241,17 +248,7 @@ function firstSetBody(p, seen, resolve2) {
|
|
|
241
248
|
return out;
|
|
242
249
|
}
|
|
243
250
|
case "sequence": {
|
|
244
|
-
|
|
245
|
-
let assertion = null;
|
|
246
|
-
for (const term of d.parsers) {
|
|
247
|
-
if (isPositiveLookahead(term)) {
|
|
248
|
-
assertion = narrowBy(assertion, fs(term));
|
|
249
|
-
continue;
|
|
250
|
-
}
|
|
251
|
-
if (!isZeroWidthAssertion(term)) out = union(out, fs(term));
|
|
252
|
-
if (!empties(term)) return applyAssertion(out, assertion);
|
|
253
|
-
}
|
|
254
|
-
return applyAssertion(out, assertion);
|
|
251
|
+
return sequenceSet(d.parsers, fs, empties, activeTrivia);
|
|
255
252
|
}
|
|
256
253
|
case "peek": {
|
|
257
254
|
const inner = d.parser;
|
|
@@ -266,12 +263,16 @@ function firstSetBody(p, seen, resolve2) {
|
|
|
266
263
|
case "token":
|
|
267
264
|
case "leaf":
|
|
268
265
|
case "node":
|
|
269
|
-
case "grammar":
|
|
270
|
-
case "expect":
|
|
271
|
-
return fs(d.parser);
|
|
272
266
|
case "sepBy":
|
|
267
|
+
case "expect":
|
|
273
268
|
return fs(d.parser);
|
|
274
|
-
|
|
269
|
+
case "grammar":
|
|
270
|
+
return firstSetOf(
|
|
271
|
+
d.parser,
|
|
272
|
+
seen,
|
|
273
|
+
resolve2,
|
|
274
|
+
d.clearTrivia ? null : d.triviaParser ?? activeTrivia
|
|
275
|
+
);
|
|
275
276
|
default:
|
|
276
277
|
return p._meta.firstSet;
|
|
277
278
|
}
|
|
@@ -7659,7 +7660,9 @@ var Encoder = class {
|
|
|
7659
7660
|
followClass(parsers, i) {
|
|
7660
7661
|
let fs = { kind: "empty" };
|
|
7661
7662
|
const rr = this.refResolver();
|
|
7662
|
-
for (let j = i + 1; j < parsers.length; j++)
|
|
7663
|
+
for (let j = i + 1; j < parsers.length; j++) {
|
|
7664
|
+
fs = union(fs, firstSetOf(parsers[j], /* @__PURE__ */ new Set(), rr, this.activeTrivia));
|
|
7665
|
+
}
|
|
7663
7666
|
return this.charClass(fs);
|
|
7664
7667
|
}
|
|
7665
7668
|
constant(v) {
|
|
@@ -7876,7 +7879,7 @@ var Encoder = class {
|
|
|
7876
7879
|
*/
|
|
7877
7880
|
subtree(c) {
|
|
7878
7881
|
const ip = this.node(c).ip;
|
|
7879
|
-
const fs = firstSetOf(c, /* @__PURE__ */ new Set(), this.refResolver());
|
|
7882
|
+
const fs = firstSetOf(c, /* @__PURE__ */ new Set(), this.refResolver(), this.activeTrivia);
|
|
7880
7883
|
return [ip, fs.kind === "empty" ? -2 : this.charClass(fs)];
|
|
7881
7884
|
}
|
|
7882
7885
|
/** Pool one scan spec. One per combinator: `node()` memoizes by identity. */
|
|
@@ -8095,12 +8098,12 @@ var Encoder = class {
|
|
|
8095
8098
|
return this.covWrap(gated, armCovIds?.[src], 1);
|
|
8096
8099
|
});
|
|
8097
8100
|
const rr = this.refResolver();
|
|
8098
|
-
const finalChoice = classifyFinalChoice(arms, rr);
|
|
8101
|
+
const finalChoice = classifyFinalChoice(arms, rr, this.activeTrivia);
|
|
8099
8102
|
const transactionalFirst = arms.map((arm, i) => {
|
|
8100
8103
|
if (!finalChoice.nullable[i]) return void 0;
|
|
8101
8104
|
const def = arm._def;
|
|
8102
8105
|
if (def.tag !== "attempt" || matchesEmpty(def.parser, /* @__PURE__ */ new Set(), rr)) return void 0;
|
|
8103
|
-
return firstSetOf(def.parser, /* @__PURE__ */ new Set(), rr);
|
|
8106
|
+
return firstSetOf(def.parser, /* @__PURE__ */ new Set(), rr, this.activeTrivia);
|
|
8104
8107
|
});
|
|
8105
8108
|
const gateFirst = finalChoice.firstSets.map((first, i) => transactionalFirst[i] ?? first);
|
|
8106
8109
|
const classes = gateFirst.map((first, i) => finalChoice.nullable[i] && transactionalFirst[i] === void 0 ? -1 : this.charClass(first));
|
|
@@ -8147,7 +8150,7 @@ var Encoder = class {
|
|
|
8147
8150
|
case "oneOrMore": {
|
|
8148
8151
|
const child = this.node(d.parser).ip;
|
|
8149
8152
|
const rr = this.refResolver();
|
|
8150
|
-
const itemClass = matchesEmpty(d.parser, /* @__PURE__ */ new Set(), rr) ? -1 : this.existingCharClass(firstSetOf(d.parser, /* @__PURE__ */ new Set(), rr));
|
|
8153
|
+
const itemClass = matchesEmpty(d.parser, /* @__PURE__ */ new Set(), rr) ? -1 : this.existingCharClass(firstSetOf(d.parser, /* @__PURE__ */ new Set(), rr, this.activeTrivia));
|
|
8151
8154
|
const op = d.valueUnused ? OP_REPV : OP_REP;
|
|
8152
8155
|
const min = d.tag === "many" ? 0 : d.min;
|
|
8153
8156
|
return this.rec ? this.emit(op, child, min, d.max ?? -1, -1, 0, this.expected(deriveExpected(d.parser)), itemClass) : this.emit(op, child, min, d.max ?? -1, -1, 0);
|
|
@@ -8165,7 +8168,7 @@ var Encoder = class {
|
|
|
8165
8168
|
sep,
|
|
8166
8169
|
flags,
|
|
8167
8170
|
this.expected(deriveExpected(d.parser)),
|
|
8168
|
-
this.charClass(firstSetOf(d.separator, /* @__PURE__ */ new Set(), this.refResolver()))
|
|
8171
|
+
this.charClass(firstSetOf(d.separator, /* @__PURE__ */ new Set(), this.refResolver(), this.activeTrivia))
|
|
8169
8172
|
);
|
|
8170
8173
|
}
|
|
8171
8174
|
return d.min >= 2 ? this.emit(OP_REP, child, d.min, d.max ?? -1, sep, flags, this.expected(deriveExpected(d.parser))) : this.emit(OP_REP, child, d.min, d.max ?? -1, sep, flags);
|
|
@@ -8220,7 +8223,7 @@ var Encoder = class {
|
|
|
8220
8223
|
d.tags === void 0 ? -1 : this.constant(d.tags)
|
|
8221
8224
|
);
|
|
8222
8225
|
if (matchesEmpty(d.parser)) return body;
|
|
8223
|
-
const fs = d.parser._def.tag === "lazy" ? firstSetOf(d.parser, /* @__PURE__ */ new Set(), this.refResolver()) : d.parser._meta.firstSet;
|
|
8226
|
+
const fs = d.parser._def.tag === "lazy" ? firstSetOf(d.parser, /* @__PURE__ */ new Set(), this.refResolver(), this.activeTrivia) : d.parser._meta.firstSet;
|
|
8224
8227
|
if (fs.kind === "any") return body;
|
|
8225
8228
|
const cls = this.charClass(fs);
|
|
8226
8229
|
if (cls < 0) return body;
|
|
@@ -8334,7 +8337,7 @@ var Encoder = class {
|
|
|
8334
8337
|
case "attempt": {
|
|
8335
8338
|
const inner = this.emit(OP_ATTEMPT, this.node(d.parser).ip);
|
|
8336
8339
|
if (!this.failureNeedsRollback(d.parser, void 0)) this.failureRollbackCleanSites.add(inner);
|
|
8337
|
-
const fs = d.parser._def.tag === "lazy" ? firstSetOf(d.parser, /* @__PURE__ */ new Set(), this.refResolver()) : d.parser._meta.firstSet;
|
|
8340
|
+
const fs = d.parser._def.tag === "lazy" ? firstSetOf(d.parser, /* @__PURE__ */ new Set(), this.refResolver(), this.activeTrivia) : d.parser._meta.firstSet;
|
|
8338
8341
|
if (fs.kind === "any" || matchesEmpty(d.parser)) return inner;
|
|
8339
8342
|
const cls = this.charClass(fs);
|
|
8340
8343
|
if (cls < 0) return inner;
|