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.
package/dist/index.esm.js CHANGED
@@ -262,9 +262,11 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
262
262
  };
263
263
 
264
264
  class ParseError {
265
- constructor(startIndex, endIndex, pattern) {
265
+ constructor(startIndex, lastIndex, pattern) {
266
+ this.firstIndex = startIndex;
266
267
  this.startIndex = startIndex;
267
- this.endIndex = endIndex;
268
+ this.lastIndex = lastIndex;
269
+ this.endIndex = lastIndex + 1;
268
270
  this.pattern = pattern;
269
271
  }
270
272
  }
@@ -354,7 +356,7 @@ class CursorHistory {
354
356
  recordErrorAt(startIndex, endIndex, pattern) {
355
357
  const error = new ParseError(startIndex, endIndex, pattern);
356
358
  this._currentError = error;
357
- if (this._furthestError === null || endIndex > this._furthestError.endIndex) {
359
+ if (this._furthestError === null || endIndex > this._furthestError.lastIndex) {
358
360
  this._furthestError = error;
359
361
  }
360
362
  if (this._isRecording) {
@@ -2406,18 +2408,18 @@ class AutoComplete {
2406
2408
  const furthestError = cursor.furthestError;
2407
2409
  const furthestMatch = cursor.allMatchedNodes[cursor.allMatchedNodes.length - 1];
2408
2410
  if (furthestError && furthestMatch) {
2409
- if (furthestError.endIndex > furthestMatch.endIndex) {
2411
+ if (furthestError.lastIndex > furthestMatch.endIndex) {
2410
2412
  return furthestMatch.endIndex;
2411
2413
  }
2412
2414
  else {
2413
- return furthestError.endIndex;
2415
+ return furthestError.lastIndex;
2414
2416
  }
2415
2417
  }
2416
2418
  if (furthestError == null && furthestMatch != null) {
2417
2419
  return furthestMatch.endIndex;
2418
2420
  }
2419
2421
  if (furthestMatch == null && furthestError != null) {
2420
- return furthestError.endIndex;
2422
+ return furthestError.lastIndex;
2421
2423
  }
2422
2424
  return 0;
2423
2425
  }
@@ -2438,11 +2440,11 @@ class AutoComplete {
2438
2440
  }
2439
2441
  _getOptionsFromErrors() {
2440
2442
  // These errored because the length of the string.
2441
- const errors = this._cursor.errors.filter(e => e.endIndex === this._cursor.length);
2443
+ const errors = this._cursor.errors.filter(e => e.lastIndex === this._cursor.length);
2442
2444
  const suggestions = errors.map(e => {
2443
2445
  const tokens = this._getTokensForPattern(e.pattern);
2444
- const adjustedTokens = tokens.map(t => t.slice(e.endIndex - e.startIndex));
2445
- return this._createSuggestions(e.endIndex, adjustedTokens);
2446
+ const adjustedTokens = tokens.map(t => t.slice(e.lastIndex - e.startIndex));
2447
+ return this._createSuggestions(e.lastIndex, adjustedTokens);
2446
2448
  });
2447
2449
  return suggestions.flat();
2448
2450
  }
@@ -2622,20 +2624,32 @@ class Context {
2622
2624
  getTokens() {
2623
2625
  return this._pattern.getTokens();
2624
2626
  }
2625
- getTokensAfter(childReference) {
2626
- return this._pattern.getTokensAfter(childReference);
2627
+ getTokensAfter(_childReference) {
2628
+ if (this._parent == null) {
2629
+ return [];
2630
+ }
2631
+ return this._parent.getTokensAfter(this);
2627
2632
  }
2628
2633
  getNextTokens() {
2629
- return this._pattern.getNextTokens();
2634
+ if (this._parent == null) {
2635
+ return [];
2636
+ }
2637
+ return this._parent.getTokensAfter(this);
2630
2638
  }
2631
2639
  getPatterns() {
2632
2640
  return this._pattern.getPatterns();
2633
2641
  }
2634
- getPatternsAfter(childReference) {
2635
- return this._pattern.getPatternsAfter(childReference);
2642
+ getPatternsAfter(_childReference) {
2643
+ if (this._parent == null) {
2644
+ return [];
2645
+ }
2646
+ return this._parent.getPatternsAfter(this);
2636
2647
  }
2637
2648
  getNextPatterns() {
2638
- return this._pattern.getNextPatterns();
2649
+ if (this._parent == null) {
2650
+ return [];
2651
+ }
2652
+ return this._parent.getPatternsAfter(this);
2639
2653
  }
2640
2654
  find(predicate) {
2641
2655
  return this._pattern.find(predicate);