parseman 0.48.0 → 0.48.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.
@@ -3422,6 +3422,7 @@ function choice(...args) {
3422
3422
  },
3423
3423
  parse(input, pos, ctx) {
3424
3424
  const expected = [];
3425
+ let expectedAt = pos;
3425
3426
  if (disjoint) {
3426
3427
  const code = pos < input.length ? input.codePointAt(pos) : -1;
3427
3428
  let idx = code >= 0 && code < 128 ? asciiDispatch[code] : -1;
@@ -3479,7 +3480,12 @@ function choice(...args) {
3479
3480
  const result = parsers[i].parse(input, pos, ctx);
3480
3481
  if (!result.ok) {
3481
3482
  rollbackTrivia(ctx, mark);
3482
- expected.push(...result.expected);
3483
+ const at = result.span.start;
3484
+ if (at > expectedAt) {
3485
+ expectedAt = at;
3486
+ expected.length = 0;
3487
+ }
3488
+ if (at === expectedAt) expected.push(...result.expected);
3483
3489
  if (result.committed) return { ok: false, expected, span: result.span, committed: true };
3484
3490
  continue;
3485
3491
  }
@@ -3490,6 +3496,9 @@ function choice(...args) {
3490
3496
  }
3491
3497
  return result;
3492
3498
  }
3499
+ if (expected.length === 0) {
3500
+ for (const parser2 of parsers) expected.push(...deriveExpected(parser2));
3501
+ }
3493
3502
  return { ok: false, expected, span: { start: pos, end: pos } };
3494
3503
  }
3495
3504
  };
@@ -5181,24 +5190,43 @@ function choiceNode(arms, classes, armExpected, choiceExpected) {
5181
5190
  };
5182
5191
  for (let i = arms.length - 1; i >= 0; i--) {
5183
5192
  const arm = arms[i], cls = classes[i], staticExpected = armExpected[i], next = tail;
5184
- tail = (input, pos, ctx, lead2, acc) => {
5193
+ tail = (input, pos, ctx, lead2, acc, best) => {
5185
5194
  if (cls !== void 0 && !classHas(cls, lead2)) {
5186
- return next(input, pos, ctx, lead2, appendExpected(acc, staticExpected));
5195
+ return next(
5196
+ input,
5197
+ pos,
5198
+ ctx,
5199
+ lead2,
5200
+ best === pos ? appendExpected(acc, staticExpected) : acc,
5201
+ best
5202
+ );
5187
5203
  }
5188
5204
  ctx._fc = false;
5189
5205
  const end = arm.run(input, pos, ctx);
5190
5206
  if (end >= 0) return end;
5191
- const nextAcc = appendExpected(acc, ctx._fx);
5207
+ const at = ctx._fe ?? pos;
5208
+ if (at > best) {
5209
+ best = at;
5210
+ acc = void 0;
5211
+ }
5212
+ const nextAcc = at === best ? appendExpected(acc, ctx._fx) : acc;
5192
5213
  if (committed(ctx)) {
5193
5214
  if (nextAcc !== void 0) ctx._fx = nextAcc;
5194
5215
  return -1;
5195
5216
  }
5196
- return next(input, pos, ctx, lead2, nextAcc);
5217
+ return next(input, pos, ctx, lead2, nextAcc, best);
5197
5218
  };
5198
5219
  }
5199
5220
  return {
5200
5221
  match: matchTail,
5201
- run: (input, pos, ctx) => tail(input, pos, ctx, pos < input.length ? input.codePointAt(pos) : -1, void 0)
5222
+ run: (input, pos, ctx) => tail(
5223
+ input,
5224
+ pos,
5225
+ ctx,
5226
+ pos < input.length ? input.codePointAt(pos) : -1,
5227
+ void 0,
5228
+ pos
5229
+ )
5202
5230
  };
5203
5231
  }
