parseman 0.50.5 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/table/encode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,UAAU,EAAuB,MAAM,aAAa,CAAA;AAwBhF,OAAO,KAAK,EAAmE,YAAY,EAAc,MAAM,cAAc,CAAA;AAS7H,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AA0B9E,8EAA8E;AAC9E,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,YAAY,GAAG,EAAE,MAAM,EAAqE;CAC7F;AAED,8EAA8E;AAC9E,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;IACjC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;IAC7B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAA;CACxC,CAAA;AAutDD,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC5C,QAAQ,GAAE,aAAkB,GAC3B,YAAY,CAEd;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC5C,QAAQ,GAAE,aAAkB,GAC3B;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAA;CAAE,CA+BnD"}
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/table/encode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,UAAU,EAAuB,MAAM,aAAa,CAAA;AAwBhF,OAAO,KAAK,EAAmE,YAAY,EAAc,MAAM,cAAc,CAAA;AAS7H,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAA;AA0B9E,8EAA8E;AAC9E,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,YAAY,GAAG,EAAE,MAAM,EAAqE;CAC7F;AAED,8EAA8E;AAC9E,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,GAAG,KAAK,CAAA;IACjC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;IAC7B;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAC3B;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,mBAAmB,CAAA;CACxC,CAAA;AAytDD,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC5C,QAAQ,GAAE,aAAkB,GAC3B,YAAY,CAEd;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC,EAC5C,QAAQ,GAAE,aAAkB,GAC3B;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,MAAM,EAAE,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,CAAA;CAAE,CA+BnD"}
@@ -1,12 +1,12 @@
1
1
  // src/combinators/first-set.ts
