clarity-pattern-parser 10.1.22 → 10.1.24

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.
@@ -268,9 +268,11 @@
268
268
  };
269
269
 
270
270
  class ParseError {
271
- constructor(startIndex, endIndex, pattern) {
271
+ constructor(startIndex, lastIndex, pattern) {
272
+ this.firstIndex = startIndex;
272
273
  this.startIndex = startIndex;
273
- this.endIndex = endIndex;
274
+ this.lastIndex = lastIndex;
275
+ this.endIndex = lastIndex + 1;
274
276
  this.pattern = pattern;
275
277
  }
276
278
  }
@@ -360,7 +362,7 @@
360
362
  recordErrorAt(startIndex, endIndex, pattern) {
361
363
  const error = new ParseError(startIndex, endIndex, pattern);
362
364
  this._currentError = error;
363
- if (this._furthestError === null || endIndex > this._furthestError.endIndex) {
365
+ if (this._furthestError === null || endIndex > this._furthestError.lastIndex) {
364
366
  this._furthestError = error;
365
367
  }
366
368
  if (this._isRecording) {
@@ -2412,18 +2414,18 @@
2412
2414
  const furthestError = cursor.furthestError;
2413
2415
  const furthestMatch = cursor.allMatchedNodes[cursor.allMatchedNodes.length - 1];
2414
2416
  if (furthestError && furthestMatch) {
2415
- if (furthestError.endIndex > furthestMatch.endIndex) {
2417
+ if (furthestError.lastIndex > furthestMatch.endIndex) {
2416
2418
  return furthestMatch.endIndex;
2417
2419
  }
2418
2420
  else {
2419
- return furthestError.endIndex;
2421
+ return furthestError.lastIndex;
2420
2422
  }
2421
2423
  }
2422
2424
  if (furthestError == null && furthestMatch != null) {
2423
2425
  return furthestMatch.endIndex;
2424
2426
  }
2425
2427
  if (furthestMatch == null && furthestError != null) {
2426
- return furthestError.endIndex;
2428
+ return furthestError.lastIndex;
2427
2429
  }
2428
2430
  return 0;
2429
2431
  }
@@ -2444,11 +2446,11 @@
2444
2446
  }
2445
2447
  _getOptionsFromErrors() {
2446
2448
  // These errored because the length of the string.
2447
- const errors = this._cursor.errors.filter(e => e.endIndex === this._cursor.length);
2449
+ const errors = this._cursor.errors.filter(e => e.lastIndex === this._cursor.length);
2448
2450
  const suggestions = errors.map(e => {
2449
2451
  const tokens = this._getTokensForPattern(e.pattern);
2450
- const adjustedTokens = tokens.map(t => t.slice(e.endIndex - e.startIndex));
2451
- return this._createSuggestions(e.endIndex, adjustedTokens);
2452
+ const adjustedTokens = tokens.map(t => t.slice(e.lastIndex - e.startIndex));
2453
+ return this._createSuggestions(e.lastIndex, adjustedTokens);
2452
2454
  });
2453
2455
  return suggestions.flat();
2454
2456
  }
@@ -2628,20 +2630,32 @@
2628
2630
  getTokens() {
2629
2631
  return this._pattern.getTokens();
2630
2632
  }
2631
- getTokensAfter(childReference) {
2632
- return this._pattern.getTokensAfter(childReference);
2633
+ getTokensAfter(_childReference) {
2634
+ if (this._parent == null) {
2635
+ return [];
2636
+ }
2637
+ return this._parent.getTokensAfter(this);
2633
2638
  }
2634
2639
  getNextTokens() {
2635
- return this._pattern.getNextTokens();
2640
+ if (this._parent == null) {
2641
+ return [];
2642
+ }
2643
+ return this._parent.getTokensAfter(this);
2636
2644
  }
2637
2645
  getPatterns() {
2638
2646
  return this._pattern.getPatterns();
2639
2647
  }
2640
- getPatternsAfter(childReference) {
2641
- return this._pattern.getPatternsAfter(childReference);
2648
+ getPatternsAfter(_childReference) {
2649
+ if (this._parent == null) {
2650
+ return [];
2651
+ }
2652
+ return this._parent.getPatternsAfter(this);
2642
2653
  }
2643
2654
  getNextPatterns() {
2644
- return this._pattern.getNextPatterns();
2655
+ if (this._parent == null) {
2656
+ return [];
2657
+ }
2658
+ return this._parent.getPatternsAfter(this);
2645
2659
  }
2646
2660
  find(predicate) {
2647
2661
  return this._pattern.find(predicate);