5204
5232
  function notNode(body, failure) {
@@ -9289,9 +9317,11 @@ ${catchCases}
9289
9317
  ctx._fc=false
9290
9318
  {const v=${arm}(input,pos,ctx)
9291
9319
  if(v!==FAIL)return v}
9292
- acc=${catchName}(${i},prev,acc)
9320
+ if(best===pos)acc=${catchName}(${i},prev,acc)
9293
9321
  prev=${i + 1}
9294
- acc=_accSet(ctx._fx,acc)
9322
+ {const at=ctx._fe??pos
9323
+ if(at>best){best=at;acc=undefined}
9324
+ if(at===best)acc=_accSet(ctx._fx,acc)}
9295
9325
  if(ctx._fc===true){if(acc!==undefined)ctx._fx=acc;return FAIL}
9296
9326
  ${emitRollback(p, L.buf, sinks)}
9297
9327
  }`;
@@ -9300,19 +9330,22 @@ ${emitRollback(p, L.buf, sinks)}
9300
9330
  ctx._fc=false
9301
9331
  {const v=${arm}(input,pos,ctx)
9302
9332
  if(v!==FAIL)return v}
9303
- acc=_accSet(ctx._fx,acc)
9333
+ {const at=ctx._fe??pos
9334
+ if(at>best){best=at;acc=undefined}
9335
+ if(at===best)acc=_accSet(ctx._fx,acc)}
9304
9336
  if(ctx._fc===true){if(acc!==undefined)ctx._fx=acc;return FAIL}
9305
9337
  ${emitRollback(p, L.buf, sinks)}
9306
- }else acc=_accSet(${expected[i]},acc)`).join("\n");
9338
+ }else if(best===pos)acc=_accSet(${expected[i]},acc)`).join("\n");
9307
9339
  return `${head}
9308
9340
  const c=lead(input,pos)
9309
9341
  ${emitMark(p, L.buf, sinks)}
9310
9342
  let acc
