parseman 0.48.0 → 0.49.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.
Files changed (45) hide show
  1. package/dist/analysis/diagnostics.js +158 -51
  2. package/dist/analysis/diagnostics.js.map +2 -2
  3. package/dist/cli/index.js +160 -52
  4. package/dist/cli/index.js.map +2 -2
  5. package/dist/combinators/choice.d.ts.map +1 -1
  6. package/dist/compiler/ir-serialize.d.ts.map +1 -1
  7. package/dist/compiler/linker.d.ts.map +1 -1
  8. package/dist/index.js +169 -55
  9. package/dist/index.js.map +2 -2
  10. package/dist/language-service/index.js.map +1 -1
  11. package/dist/plugin/direct-builder-static.d.ts +20 -0
  12. package/dist/plugin/direct-builder-static.d.ts.map +1 -1
  13. package/dist/plugin/evaluator.d.ts +13 -0
  14. package/dist/plugin/evaluator.d.ts.map +1 -1
  15. package/dist/plugin/index.d.ts.map +1 -1
  16. package/dist/plugin/index.js +365 -71
  17. package/dist/plugin/index.js.map +2 -2
  18. package/dist/spec/index.js +12 -2
  19. package/dist/spec/index.js.map +2 -2
  20. package/dist/table/assemble.d.ts.map +1 -1
  21. package/dist/table/emit-assembly.d.ts.map +1 -1
  22. package/dist/table/encode.d.ts.map +1 -1
  23. package/dist/table/exec.d.ts.map +1 -1
  24. package/dist/table/index.js +158 -51
  25. package/dist/table/index.js.map +1 -1
  26. package/dist/table/lex-program.d.ts.map +1 -1
  27. package/dist/table/ops.d.ts +4 -4
  28. package/dist/types.d.ts +6 -1
  29. package/dist/types.d.ts.map +1 -1
  30. package/dist/version.d.ts +1 -1
  31. package/package.json +1 -1
  32. package/src/combinators/choice.ts +10 -1
  33. package/src/compiler/ir-serialize.ts +15 -3
  34. package/src/compiler/linker.ts +14 -1
  35. package/src/plugin/direct-builder-static.ts +116 -12
  36. package/src/plugin/evaluator.ts +50 -2
  37. package/src/plugin/index.ts +140 -1
  38. package/src/table/assemble.ts +82 -59
  39. package/src/table/emit-assembly.ts +10 -5
  40. package/src/table/encode.ts +6 -10
  41. package/src/table/exec.ts +13 -18
  42. package/src/table/lex-program.ts +15 -6
  43. package/src/table/ops.ts +4 -4
  44. package/src/types.ts +1 -1
  45. package/src/version.ts +1 -1
package/dist/cli/index.js CHANGED
@@ -3815,6 +3815,7 @@ function choice(...args) {
3815
3815
  },
3816
3816
  parse(input, pos, ctx) {
3817
3817
  const expected = [];
3818
+ let expectedAt = pos;
3818
3819
  if (disjoint) {
3819
3820
  const code = pos < input.length ? input.codePointAt(pos) : -1;
3820
3821
  let idx = code >= 0 && code < 128 ? asciiDispatch[code] : -1;
@@ -3872,7 +3873,12 @@ function choice(...args) {
3872
3873
  const result = parsers[i].parse(input, pos, ctx);
3873
3874
  if (!result.ok) {
3874
3875
  rollbackTrivia(ctx, mark);
3875
- expected.push(...result.expected);
3876
+ const at = result.span.start;
3877
+ if (at > expectedAt) {
3878
+ expectedAt = at;
3879
+ expected.length = 0;
3880
+ }
3881
+ if (at === expectedAt) expected.push(...result.expected);
3876
3882
  if (result.committed) return { ok: false, expected, span: result.span, committed: true };
3877
3883
  continue;
3878
3884
  }
@@ -3883,6 +3889,9 @@ function choice(...args) {
3883
3889
  }
3884
3890
  return result;
3885
3891
  }
3892
+ if (expected.length === 0) {
3893
+ for (const parser2 of parsers) expected.push(...deriveExpected(parser2));
3894
+ }
3886
3895
  return { ok: false, expected, span: { start: pos, end: pos } };
3887
3896
  }
3888
3897
  };
@@ -5470,7 +5479,7 @@ function evalRuleMapIR(ir) {
5470
5479
  l._def.fnSrc = src;
5471
5480
  return l;
5472
5481
  };
