parseman 0.18.0 → 0.18.1

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.
@@ -1489,7 +1489,11 @@ function label(name, combinator) {
1489
1489
  _tag: combinator._tag,
1490
1490
  _meta: combinator._meta,
1491
1491
  _def: { tag: "label", label: name, parser: combinator },
1492
- parse: combinator.parse.bind(combinator)
1492
+ parse(input, pos, ctx) {
1493
+ const result = combinator.parse(input, pos, ctx);
1494
+ if (!result.ok) return { ...result, expected: [name] };
1495
+ return result;
1496
+ }
1493
1497
  };
1494
1498
  }
1495
1499
 
@@ -4532,8 +4536,17 @@ function emitDispatch(p, ctx, pos) {
4532
4536
  return emit(def.parser, ctx, pos);
4533
4537
  case "token":
4534
4538
  return emitToken(def, ctx, pos);
4535
- case "label":
4536
- return emit(def.parser, ctx, pos);
4539
+ case "label": {
4540
+ const inner = emitFallible(def.parser, ctx, pos);
4541
+ return {
4542
+ stmts: [
4543
+ ...inner.stmts,
4544
+ ...emitIfFail(ctx, `!${inner.okVar}`, failBody(ctx, JSON.stringify(def.label), "_ctx._fe"))
4545
+ ],
4546
+ valueVar: inner.valVar,
4547
+ endVar: inner.endVar
4548
+ };
4549
+ }
4537
4550
  case "grammar": {
4538
4551
  const savedTrivia = ctx.activeTrivia;
4539
4552
  const savedKindLabels = ctx.triviaKindLabels;