9343
+ let best=pos
9311
9344
  ${maskable ? `if(c<128){
9312
9345
  const bits=${maskName}[c<0?128:c]
9313
9346
  let prev=0
9314
9347
  ${maskArms}
9315
- acc=${catchName}(${n},prev,acc)
9348
+ if(best===pos)acc=${catchName}(${n},prev,acc)
9316
9349
  ctx._fe=pos;ctx._fx=acc??${choiceFx}
9317
9350
  return FAIL
9318
9351
  }
@@ -10431,14 +10464,19 @@ function assemble(t, prog, cfg) {
10431
10464
  };
10432
10465
  }
10433
10466
  function maskedChoiceBlock(start, a0, a1, a2, a3, through, next, total, choiceFx) {
10434
- return (input, pos, ctx, bits, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot, acc, prev) => {
10467
+ return (input, pos, ctx, bits, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot, acc, prev, best) => {
10435
10468
  if ((bits & 1 << start) !== 0) {
10436
10469
  ctx._fc = false;
10437
10470
  const v = a0(input, pos, ctx);
10438
10471
  if (v !== FAIL) return v;
10439
- acc = through(start, prev, acc);
10472
+ if (best === pos) acc = through(start, prev, acc);
10440
10473
  prev = start + 1;
10441
- acc = accSet(ctx._fx, acc);
10474
+ const at = ctx._fe ?? pos;
10475
+ if (at > best) {
10476
+ best = at;
10477
+ acc = void 0;
10478
+ }
10479
+ if (at === best) acc = accSet(ctx._fx, acc);
10442
10480
  if (committed3(ctx)) {
10443
10481
  if (acc !== void 0) ctx._fx = acc;
10444
10482
  return FAIL;
@@ -10449,9 +10487,14 @@ function assemble(t, prog, cfg) {
10449
10487
  ctx._fc = false;
10450
10488
  const v = a1(input, pos, ctx);
10451
10489
  if (v !== FAIL) return v;
10452
- acc = through(start + 1, prev, acc);
10490
+ if (best === pos) acc = through(start + 1, prev, acc);
10453
10491
  prev = start + 2;
10454
- acc = accSet(ctx._fx, acc);
10492
+ const at = ctx._fe ?? pos;
10493
+ if (at > best) {
10494
+ best = at;
10495
+ acc = void 0;
10496
+ }
10497
+ if (at === best) acc = accSet(ctx._fx, acc);
10455
10498
  if (committed3(ctx)) {
10456
10499
  if (acc !== void 0) ctx._fx = acc;
10457
10500
  return FAIL;
@@ -10462,9 +10505,14 @@ function assemble(t, prog, cfg) {
10462
10505
  ctx._fc = false;
10463
10506
  const v = a2(input, pos, ctx);
10464
10507
  if (v !== FAIL) return v;
10465
- acc = through(start + 2, prev, acc);
10508
+ if (best === pos) acc = through(start + 2, prev, acc);
10466
10509
  prev = start + 3;
10467
- acc = accSet(ctx._fx, acc);
10510
+ const at = ctx._fe ?? pos;
10511
+ if (at > best) {
10512
+ best = at;
10513
+ acc = void 0;
10514
+ }
10515
+ if (at === best) acc = accSet(ctx._fx, acc);
10468
10516
  if (committed3(ctx)) {
10469
10517
  if (acc !== void 0) ctx._fx = acc;
10470
10518
  return FAIL;
@@ -10475,9 +10523,14 @@ function assemble(t, prog, cfg) {
10475
10523
  ctx._fc = false;
10476
10524
  const v = a3(input, pos, ctx);
10477
10525
  if (v !== FAIL) return v;
10478
- acc = through(start + 3, prev, acc);
10526
+ if (best === pos) acc = through(start + 3, prev, acc);
10479
10527
  prev = start + 4;
10480
- acc = accSet(ctx._fx, acc);
10528
+ const at = ctx._fe ?? pos;
10529
+ if (at > best) {
10530
+ best = at;
10531
+ acc = void 0;
10532
+ }
10533
+ if (at === best) acc = accSet(ctx._fx, acc);
10481
10534
  if (committed3(ctx)) {
10482
10535
  if (acc !== void 0) ctx._fx = acc;
10483
10536
  return FAIL;
@@ -10485,23 +10538,28 @@ function assemble(t, prog, cfg) {
10485
10538
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
10486
10539
  }
10487
10540
  if (next !== void 0) {
10488
- return next(input, pos, ctx, bits, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot, acc, prev);
10541
+ return next(input, pos, ctx, bits, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot, acc, prev, best);
10489
10542
  }
10490
- acc = through(total, prev, acc);
10543
+ if (best === pos) acc = through(total, prev, acc);
10491
10544
  ctx._fe = pos;
10492
10545
  ctx._fx = acc ?? choiceFx;
10493
10546
  return FAIL;
10494
10547
  };
10495
10548
  }
10496
10549
  function generalChoiceBlock(start, a0, a1, a2, a3, g0, g1, g2, g3, through, next, total, choiceFx) {
10497
- return (input, pos, ctx, c, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot, acc, prev) => {
10550
+ return (input, pos, ctx, c, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot, acc, prev, best) => {
10498
10551
  if (g0 === null || classHas2(g0, c)) {
10499
10552
  ctx._fc = false;
10500
10553
  const v = a0(input, pos, ctx);
10501
10554
  if (v !== FAIL) return v;
10502
- acc = through(start, prev, acc);
10555
+ if (best === pos) acc = through(start, prev, acc);
10503
10556
  prev = start + 1;
10504
- acc = accSet(ctx._fx, acc);
10557
+ const at = ctx._fe ?? pos;
10558
+ if (at > best) {
10559
+ best = at;
10560
+ acc = void 0;
10561
+ }
10562
+ if (at === best) acc = accSet(ctx._fx, acc);
10505
10563
  if (committed3(ctx)) {
10506
10564
  if (acc !== void 0) ctx._fx = acc;
10507
10565
  return FAIL;
@@ -10512,9 +10570,14 @@ function assemble(t, prog, cfg) {
10512
10570
  ctx._fc = false;
10513
10571
  const v = a1(input, pos, ctx);
10514
10572
  if (v !== FAIL) return v;
10515
- acc = through(start + 1, prev, acc);
10573
+ if (best === pos) acc = through(start + 1, prev, acc);
10516
10574
  prev = start + 2;
10517
- acc = accSet(ctx._fx, acc);
10575
+ const at = ctx._fe ?? pos;
10576
+ if (at > best) {
10577
+ best = at;
10578
+ acc = void 0;
10579
+ }
10580
+ if (at === best) acc = accSet(ctx._fx, acc);
10518
10581
  if (committed3(ctx)) {
10519
10582
  if (acc !== void 0) ctx._fx = acc;
10520
10583
  return FAIL;
@@ -10525,9 +10588,14 @@ function assemble(t, prog, cfg) {
10525
10588
  ctx._fc = false;
10526
10589
  const v = a2(input, pos, ctx);
10527
10590
  if (v !== FAIL) return v;
10528
- acc = through(start + 2, prev, acc);
10591
+ if (best === pos) acc = through(start + 2, prev, acc);
10529
10592
  prev = start + 3;
10530
- acc = accSet(ctx._fx, acc);
10593
+ const at = ctx._fe ?? pos;
10594
+ if (at > best) {
10595
+ best = at;
10596
+ acc = void 0;
10597
+ }
10598
+ if (at === best) acc = accSet(ctx._fx, acc);
10531
10599
  if (committed3(ctx)) {
10532
10600
  if (acc !== void 0) ctx._fx = acc;
10533
10601
  return FAIL;
@@ -10538,9 +10606,14 @@ function assemble(t, prog, cfg) {
10538
10606
  ctx._fc = false;
10539
10607
  const v = a3(input, pos, ctx);
10540
10608
  if (v !== FAIL) return v;
10541
- acc = through(start + 3, prev, acc);
10609
+ if (best === pos) acc = through(start + 3, prev, acc);
10542
10610
  prev = start + 4;
10543
- acc = accSet(ctx._fx, acc);
10611
+ const at = ctx._fe ?? pos;
10612
+ if (at > best) {
10613
+ best = at;
10614
+ acc = void 0;
10615
+ }
10616
+ if (at === best) acc = accSet(ctx._fx, acc);
10544
10617
  if (committed3(ctx)) {
10545
10618
  if (acc !== void 0) ctx._fx = acc;
10546
10619
  return FAIL;
@@ -10548,9 +10621,9 @@ function assemble(t, prog, cfg) {
10548
10621
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
10549
10622
  }
10550
10623
  if (next !== void 0) {
10551
- return next(input, pos, ctx, c, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot, acc, prev);
10624
+ return next(input, pos, ctx, c, need, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot, acc, prev, best);
10552
10625
  }
10553
- acc = through(total, prev, acc);
10626
+ if (best === pos) acc = through(total, prev, acc);
10554
10627
  ctx._fe = pos;
10555
10628
  ctx._fx = acc ?? choiceFx;
10556
10629
  return FAIL;
@@ -11906,6 +11979,7 @@ function assemble(t, prog, cfg) {
11906
11979
  const mLog = need ? ctx._triviaLog?.length ?? 0 : 0;
11907
11980
  const mRoot = need ? ctx._rootTriviaLog?.length ?? 0 : 0;
11908
11981
  let acc;
11982
+ let best = pos;
11909
11983
  if (c < 128) {
11910
11984
  const bits = mask[c < 0 ? 128 : c];
11911
11985
  let prev = 0;
@@ -11914,7 +11988,12 @@ function assemble(t, prog, cfg) {
11914
11988
  const v = a0(input, pos, ctx);
11915
11989
  if (v !== FAIL) return v;
11916
11990
  prev = 1;
11917
- acc = accSet(ctx._fx, acc);
11991
+ const at = ctx._fe ?? pos;
11992
+ if (at > best) {
11993
+ best = at;
11994
+ acc = void 0;
11995
+ }
11996
+ if (at === best) acc = accSet(ctx._fx, acc);
11918
11997
  if (committed3(ctx)) {
11919
11998
  if (acc !== void 0) ctx._fx = acc;
11920
11999
  return FAIL;
@@ -11925,9 +12004,14 @@ function assemble(t, prog, cfg) {
11925
12004
  ctx._fc = false;
11926
12005
  const v = a1(input, pos, ctx);
11927
12006
  if (v !== FAIL) return v;
11928
- if (prev < 1) acc = accSet(e0, acc);
12007
+ if (best === pos && prev < 1) acc = accSet(e0, acc);
11929
12008
  prev = 2;
11930
- acc = accSet(ctx._fx, acc);
12009
+ const at = ctx._fe ?? pos;
12010
+ if (at > best) {
12011
+ best = at;
12012
+ acc = void 0;
12013
+ }
12014
+ if (at === best) acc = accSet(ctx._fx, acc);
11931
12015
  if (committed3(ctx)) {
11932
12016
  if (acc !== void 0) ctx._fx = acc;
11933
12017
  return FAIL;
@@ -11938,19 +12022,24 @@ function assemble(t, prog, cfg) {
11938
12022
  ctx._fc = false;
11939
12023
  const v = a2(input, pos, ctx);
11940
12024
  if (v !== FAIL) return v;
11941
- if (prev < 1) acc = accSet(e0, acc);
11942
- if (prev < 2) acc = accSet(e1, acc);
12025
+ if (best === pos && prev < 1) acc = accSet(e0, acc);
12026
+ if (best === pos && prev < 2) acc = accSet(e1, acc);
11943
12027
  prev = 3;
11944
- acc = accSet(ctx._fx, acc);
12028
+ const at = ctx._fe ?? pos;
12029
+ if (at > best) {
12030
+ best = at;
12031
+ acc = void 0;
12032
+ }
12033
+ if (at === best) acc = accSet(ctx._fx, acc);
11945
12034
  if (committed3(ctx)) {
11946
12035
  if (acc !== void 0) ctx._fx = acc;
11947
12036
  return FAIL;
11948
12037
  }
11949
12038
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
11950
12039
  }
11951
- if (prev < 1) acc = accSet(e0, acc);
11952
- if (prev < 2) acc = accSet(e1, acc);
11953
- if (n === 3 && prev < 3) acc = accSet(e2, acc);
12040
+ if (best === pos && prev < 1) acc = accSet(e0, acc);
12041
+ if (best === pos && prev < 2) acc = accSet(e1, acc);
12042
+ if (best === pos && n === 3 && prev < 3) acc = accSet(e2, acc);
11954
12043
  ctx._fe = pos;
11955
12044
  ctx._fx = acc ?? choiceFx;
11956
12045
  return FAIL;
@@ -11959,36 +12048,51 @@ function assemble(t, prog, cfg) {
11959
12048
  ctx._fc = false;
11960
12049
  const v = a0(input, pos, ctx);
11961
12050
  if (v !== FAIL) return v;
11962
- acc = accSet(ctx._fx, acc);
12051
+ const at = ctx._fe ?? pos;
12052
+ if (at > best) {
12053
+ best = at;
12054
+ acc = void 0;
12055
+ }
12056
+ if (at === best) acc = accSet(ctx._fx, acc);
11963
12057
  if (committed3(ctx)) {
11964
12058
  if (acc !== void 0) ctx._fx = acc;
11965
12059
  return FAIL;
11966
12060
  }
11967
12061
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
11968
- } else acc = accSet(e0, acc);
12062
+ } else if (best === pos) acc = accSet(e0, acc);
11969
12063
  if (g1 === null || classHas2(g1, c)) {
11970
12064
  ctx._fc = false;
11971
12065
  const v = a1(input, pos, ctx);
11972
12066
  if (v !== FAIL) return v;
11973
- acc = accSet(ctx._fx, acc);
12067
+ const at = ctx._fe ?? pos;
12068
+ if (at > best) {
12069
+ best = at;
12070
+ acc = void 0;
12071
+ }
12072
+ if (at === best) acc = accSet(ctx._fx, acc);
11974
12073
  if (committed3(ctx)) {
11975
12074
  if (acc !== void 0) ctx._fx = acc;
11976
12075
  return FAIL;
11977
12076
  }
11978
12077
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
11979
- } else acc = accSet(e1, acc);
12078
+ } else if (best === pos) acc = accSet(e1, acc);
11980
12079
  if (n === 3) {
11981
12080
  if (g2 === null || classHas2(g2, c)) {
11982
12081
  ctx._fc = false;
11983
12082
  const v = a2(input, pos, ctx);
11984
12083
  if (v !== FAIL) return v;
11985
- acc = accSet(ctx._fx, acc);
12084
+ const at = ctx._fe ?? pos;
12085
+ if (at > best) {
12086
+ best = at;
12087
+ acc = void 0;
12088
+ }
12089
+ if (at === best) acc = accSet(ctx._fx, acc);
11986
12090
  if (committed3(ctx)) {
11987
12091
  if (acc !== void 0) ctx._fx = acc;
11988
12092
  return FAIL;
11989
12093
  }
11990
12094
  if (need) rollbackTriviaAt(ctx, mRaw, mTl, mLv, mFl, mEr, mLog, mRoot);
11991
- } else acc = accSet(e2, acc);
12095
+ } else if (best === pos) acc = accSet(e2, acc);
11992
12096
  }
11993
12097
  ctx._fe = pos;
11994
12098
  ctx._fx = acc ?? choiceFx;
@@ -12086,7 +12190,8 @@ function assemble(t, prog, cfg) {
12086
12190
  mLog,
12087
12191
  mRoot,
12088
12192
  void 0,
12089
- 0
12193
+ 0,
12194
+ pos
12090
12195
  );
12091
12196
  }
12092
12197
  return general(
@@ -12103,7 +12208,8 @@ function assemble(t, prog, cfg) {
12103
12208
  mLog,
12104
12209
  mRoot,
12105
12210
  void 0,
12106
- 0
12211
+ 0,
12212
+ pos
12107
12213
  );
12108
12214
  };
12109
12215
  }
@@ -12131,7 +12237,8 @@ function assemble(t, prog, cfg) {
12131
12237
  mLog,
12132
12238
  mRoot,
12133
12239
  void 0,
12134
- 0
12240
+ 0,
12241
+ pos
12135
12242
  );
12136
12243
  };
12137
12244
  }
@@ -15468,7 +15575,7 @@ function compileRuleMap(ruleMap, opts = {}) {
15468
15575
  }
15469
15576
 
15470
15577
  // src/version.ts
15471
- var PARSEMAN_VERSION = "0.48.0";
15578
+ var PARSEMAN_VERSION = "0.48.1";
15472
15579
 
15473
15580
  // src/compiler/compile-linkable-table.ts
15474
15581
  function isLocal(rule) {