5473
- const _nd = (type, child, src, opts, staticError, sigSrc) => {
5482
+ const _nd = (type, child, src, opts, staticError, sigSrc, buildImports) => {
5474
5483
  if (staticError !== void 0 && staticError.length > 0) {
5475
5484
  throw new Error(`IR direct node builder for ${type} must be macro-static and self-contained; unsupported binding(s): ${staticError.join(", ")}`);
5476
5485
  }
@@ -5480,6 +5489,7 @@ function evalRuleMapIR(ir) {
5480
5489
  n._def.buildSrc = src;
5481
5490
  if (staticError !== void 0) n._def.buildStaticError = staticError;
5482
5491
  if (sigSrc !== void 0) n._def.buildSigSrc = sigSrc;
5492
+ if (buildImports !== void 0) n._def.buildImports = buildImports;
5483
5493
  return n;
5484
5494
  };
5485
5495
  const _gch = (items) => {
@@ -5844,24 +5854,43 @@ function choiceNode(arms, classes, armExpected, choiceExpected) {
5844
5854
  };
5845
5855
  for (let i = arms.length - 1; i >= 0; i--) {
5846
5856
  const arm = arms[i], cls = classes[i], staticExpected = armExpected[i], next = tail;
5847
- tail = (input, pos, ctx, lead2, acc) => {
5857
+ tail = (input, pos, ctx, lead2, acc, best) => {
5848
5858
  if (cls !== void 0 && !classHas(cls, lead2)) {
5849
- return next(input, pos, ctx, lead2, appendExpected(acc, staticExpected));
5859
+ return next(
5860
+ input,
5861
+ pos,
5862
+ ctx,
5863
+ lead2,
5864
+ best === pos ? appendExpected(acc, staticExpected) : acc,
5865
+ best
5866
+ );
5850
5867
  }
5851
5868
  ctx._fc = false;
5852
5869
  const end = arm.run(input, pos, ctx);
5853
5870
  if (end >= 0) return end;
5854
- const nextAcc = appendExpected(acc, ctx._fx);
5871
+ const at = ctx._fe ?? pos;
5872
+ if (at > best) {
5873
+ best = at;
5874
+ acc = void 0;
5875
+ }
5876
+ const nextAcc = at === best ? appendExpected(acc, ctx._fx) : acc;
5855
5877
  if (committed(ctx)) {
5856
5878
  if (nextAcc !== void 0) ctx._fx = nextAcc;
5857
5879
  return -1;
5858
5880
  }
5859
- return next(input, pos, ctx, lead2, nextAcc);
5881
+ return next(input, pos, ctx, lead2, nextAcc, best);
5860
5882
  };
5861
5883
  }
5862
5884
  return {
5863
5885
  match: matchTail,
5864
- run: (input, pos, ctx) => tail(input, pos, ctx, pos < input.length ? input.codePointAt(pos) : -1, void 0)
5886
+ run: (input, pos, ctx) => tail(
5887
+ input,
5888
+ pos,
5889
+ ctx,
5890
+ pos < input.length ? input.codePointAt(pos) : -1,
5891
+ void 0,
5892
+ pos
5893
+ )
5865
5894
  };
5866
5895
  }
5867
5896
  function notNode(body, failure) {
@@ -9952,9 +9981,11 @@ ${catchCases}
9952
9981
  ctx._fc=false
9953
9982
  {const v=${arm}(input,pos,ctx)
9954
9983
  if(v!==FAIL)return v}
9955
- acc=${catchName}(${i},prev,acc)
9984
+ if(best===pos)acc=${catchName}(${i},prev,acc)
9956
9985
  prev=${i + 1}
9957
- acc=_accSet(ctx._fx,acc)
9986
+ {const at=ctx._fe??pos
9987
+ if(at>best){best=at;acc=undefined}
9988
+ if(at===best)acc=_accSet(ctx._fx,acc)}
9958
9989
  if(ctx._fc===true){if(acc!==undefined)ctx._fx=acc;return FAIL}
9959
9990
  ${emitRollback(p, L.buf, sinks)}
9960
9991
  }`;
@@ -9963,19 +9994,22 @@ ${emitRollback(p, L.buf, sinks)}
9963
9994
  ctx._fc=false
9964
9995
  {const v=${arm}(input,pos,ctx)
9965
9996
  if(v!==FAIL)return v}
9966
- acc=_accSet(ctx._fx,acc)
9997
+ {const at=ctx._fe??pos
9998
+ if(at>best){best=at;acc=undefined}
9999
+ if(at===best)acc=_accSet(ctx._fx,acc)}
9967
10000
  if(ctx._fc===true){if(acc!==undefined)ctx._fx=acc;return FAIL}
9968
10001
  ${emitRollback(p, L.buf, sinks)}
9969
- }else acc=_accSet(${expected[i]},acc)`).join("\n");
10002
+ }else if(best===pos)acc=_accSet(${expected[i]},acc)`).join("\n");
9970
10003
  return `${head}
9971
10004
  const c=lead(input,pos)
9972
10005
  ${emitMark(p, L.buf, sinks)}
9973
10006
  let acc
10007
+ let best=pos
9974
10008
  ${maskable ? `if(c<128){
9975
10009
  const bits=${maskName}[c<0?128:c]
9976
10010
  let prev=0
9977
10011
  ${maskArms}
9978
- acc=${catchName}(${n},prev,acc)
10012
+ if(best===pos)acc=${catchName}(${n},prev,acc)
9979
10013
  ctx._fe=pos;ctx._fx=acc??${choiceFx}
9980
10014
  return FAIL
9981
10015
  }
@@ -10956,14 +10990,19 @@ function assemble(t2, prog, cfg) {
10956
10990
  };
10957
10991
  }
10958
10992
  function maskedChoiceBlock(start, a0, a1, a2, a3, through, next, total, choiceFx) {
10959
- return (input, pos, ctx, bits, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot, acc, prev) => {
10993
+ return (input, pos, ctx, bits, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot, acc, prev, best) => {
10960
10994
  if ((bits & 1 << start) !== 0) {
10961
10995
  ctx._fc = false;
10962
10996
  const v = a0(input, pos, ctx);
10963
10997
  if (v !== FAIL) return v;
10964
- acc = through(start, prev, acc);
10998
+ if (best === pos) acc = through(start, prev, acc);
10965
10999
  prev = start + 1;
10966
- acc = accSet(ctx._fx, acc);
11000
+ const at = ctx._fe ?? pos;
11001
+ if (at > best) {
11002
+ best = at;
11003
+ acc = void 0;
11004
+ }
11005
+ if (at === best) acc = accSet(ctx._fx, acc);
10967
11006
  if (committed3(ctx)) {
10968
11007
  if (acc !== void 0) ctx._fx = acc;
10969
11008
  return FAIL;
@@ -10974,9 +11013,14 @@ function assemble(t2, prog, cfg) {
10974
11013
  ctx._fc = false;
10975
11014
  const v = a1(input, pos, ctx);
10976
11015
  if (v !== FAIL) return v;
10977
- acc = through(start + 1, prev, acc);
11016
+ if (best === pos) acc = through(start + 1, prev, acc);
10978
11017
  prev = start + 2;
10979
- acc = accSet(ctx._fx, acc);
11018
+ const at = ctx._fe ?? pos;
11019
+ if (at > best) {
11020
+ best = at;
11021
+ acc = void 0;
11022
+ }
11023
+ if (at === best) acc = accSet(ctx._fx, acc);
10980
11024
  if (committed3(ctx)) {
10981
11025
  if (acc !== void 0) ctx._fx = acc;
10982
11026
  return FAIL;
@@ -10987,9 +11031,14 @@ function assemble(t2, prog, cfg) {
10987
11031
  ctx._fc = false;
10988
11032
  const v = a2(input, pos, ctx);
10989
11033
  if (v !== FAIL) return v;
10990
- acc = through(start + 2, prev, acc);
11034
+ if (best === pos) acc = through(start + 2, prev, acc);
10991
11035
  prev = start + 3;
10992
- acc = accSet(ctx._fx, acc);
11036
+ const at = ctx._fe ?? pos;
11037
+ if (at > best) {
11038
+ best = at;
11039
+ acc = void 0;
11040
+ }
11041
+ if (at === best) acc = accSet(ctx._fx, acc);
10993
11042
  if (committed3(ctx)) {
10994
11043
  if (acc !== void 0) ctx._fx = acc;
10995
11044
  return FAIL;
@@ -11000,9 +11049,14 @@ function assemble(t2, prog, cfg) {
11000
11049
  ctx._fc = false;
11001
11050
  const v = a3(input, pos, ctx);
11002
11051
  if (v !== FAIL) return v;
11003
- acc = through(start + 3, prev, acc);
11052
+ if (best === pos) acc = through(start + 3, prev, acc);
11004
11053
  prev = start + 4;
11005
- acc = accSet(ctx._fx, acc);
11054
+ const at = ctx._fe ?? pos;
11055
+ if (at > best) {
11056
+ best = at;
11057
+ acc = void 0;
11058
+ }
11059
+ if (at === best) acc = accSet(ctx._fx, acc);
11006
11060
  if (committed3(ctx)) {
11007
11061
  if (acc !== void 0) ctx._fx = acc;
11008
11062
  return FAIL;
@@ -11010,23 +11064,28 @@ function assemble(t2, prog, cfg) {
11010
11064
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
11011
11065
  }
11012
11066
  if (next !== void 0) {
11013
- return next(input, pos, ctx, bits, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot, acc, prev);
11067
+ return next(input, pos, ctx, bits, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot, acc, prev, best);
11014
11068
  }
11015
- acc = through(total, prev, acc);
11069
+ if (best === pos) acc = through(total, prev, acc);
11016
11070
  ctx._fe = pos;
11017
11071
  ctx._fx = acc ?? choiceFx;
11018
11072
  return FAIL;
11019
11073
  };
11020
11074
  }
11021
11075
  function generalChoiceBlock(start, a0, a1, a2, a3, g0, g1, g2, g3, through, next, total, choiceFx) {
11022
- return (input, pos, ctx, c, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot, acc, prev) => {
11076
+ return (input, pos, ctx, c, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot, acc, prev, best) => {
11023
11077
  if (g0 === null || classHas2(g0, c)) {
11024
11078
  ctx._fc = false;
11025
11079
  const v = a0(input, pos, ctx);
11026
11080
  if (v !== FAIL) return v;
11027
- acc = through(start, prev, acc);
11081
+ if (best === pos) acc = through(start, prev, acc);
11028
11082
  prev = start + 1;
11029
- acc = accSet(ctx._fx, acc);
11083
+ const at = ctx._fe ?? pos;
11084
+ if (at > best) {
11085
+ best = at;
11086
+ acc = void 0;
11087
+ }
11088
+ if (at === best) acc = accSet(ctx._fx, acc);
11030
11089
  if (committed3(ctx)) {
11031
11090
  if (acc !== void 0) ctx._fx = acc;
11032
11091
  return FAIL;
@@ -11037,9 +11096,14 @@ function assemble(t2, prog, cfg) {
11037
11096
  ctx._fc = false;
11038
11097
  const v = a1(input, pos, ctx);
11039
11098
  if (v !== FAIL) return v;
11040
- acc = through(start + 1, prev, acc);
11099
+ if (best === pos) acc = through(start + 1, prev, acc);
11041
11100
  prev = start + 2;
11042
- acc = accSet(ctx._fx, acc);
11101
+ const at = ctx._fe ?? pos;
11102
+ if (at > best) {
11103
+ best = at;
11104
+ acc = void 0;
11105
+ }
11106
+ if (at === best) acc = accSet(ctx._fx, acc);
11043
11107
  if (committed3(ctx)) {
11044
11108
  if (acc !== void 0) ctx._fx = acc;
11045
11109
  return FAIL;
@@ -11050,9 +11114,14 @@ function assemble(t2, prog, cfg) {
11050
11114
  ctx._fc = false;
11051
11115
  const v = a2(input, pos, ctx);
11052
11116
  if (v !== FAIL) return v;
11053
- acc = through(start + 2, prev, acc);
11117
+ if (best === pos) acc = through(start + 2, prev, acc);
11054
11118
  prev = start + 3;
11055
- acc = accSet(ctx._fx, acc);
11119
+ const at = ctx._fe ?? pos;
11120
+ if (at > best) {
11121
+ best = at;
11122
+ acc = void 0;
11123
+ }
11124
+ if (at === best) acc = accSet(ctx._fx, acc);
11056
11125
  if (committed3(ctx)) {
11057
11126
  if (acc !== void 0) ctx._fx = acc;
11058
11127
  return FAIL;
@@ -11063,9 +11132,14 @@ function assemble(t2, prog, cfg) {
11063
11132
  ctx._fc = false;
11064
11133
  const v = a3(input, pos, ctx);
11065
11134
  if (v !== FAIL) return v;
11066
- acc = through(start + 3, prev, acc);
11135
+ if (best === pos) acc = through(start + 3, prev, acc);
11067
11136
  prev = start + 4;
11068
- acc = accSet(ctx._fx, acc);
11137
+ const at = ctx._fe ?? pos;
11138
+ if (at > best) {
11139
+ best = at;
11140
+ acc = void 0;
11141
+ }
11142
+ if (at === best) acc = accSet(ctx._fx, acc);
11069
11143
  if (committed3(ctx)) {
11070
11144
  if (acc !== void 0) ctx._fx = acc;
11071
11145
  return FAIL;
@@ -11073,9 +11147,9 @@ function assemble(t2, prog, cfg) {
11073
11147
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
11074
11148
  }
11075
11149
  if (next !== void 0) {
11076
- return next(input, pos, ctx, c, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot, acc, prev);
11150
+ return next(input, pos, ctx, c, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot, acc, prev, best);
11077
11151
  }
11078
- acc = through(total, prev, acc);
11152
+ if (best === pos) acc = through(total, prev, acc);
11079
11153
  ctx._fe = pos;
11080
11154
  ctx._fx = acc ?? choiceFx;
11081
11155
  return FAIL;
@@ -12431,6 +12505,7 @@ function assemble(t2, prog, cfg) {
12431
12505
  const mLog = need ? ctx._triviaLog?.length ?? 0 : 0;
12432
12506
  const mRoot = need ? ctx._rootTriviaLog?.length ?? 0 : 0;
12433
12507
  let acc;
12508
+ let best = pos;
12434
12509
  if (c < 128) {
12435
12510
  const bits = mask[c < 0 ? 128 : c];
12436
12511
  let prev = 0;
@@ -12439,7 +12514,12 @@ function assemble(t2, prog, cfg) {
12439
12514
  const v = a0(input, pos, ctx);
12440
12515
  if (v !== FAIL) return v;
12441
12516
  prev = 1;
12442
- acc = accSet(ctx._fx, acc);
12517
+ const at = ctx._fe ?? pos;
12518
+ if (at > best) {
12519
+ best = at;
12520
+ acc = void 0;
12521
+ }
12522
+ if (at === best) acc = accSet(ctx._fx, acc);
12443
12523
  if (committed3(ctx)) {
12444
12524
  if (acc !== void 0) ctx._fx = acc;
12445
12525
  return FAIL;
@@ -12450,9 +12530,14 @@ function assemble(t2, prog, cfg) {
12450
12530
  ctx._fc = false;
12451
12531
  const v = a1(input, pos, ctx);
12452
12532
  if (v !== FAIL) return v;
12453
- if (prev < 1) acc = accSet(e0, acc);
12533
+ if (best === pos && prev < 1) acc = accSet(e0, acc);
12454
12534
  prev = 2;
12455
- acc = accSet(ctx._fx, acc);
12535
+ const at = ctx._fe ?? pos;
12536
+ if (at > best) {
12537
+ best = at;
12538
+ acc = void 0;
12539
+ }
12540
+ if (at === best) acc = accSet(ctx._fx, acc);
12456
12541
  if (committed3(ctx)) {
12457
12542
  if (acc !== void 0) ctx._fx = acc;
12458
12543
  return FAIL;
@@ -12463,19 +12548,24 @@ function assemble(t2, prog, cfg) {
12463
12548
  ctx._fc = false;
12464
12549
  const v = a2(input, pos, ctx);
12465
12550
  if (v !== FAIL) return v;
12466
- if (prev < 1) acc = accSet(e0, acc);
12467
- if (prev < 2) acc = accSet(e1, acc);
12551
+ if (best === pos && prev < 1) acc = accSet(e0, acc);
12552
+ if (best === pos && prev < 2) acc = accSet(e1, acc);
12468
12553
  prev = 3;
12469
- acc = accSet(ctx._fx, acc);
12554
+ const at = ctx._fe ?? pos;
12555
+ if (at > best) {
12556
+ best = at;
12557
+ acc = void 0;
12558
+ }
12559
+ if (at === best) acc = accSet(ctx._fx, acc);
12470
12560
  if (committed3(ctx)) {
12471
12561
  if (acc !== void 0) ctx._fx = acc;
12472
12562
  return FAIL;
12473
12563
  }
12474
12564
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
12475
12565
  }
12476
- if (prev < 1) acc = accSet(e0, acc);
12477
- if (prev < 2) acc = accSet(e1, acc);
12478
- if (n === 3 && prev < 3) acc = accSet(e2, acc);
12566
+ if (best === pos && prev < 1) acc = accSet(e0, acc);
12567
+ if (best === pos && prev < 2) acc = accSet(e1, acc);
12568
+ if (best === pos && n === 3 && prev < 3) acc = accSet(e2, acc);
12479
12569
  ctx._fe = pos;
12480
12570
  ctx._fx = acc ?? choiceFx;
12481
12571
  return FAIL;
@@ -12484,36 +12574,51 @@ function assemble(t2, prog, cfg) {
12484
12574
  ctx._fc = false;
12485
12575
  const v = a0(input, pos, ctx);
12486
12576
  if (v !== FAIL) return v;
12487
- acc = accSet(ctx._fx, acc);
12577
+ const at = ctx._fe ?? pos;
12578
+ if (at > best) {
12579
+ best = at;
12580
+ acc = void 0;
12581
+ }
12582
+ if (at === best) acc = accSet(ctx._fx, acc);
12488
12583
  if (committed3(ctx)) {
12489
12584
  if (acc !== void 0) ctx._fx = acc;
12490
12585
  return FAIL;
12491
12586
  }
12492
12587
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
12493
- } else acc = accSet(e0, acc);
12588
+ } else if (best === pos) acc = accSet(e0, acc);
12494
12589
  if (g1 === null || classHas2(g1, c)) {
12495
12590
  ctx._fc = false;
12496
12591
  const v = a1(input, pos, ctx);
12497
12592
  if (v !== FAIL) return v;
12498
- acc = accSet(ctx._fx, acc);
12593
+ const at = ctx._fe ?? pos;
12594
+ if (at > best) {
12595
+ best = at;
12596
+ acc = void 0;
12597
+ }
12598
+ if (at === best) acc = accSet(ctx._fx, acc);
12499
12599
  if (committed3(ctx)) {
12500
12600
  if (acc !== void 0) ctx._fx = acc;
12501
12601
  return FAIL;
12502
12602
  }
12503
12603
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
12504
- } else acc = accSet(e1, acc);
12604
+ } else if (best === pos) acc = accSet(e1, acc);
12505
12605
  if (n === 3) {
12506
12606
  if (g2 === null || classHas2(g2, c)) {
12507
12607
  ctx._fc = false;
12508
12608
  const v = a2(input, pos, ctx);
12509
12609
  if (v !== FAIL) return v;
12510
- acc = accSet(ctx._fx, acc);
12610
+ const at = ctx._fe ?? pos;
12611
+ if (at > best) {
12612
+ best = at;
12613
+ acc = void 0;
12614
+ }
12615
+ if (at === best) acc = accSet(ctx._fx, acc);
12511
12616
  if (committed3(ctx)) {
12512
12617
  if (acc !== void 0) ctx._fx = acc;
12513
12618
  return FAIL;
12514
12619
  }
12515
12620
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
12516
- } else acc = accSet(e2, acc);
12621
+ } else if (best === pos) acc = accSet(e2, acc);
12517
12622
  }
12518
12623
  ctx._fe = pos;
12519
12624
  ctx._fx = acc ?? choiceFx;
@@ -12611,7 +12716,8 @@ function assemble(t2, prog, cfg) {
12611
12716
  mLog,
12612
12717
  mRoot,
12613
12718
  void 0,
12614
- 0
12719
+ 0,
12720
+ pos
12615
12721
  );
12616
12722
  }
12617
12723
  return general(
@@ -12628,7 +12734,8 @@ function assemble(t2, prog, cfg) {
12628
12734
  mLog,
12629
12735
  mRoot,
12630
12736
  void 0,
12631
- 0
12737
+ 0,
12738
+ pos
12632
12739
  );
12633
12740
  };
12634
12741
  }
@@ -12656,7 +12763,8 @@ function assemble(t2, prog, cfg) {
12656
12763
  mLog,
12657
12764
  mRoot,
12658
12765
  void 0,
12659
- 0
12766
+ 0,
12767
+ pos
12660
12768
  );
12661
12769
  };
12662
12770
  }