parseman 0.17.0 → 0.18.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.
@@ -1 +1 @@
1
- {"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../src/plugin/evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EACV,UAAU,EAAE,IAAI,EAMjB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAa7C,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,CAAA;IAC1B,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB,CAAA;AACD,MAAM,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;AAM3C,KAAK,gBAAgB,GAAG;IAAE,GAAG,EAAE,aAAa,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAA;AA2VhE,0EAA0E;AAC1E,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,KAAK,EACZ,IAAI,CAAC,EAAE,MAAM,GACZ,gBAAgB,GAAG,IAAI,CAUzB;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAC1B,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,KAAK,EACZ,IAAI,CAAC,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,MAAM,EAAE,GACtB,UAAU,CAAC,OAAO,CAAC,GAAG,IAAI,CAE5B;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,KAAK,EACZ,IAAI,CAAC,EAAE,MAAM,GACZ,UAAU,CAAC,OAAO,CAAC,EAAE,GAAG,IAAI,CAM9B;AAiED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,UAA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C,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAcnF"}
@@ -100,6 +100,7 @@ function matchesEmpty(p, seen = /* @__PURE__ */ new Set()) {
100
100
  case "transform":
101
101
  case "label":
102
102
  case "trivia":
103
+ case "token":
103
104
  case "expect":
104
105
  case "withCtx":
105
106
  case "node":
@@ -162,6 +163,7 @@ function firstSetOf(p, seen = /* @__PURE__ */ new Set()) {
162
163
  case "transform":
163
164
  case "label":
164
165
  case "trivia":
166
+ case "token":
165
167
  case "node":
166
168
  case "grammar":
167
169
  case "expect":
@@ -1285,6 +1287,7 @@ function markUnusedValues(root) {
1285
1287
  return;
1286
1288
  case "label":
1287
1289
  case "trivia":
1290
+ case "token":
1288
1291
  case "withCtx":
1289
1292
  case "expect":
1290
1293
  visit(def.parser, consumed);
@@ -1562,8 +1565,60 @@ function noTrivia(root) {
1562
1565
  return parser({ trivia: null }, root);
1563
1566
  }
1564
1567
 
1568
+ // src/combinators/token.ts
1569
+ function token(root) {
1570
+ const meta = {
1571
+ firstSet: root._meta.firstSet,
1572
+ canMatchNewline: root._meta.canMatchNewline,
1573
+ isTrivia: false
1574
+ };
1575
+ return {
1576
+ _tag: "token",
1577
+ _meta: meta,
1578
+ _def: { tag: "token", parser: root },
1579
+ parse(input, pos, ctx) {
1580
+ const savedTrivia = ctx.trivia;
1581
+ const savedKinds = ctx.triviaKindLabels;
1582
+ const savedBuf = ctx._cstBuf;
1583
+ const savedChildren = ctx._cstChildren;
1584
+ const savedLeaves = ctx._cstLeaves;
1585
+ const savedRaw = ctx._cstRawChildren;
1586
+ const savedTriviaLog = ctx._cstTriviaLog;
1587
+ const savedOuterTriviaLog = ctx._triviaLog;
1588
+ const wasCapturing = cstCaptureActive(ctx);
1589
+ ctx.trivia = void 0;
1590
+ ctx.triviaKindLabels = void 0;
1591
+ ctx._cstBuf = void 0;
1592
+ ctx._cstChildren = void 0;
1593
+ ctx._cstLeaves = void 0;
1594
+ ctx._cstRawChildren = void 0;
1595
+ ctx._cstTriviaLog = void 0;
1596
+ delete ctx._triviaLog;
1597
+ let result;
1598
+ try {
1599
+ result = root.parse(input, pos, ctx);
1600
+ } finally {
1601
+ ctx.trivia = savedTrivia;
1602
+ ctx.triviaKindLabels = savedKinds;
1603
+ ctx._cstBuf = savedBuf;
1604
+ ctx._cstChildren = savedChildren;
1605
+ ctx._cstLeaves = savedLeaves;
1606
+ ctx._cstRawChildren = savedRaw;
1607
+ ctx._cstTriviaLog = savedTriviaLog;
1608
+ if (savedOuterTriviaLog === void 0) delete ctx._triviaLog;
1609
+ else ctx._triviaLog = savedOuterTriviaLog;
1610
+ }
1611
+ if (!result.ok) return result;
1612
+ const span = result.span;
1613
+ const value = input.slice(pos, span.end);
1614
+ if (wasCapturing) pushCstLeaf(ctx, { _tag: "leaf", value, span });
1615
+ return { ok: true, value, span };
1616
+ }
1617
+ };
1618
+ }
1619
+
1565
1620
  // src/combinators/expect.ts
1566
- function staticExpected(c) {
1621
+ function deriveExpected(c) {
1567
1622
  const def = c._def;
1568
1623
  switch (def.tag) {
1569
1624
  case "literal":
@@ -1575,22 +1630,23 @@ function staticExpected(c) {
1575
1630
  case "label":
1576
1631
  return [def.label];
1577
1632
  case "choice":
1578
- return def.parsers.flatMap(staticExpected);
1633
+ return def.parsers.flatMap(deriveExpected);
1579
1634
  case "sequence":
1580
- return def.parsers.length > 0 ? staticExpected(def.parsers[0]) : [];
1635
+ return def.parsers.length > 0 ? deriveExpected(def.parsers[0]) : [];
1581
1636
  case "node":
1582
1637
  case "grammar":
1583
1638
  case "trivia":
1639
+ case "token":
1584
1640
  case "optional":
1585
1641
  case "many":
1586
1642
  case "oneOrMore":
1587
1643
  case "transform":
1588
1644
  case "not":
1589
- return staticExpected(def.parser);
1645
+ return deriveExpected(def.parser);
1590
1646
  case "lazy": {
1591
1647
  const name = c._ruleName;
1592
1648
  try {
1593
- return staticExpected(def.thunk());
1649
+ return deriveExpected(def.thunk());
1594
1650
  } catch {
1595
1651
  return name ? [name] : [];
1596
1652
  }
@@ -1600,7 +1656,7 @@ function staticExpected(c) {
1600
1656
  }
1601
1657
  }
1602
1658
  function expect(combinator, label2) {
1603
- const expected = label2 !== void 0 ? [label2] : staticExpected(combinator);
1659
+ const expected = label2 !== void 0 ? [label2] : deriveExpected(combinator);
1604
1660
  const meta = {
1605
1661
  firstSet: combinator._meta.firstSet,
1606
1662
  canMatchNewline: combinator._meta.canMatchNewline,
@@ -3260,6 +3316,7 @@ function mayLeavePartialCapture(p, seen = /* @__PURE__ */ new Set()) {
3260
3316
  case "guard":
3261
3317
  case "not":
3262
3318
  case "trivia":
3319
+ case "token":
3263
3320
  case "scanTo":
3264
3321
  case "unknown":
3265
3322
  return false;
@@ -3321,6 +3378,7 @@ function capturesLeaf(p, seen = /* @__PURE__ */ new Set()) {
3321
3378
  case "regex":
3322
3379
  case "keywords":
3323
3380
  case "node":
3381
+ case "token":
3324
3382
  return true;
3325
3383
  case "not":
3326
3384
  case "guard":
@@ -3599,9 +3657,9 @@ function emitSeq(def, ctx, pos) {
3599
3657
  stmts.push(`${ind(ctx)}const ${arrV} = [${valueVars.join(", ")}]`);
3600
3658
  return { stmts, valueVar: arrV, endVar };
3601
3659
  }
3602
- function staticExpectedArr(parsers) {
3660
+ function deriveExpectedArr(parsers) {
3603
3661
  return JSON.stringify(parsers.flatMap((p) => {
3604
- const e = staticExpected(p);
3662
+ const e = deriveExpected(p);
3605
3663
  return e.length > 0 ? e : [p._tag];
3606
3664
  }));
3607
3665
  }
@@ -3622,7 +3680,7 @@ function failsAtStart(p) {
3622
3680
  }
3623
3681
  }
3624
3682
  function armStaticExpected(ctx, p) {
3625
- return hoistExpected(ctx, staticExpectedArr([p]));
3683
+ return hoistExpected(ctx, deriveExpectedArr([p]));
3626
3684
  }
3627
3685
  function canMatchEmptyAtStart(p) {
3628
3686
  const d = p._def;
@@ -3660,7 +3718,7 @@ function emitDisjointArm(p, ctx, pos, valV, endV) {
3660
3718
  ];
3661
3719
  }
3662
3720
  function emitChoice(def, ctx, pos) {
3663
- const allExpected = staticExpectedArr(def.parsers);
3721
+ const allExpected = deriveExpectedArr(def.parsers);
3664
3722
  if (def.disjoint) {
3665
3723
  const codeV = v(ctx, "_code");
3666
3724
  const valV = v(ctx, "_chv");
@@ -3721,7 +3779,7 @@ function emitGreedyClassify(def, superIndex, ctx, pos) {
3721
3779
  const wordV = v(ctx, "_gw");
3722
3780
  const endV = v(ctx, "_ge");
3723
3781
  const valV = v(ctx, "_gcv");
3724
- const regexExpected = JSON.stringify(staticExpected(superParser));
3782
+ const regexExpected = JSON.stringify(deriveExpected(superParser));
3725
3783
  const stmts = [
3726
3784
  `${ind(ctx)}${reVar}.lastIndex = ${pos}`,
3727
3785
  `${ind(ctx)}const ${matchV} = ${reVar}.exec(input)`,
@@ -4113,6 +4171,116 @@ function emitNot(def, ctx, pos) {
4113
4171
  endVar: pos
4114
4172
  };
4115
4173
  }
4174
+ function escapeTokenLiteral(value) {
4175
+ return value.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
4176
+ }
4177
+ function regexMatchesEmpty(source, flags) {
4178
+ try {
4179
+ return new RegExp(`^(?:${source})$`, flags).test("");
4180
+ } catch {
4181
+ return true;
4182
+ }
4183
+ }
4184
+ function tokenTerminalSource(p) {
4185
+ const def = p._def;
4186
+ switch (def.tag) {
4187
+ case "literal":
4188
+ if (def.value.length === 0) return null;
4189
+ return {
4190
+ source: escapeTokenLiteral(def.value),
4191
+ caseInsensitive: def.caseInsensitive,
4192
+ rawCaseSensitive: def.caseInsensitive ? "" : def.value
4193
+ };
4194
+ case "regex": {
4195
+ if (def.flags.replace(/i/g, "") !== "") return null;
4196
+ if (regexMatchesEmpty(def.source, def.flags)) return null;
4197
+ return {
4198
+ source: `(?:${def.source})`,
4199
+ caseInsensitive: def.flags.includes("i"),
4200
+ rawCaseSensitive: def.flags.includes("i") ? "" : def.source
4201
+ };
4202
+ }
4203
+ default:
4204
+ return null;
4205
+ }
4206
+ }
4207
+ function tokenSequenceSource(p) {
4208
+ const def = p._def;
4209
+ const parts = def.tag === "sequence" ? def.parsers.map(tokenTerminalSource) : [tokenTerminalSource(p)];
4210
+ if (parts.some((part) => part === null)) return null;
4211
+ const typed = parts;
4212
+ const flags = typed.some((part) => part.caseInsensitive) ? "i" : "";
4213
+ if (flags.includes("i") && typed.some((part) => /[A-Za-z]/.test(part.rawCaseSensitive))) return null;
4214
+ return {
4215
+ source: typed.map((part) => part.source).join(""),
4216
+ flags,
4217
+ hasCaseSensitiveLetters: typed.some((part) => /[A-Za-z]/.test(part.rawCaseSensitive))
4218
+ };
4219
+ }
4220
+ function combineTokenRegexSources(parts) {
4221
+ const flags = parts.some((part) => part.flags.includes("i")) ? "i" : "";
4222
+ if (flags.includes("i") && parts.some((part) => part.flags === "" && part.hasCaseSensitiveLetters)) return null;
4223
+ return { source: parts.map((part) => part.source).join(""), flags };
4224
+ }
4225
+ function tokenNullableRegex(def) {
4226
+ const inner = def.parser._def;
4227
+ if (inner.tag === "many") {
4228
+ const seq = tokenSequenceSource(inner.parser);
4229
+ if (!seq) return null;
4230
+ return { tag: "regex", source: `(?:${seq.source})*`, flags: seq.flags };
4231
+ }
4232
+ if (inner.tag === "optional") {
4233
+ const seq = tokenSequenceSource(inner.parser);
4234
+ if (!seq) return null;
4235
+ return { tag: "regex", source: `(?:${seq.source})?`, flags: seq.flags };
4236
+ }
4237
+ if (inner.tag === "sepBy") {
4238
+ const item = tokenSequenceSource(inner.parser);
4239
+ const sep = tokenSequenceSource(inner.separator);
4240
+ if (!item || !sep) return null;
4241
+ const combined = combineTokenRegexSources([item, sep]);
4242
+ if (!combined) return null;
4243
+ return { tag: "regex", source: `(?:${item.source}(?:${sep.source}${item.source})*)?`, flags: combined.flags };
4244
+ }
4245
+ return null;
4246
+ }
4247
+ function emitToken(def, ctx, pos) {
4248
+ const lowered = tokenNullableRegex(def);
4249
+ if (lowered) return emitRegex(lowered, ctx, pos);
4250
+ const savedTrivia = ctx.activeTrivia;
4251
+ const savedKindLabels = ctx.triviaKindLabels;
4252
+ ctx.activeTrivia = void 0;
4253
+ ctx.triviaKindLabels = void 0;
4254
+ const inner = emitFallible(def.parser, ctx, pos);
4255
+ ctx.activeTrivia = savedTrivia;
4256
+ ctx.triviaKindLabels = savedKindLabels;
4257
+ const i = ind(ctx);
4258
+ const sc = v(ctx, "_tokCh");
4259
+ const sl = v(ctx, "_tokLv");
4260
+ const sr = v(ctx, "_tokRaw");
4261
+ const sv = v(ctx, "_tokTr");
4262
+ const sk = v(ctx, "_tokKinds");
4263
+ const stl = v(ctx, "_tokTl");
4264
+ const sol = v(ctx, "_tokLog");
4265
+ const sb = v(ctx, "_tokBuf");
4266
+ const valV = v(ctx, "_tok");
4267
+ return {
4268
+ stmts: [
4269
+ `${i}const ${sc} = _ctx._cstChildren, ${sl} = _ctx._cstLeaves, ${sr} = _ctx._cstRawChildren, ${sv} = _ctx.trivia, ${sk} = _ctx.triviaKindLabels, ${stl} = _ctx._cstTriviaLog, ${sol} = _ctx._triviaLog, ${sb} = _ctx._cstBuf`,
4270
+ `${i}_ctx.trivia = undefined; _ctx.triviaKindLabels = undefined; _ctx._cstChildren = undefined; _ctx._cstLeaves = undefined; _ctx._cstRawChildren = undefined; _ctx._cstTriviaLog = undefined; _ctx._triviaLog = undefined; _ctx._cstBuf = undefined`,
4271
+ `${i}try {`,
4272
+ ...reindentStmts(inner.stmts, ctx.indent + 1).map((stmt) => stmt.replace(/^(\s*)(?:const|let)\s+/, "$1var ")),
4273
+ `${i}} finally {`,
4274
+ `${i} _ctx.trivia = ${sv}; _ctx.triviaKindLabels = ${sk}; _ctx._cstChildren = ${sc}; _ctx._cstLeaves = ${sl}; _ctx._cstRawChildren = ${sr}; _ctx._cstTriviaLog = ${stl}; _ctx._triviaLog = ${sol}; _ctx._cstBuf = ${sb}`,
4275
+ `${i}}`,
4276
+ ...emitIfFail(ctx, `!${inner.okVar}`, propagateFailBody(ctx)),
4277
+ `${i}const ${valV} = input.slice(${pos}, ${inner.endVar})`,
4278
+ ...emitLeafCapture(ctx, valV, pos, inner.endVar)
4279
+ ],
4280
+ valueVar: valV,
4281
+ endVar: inner.endVar
4282
+ };
4283
+ }
4116
4284
  function emitNode(def, ctx, pos) {
4117
4285
  const structural = def.build === void 0;
4118
4286
  const mkType = structural ? null : analyzeMkInlineBuild(def);
@@ -4232,7 +4400,7 @@ function emitRecover(def, ctx, pos) {
4232
4400
  `${ind0} if (${sentOk}) break`,
4233
4401
  `${ind0} ${scanV}++`,
4234
4402
  `${ind0} }`,
4235
- `${ind0} const ${errV} = { _tag: 'parseError', span: { start: ${pos}, end: ${scanV} }, expected: ${JSON.stringify(staticExpected(def.parser))} }`,
4403
+ `${ind0} const ${errV} = { _tag: 'parseError', span: { start: ${pos}, end: ${scanV} }, expected: ${JSON.stringify(deriveExpected(def.parser))} }`,
4236
4404
  `${ind0} if (_ctx._errors) _ctx._errors.push(${errV})`,
4237
4405
  `${ind0} ${valVar} = ${errV}`,
4238
4406
  `${ind0} ${endVar} = ${scanV}`,
@@ -4362,6 +4530,8 @@ function emitDispatch(p, ctx, pos) {
4362
4530
  return emitLazy(p, def, ctx, pos);
4363
4531
  case "trivia":
4364
4532
  return emit(def.parser, ctx, pos);
4533
+ case "token":
4534
+ return emitToken(def, ctx, pos);
4365
4535
  case "label":
4366
4536
  return emit(def.parser, ctx, pos);
4367
4537
  case "grammar": {
@@ -4463,6 +4633,7 @@ function hasNodeDef(p, seen = /* @__PURE__ */ new Set()) {
4463
4633
  }
4464
4634
  case "grammar":
4465
4635
  case "trivia":
4636
+ case "token":
4466
4637
  case "label":
4467
4638
  case "optional":
4468
4639
  case "many":
@@ -4498,6 +4669,7 @@ function childrenOf(def) {
4498
4669
  case "optional":
4499
4670
  case "transform":
4500
4671
  case "trivia":
4672
+ case "token":
4501
4673
  case "label":
4502
4674
  case "grammar":
4503
4675
  case "not":
@@ -5081,7 +5253,7 @@ function balanced(open, close, options = {}) {
5081
5253
  const content = bounded ? regex(new RegExp(`[^${cls}]+`)) : regex(new RegExp(`[^${escapeClassChar(open)}${escapeClassChar(close)}]`));
5082
5254
  const inner = many(choice(self, ...skips, content));
5083
5255
  const combi = transform(
5084
- sequence(literal(open), inner, expect(literal(close), close)),
5256
+ sequence(literal(open), inner, expect(literal(close))),
5085
5257
  // parts: strings (content/self) or arrays (a sequence-shaped skip) or a
5086
5258
  // ParseError (recovered close). `c` is the close string or a ParseError.
5087
5259
  ([o, parts, c]) => o + parts.map((p) => typeof p === "string" ? p : Array.isArray(p) ? p.join("") : "").join("") + (typeof c === "string" ? c : "")
@@ -5118,6 +5290,7 @@ function childrenOf2(def) {
5118
5290
  case "optional":
5119
5291
  case "transform":
5120
5292
  case "trivia":
5293
+ case "token":
5121
5294
  case "label":
5122
5295
  case "not":
5123
5296
  case "node":
@@ -5199,6 +5372,7 @@ function evalRuleMapIR(ir) {
5199
5372
  "node",
5200
5373
  "parser",
5201
5374
  "scanTo",
5375
+ "token",
5202
5376
  "transform",
5203
5377
  "skip",
5204
5378
  "trivia",
@@ -5224,6 +5398,7 @@ function evalRuleMapIR(ir) {
5224
5398
  node,
5225
5399
  parser,
5226
5400
  scanTo,
5401
+ token,
5227
5402
  transform,
5228
5403
  skip,
5229
5404
  trivia,
@@ -5357,6 +5532,8 @@ ${body}
5357
5532
  return `not(${kid(def.parser)})`;
5358
5533
  case "trivia":
5359
5534
  return `trivia(${kid(def.parser)})`;
5535
+ case "token":
5536
+ return `token(${kid(def.parser)})`;
5360
5537
  case "label":
5361
5538
  return `label(${JSON.stringify(def.label)}, ${kid(def.parser)})`;
5362
5539
  case "expect":
@@ -5479,6 +5656,7 @@ var SUPPORTED = {
5479
5656
  trivia: (...a) => trivia(a[0]),
5480
5657
  label: (...a) => label(a[0], a[1]),
5481
5658
  noTrivia: (...a) => noTrivia(a[0]),
5659
+ token: (...a) => token(a[0]),
5482
5660
  expect: (...a) => expect(a[0], a[1])
5483
5661
  };
5484
5662
  function isScopeEntry(v2) {