2
- function classifyFinalChoice(arms, resolve) {
2
+ function classifyFinalChoice(arms, resolve, activeTrivia) {
3
3
  const firstSets = [];
4
4
  const nullable2 = [];
5
5
  let exclusive = true;
6
6
  for (const arm of arms) {
7
7
  const empty2 = matchesEmpty(arm, /* @__PURE__ */ new Set(), resolve);
8
8
  nullable2.push(empty2);
9
- firstSets.push(empty2 ? { kind: "any" } : firstSetOf(arm, /* @__PURE__ */ new Set(), resolve));
9
+ firstSets.push(empty2 ? { kind: "any" } : firstSetOf(arm, /* @__PURE__ */ new Set(), resolve, activeTrivia));
10
10
  if (empty2) exclusive = false;
11
11
  }
12
12
  if (exclusive) {
@@ -67,7 +67,7 @@ function intersects(a, b) {
67
67
  return false;
68
68
  }
69
69
  function fromChar(code) {
70
- return { kind: "ranges", ranges: [{ lo: code, hi: code }] };
70
+ return fromRange(code, code);
71
71
  }
72
72
  function startsFirstSet(combinator, input, pos) {
73
73
  const fs = combinator._meta.firstSet;
@@ -160,11 +160,10 @@ function matchesEmptyBody(p, seen, resolve) {
160
160
  }
161
161
  }
162
162
  function isZeroWidthAssertion(p) {
163
- const tag = p._def.tag;
164
- return tag === "not" || tag === "adjacency";
163
+ return p._tag === "not" || p._tag === "adjacency";
165
164
  }
166
165
  function isPositiveLookahead(p) {
167
- return p._def.tag === "peek";
166
+ return p._tag === "peek";
168
167
  }
169
168
  function narrowBy(acc, constraint) {
170
169
  if (constraint.kind === "any") return acc;
@@ -180,34 +179,42 @@ function narrowBy(acc, constraint) {
180
179
  return ranges.length === 0 ? { kind: "empty" } : { kind: "ranges", ranges };
181
180
  }
182
181
  function applyAssertion(fs, assertion) {
183
- if (assertion === null) return fs;
184
- if (fs.kind === "empty") return assertion;
185
- return narrowBy(fs, assertion) ?? fs;
182
+ return assertion === null ? fs : fs.kind === "empty" ? assertion : narrowBy(fs, assertion);
186
183
  }
187
- function sequenceFirstSet(parsers) {
188
- let fs = empty();
189
- let assertion = null;
190
- for (const p of parsers) {
184
+ function sequenceSet(parsers, fs, empties, trivia2) {
185
+ const afterBoundary = (i) => {
186
+ const rest = at(i);
187
+ return trivia2 ? union(rest, fs(trivia2)) : rest;
188
+ };
189
+ const at = (i) => {
190
+ const p = parsers[i];
191
191
  if (isPositiveLookahead(p)) {
192
- assertion = narrowBy(assertion, p._meta.firstSet);
193
- continue;
192
+ const constraint = fs(p);
193
+ return i + 1 === parsers.length ? constraint : applyAssertion(afterBoundary(i + 1), constraint);
194
194
  }
195
- if (!isZeroWidthAssertion(p)) fs = union(fs, p._meta.firstSet);
196
- if (!matchesEmpty(p)) return applyAssertion(fs, assertion);
197
- }
198
- return applyAssertion(fs, assertion);
195
+ if (isZeroWidthAssertion(p)) {
196
+ return i + 1 === parsers.length ? empty() : afterBoundary(i + 1);
197
+ }
198
+ const first = fs(p);
199
+ if (!empties(p) || i + 1 === parsers.length) return first;
200
+ return union(first, afterBoundary(i + 1));
201
+ };
202
+ return at(0);
203
+ }
204
+ function sequenceFirstSet(parsers) {
205
+ return sequenceSet(parsers, (p) => p._meta.firstSet, matchesEmpty);
199
206
  }
200
- function firstSetOf(p, seen = /* @__PURE__ */ new Set(), resolve) {
207
+ function firstSetOf(p, seen = /* @__PURE__ */ new Set(), resolve, activeTrivia) {
201
208
  if (seen.has(p)) return any();
202
209
  seen.add(p);
203
210
  try {
204
- return firstSetBody(p, seen, resolve);
211
+ return firstSetBody(p, seen, resolve, activeTrivia);
205
212
  } finally {
206
213
  seen.delete(p);
207
214
  }
208
215
  }
209
- function firstSetBody(p, seen, resolve) {
210
- const fs = (c) => firstSetOf(c, seen, resolve);
216
+ function firstSetBody(p, seen, resolve, activeTrivia) {
217
+ const fs = (c) => firstSetOf(c, seen, resolve, activeTrivia);
211
218
  const empties = (c) => matchesEmpty(c, /* @__PURE__ */ new Set(), resolve);
212
219
  const d = p._def;
213
220
  switch (d.tag) {
@@ -233,17 +240,7 @@ function firstSetBody(p, seen, resolve) {
233
240
  return out;
234
241
  }
235
242
  case "sequence": {
236
- let out = empty();
237
- let assertion = null;
238
- for (const term of d.parsers) {
239
- if (isPositiveLookahead(term)) {
240
- assertion = narrowBy(assertion, fs(term));
241
- continue;
242
- }
243
- if (!isZeroWidthAssertion(term)) out = union(out, fs(term));
244
- if (!empties(term)) return applyAssertion(out, assertion);
245
- }
246
- return applyAssertion(out, assertion);
243
+ return sequenceSet(d.parsers, fs, empties, activeTrivia);
247
244
  }
248
245
  case "peek": {
249
246
  const inner = d.parser;
@@ -258,12 +255,16 @@ function firstSetBody(p, seen, resolve) {
258
255
  case "token":
259
256
  case "leaf":
260
257
  case "node":
261
- case "grammar":
262
- case "expect":
263
- return fs(d.parser);
264
258
  case "sepBy":
259
+ case "expect":
265
260
  return fs(d.parser);
266
- // both min 0 and min 1 start with the item
261
+ case "grammar":
262
+ return firstSetOf(
263
+ d.parser,
264
+ seen,
265
+ resolve,
266
+ d.clearTrivia ? null : d.triviaParser ?? activeTrivia
267
+ );
267
268
  default:
268
269
  return p._meta.firstSet;
269
270
  }
@@ -12471,7 +12472,9 @@ var Encoder = class {
12471
12472
  followClass(parsers, i) {
12472
12473
  let fs = { kind: "empty" };
12473
12474
  const rr = this.refResolver();
12474
- for (let j = i + 1; j < parsers.length; j++) fs = union(fs, firstSetOf(parsers[j], /* @__PURE__ */ new Set(), rr));
12475
+ for (let j = i + 1; j < parsers.length; j++) {
12476
+ fs = union(fs, firstSetOf(parsers[j], /* @__PURE__ */ new Set(), rr, this.activeTrivia));
12477
+ }
12475
12478
  return this.charClass(fs);
12476
12479
  }
12477
12480
  constant(v) {
@@ -12688,7 +12691,7 @@ var Encoder = class {
12688
12691
  */
12689
12692
  subtree(c) {
12690
12693
  const ip = this.node(c).ip;
12691
- const fs = firstSetOf(c, /* @__PURE__ */ new Set(), this.refResolver());
12694
+ const fs = firstSetOf(c, /* @__PURE__ */ new Set(), this.refResolver(), this.activeTrivia);
12692
12695
  return [ip, fs.kind === "empty" ? -2 : this.charClass(fs)];
12693
12696
  }
12694
12697
  /** Pool one scan spec. One per combinator: `node()` memoizes by identity. */
@@ -12907,12 +12910,12 @@ var Encoder = class {
12907
12910
  return this.covWrap(gated, armCovIds?.[src], 1);
12908
12911
  });
12909
12912
  const rr = this.refResolver();
12910
- const finalChoice = classifyFinalChoice(arms, rr);
12913
+ const finalChoice = classifyFinalChoice(arms, rr, this.activeTrivia);
12911
12914
  const transactionalFirst = arms.map((arm, i) => {
12912
12915
  if (!finalChoice.nullable[i]) return void 0;
12913
12916
  const def = arm._def;
12914
12917
  if (def.tag !== "attempt" || matchesEmpty(def.parser, /* @__PURE__ */ new Set(), rr)) return void 0;
12915
- return firstSetOf(def.parser, /* @__PURE__ */ new Set(), rr);
12918
+ return firstSetOf(def.parser, /* @__PURE__ */ new Set(), rr, this.activeTrivia);
12916
12919
  });
12917
12920
  const gateFirst = finalChoice.firstSets.map((first, i) => transactionalFirst[i] ?? first);
12918
12921
  const classes = gateFirst.map((first, i) => finalChoice.nullable[i] && transactionalFirst[i] === void 0 ? -1 : this.charClass(first));
@@ -12959,7 +12962,7 @@ var Encoder = class {
12959
12962
  case "oneOrMore": {
12960
12963
  const child = this.node(d.parser).ip;
12961
12964
  const rr = this.refResolver();
12962
- const itemClass = matchesEmpty(d.parser, /* @__PURE__ */ new Set(), rr) ? -1 : this.existingCharClass(firstSetOf(d.parser, /* @__PURE__ */ new Set(), rr));
12965
+ const itemClass = matchesEmpty(d.parser, /* @__PURE__ */ new Set(), rr) ? -1 : this.existingCharClass(firstSetOf(d.parser, /* @__PURE__ */ new Set(), rr, this.activeTrivia));
12963
12966
  const op = d.valueUnused ? OP_REPV : OP_REP;
12964
12967
  const min = d.tag === "many" ? 0 : d.min;
12965
12968
  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);
@@ -12977,7 +12980,7 @@ var Encoder = class {
12977
12980
  sep,
12978
12981
  flags,
12979
12982
  this.expected(deriveExpected(d.parser)),
12980
- this.charClass(firstSetOf(d.separator, /* @__PURE__ */ new Set(), this.refResolver()))
12983
+ this.charClass(firstSetOf(d.separator, /* @__PURE__ */ new Set(), this.refResolver(), this.activeTrivia))
12981
12984
  );
12982
12985
  }
12983
12986
  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);
@@ -13032,7 +13035,7 @@ var Encoder = class {
13032
13035
  d.tags === void 0 ? -1 : this.constant(d.tags)
13033
13036
  );
13034
13037
  if (matchesEmpty(d.parser)) return body;
13035
- const fs = d.parser._def.tag === "lazy" ? firstSetOf(d.parser, /* @__PURE__ */ new Set(), this.refResolver()) : d.parser._meta.firstSet;
13038
+ const fs = d.parser._def.tag === "lazy" ? firstSetOf(d.parser, /* @__PURE__ */ new Set(), this.refResolver(), this.activeTrivia) : d.parser._meta.firstSet;
13036
13039
  if (fs.kind === "any") return body;
13037
13040
  const cls = this.charClass(fs);
13038
13041
  if (cls < 0) return body;
@@ -13146,7 +13149,7 @@ var Encoder = class {
13146
13149
  case "attempt": {
13147
13150
  const inner = this.emit(OP_ATTEMPT, this.node(d.parser).ip);
13148
13151
  if (!this.failureNeedsRollback(d.parser, void 0)) this.failureRollbackCleanSites.add(inner);
13149
- const fs = d.parser._def.tag === "lazy" ? firstSetOf(d.parser, /* @__PURE__ */ new Set(), this.refResolver()) : d.parser._meta.firstSet;
13152
+ const fs = d.parser._def.tag === "lazy" ? firstSetOf(d.parser, /* @__PURE__ */ new Set(), this.refResolver(), this.activeTrivia) : d.parser._meta.firstSet;
13150
13153
  if (fs.kind === "any" || matchesEmpty(d.parser)) return inner;
13151
13154
  const cls = this.charClass(fs);
13152
13155
  if (cls < 0) return inner;