clarity-pattern-parser 10.1.24 → 10.1.25

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.
@@ -997,7 +997,7 @@
997
997
  }
998
998
  constructor(name, options, isGreedy = false) {
999
999
  if (options.length === 0) {
1000
- throw new Error("Need at least one pattern with an 'or' pattern.");
1000
+ throw new Error("Need at least one pattern with an 'options' pattern.");
1001
1001
  }
1002
1002
  const children = clonePatterns(options);
1003
1003
  this._assignChildrenToParent(children);
@@ -2387,14 +2387,14 @@
2387
2387
  const startIndex = options.reduce((lowestIndex, o) => {
2388
2388
  return Math.min(lowestIndex, o.startIndex);
2389
2389
  }, Infinity);
2390
- const endIndex = cursor.getLastIndex() + 1;
2391
- error = new ParseError(startIndex, endIndex, this._pattern);
2390
+ const lastIndex = cursor.getLastIndex() + 1;
2391
+ error = new ParseError(startIndex, lastIndex, this._pattern);
2392
2392
  errorAtIndex = startIndex;
2393
2393
  }
2394
2394
  else if (!isComplete && options.length === 0 && ast != null) {
2395
2395
  const startIndex = ast.endIndex;
2396
- const endIndex = cursor.getLastIndex() + 1;
2397
- error = new ParseError(startIndex, endIndex, this._pattern);
2396
+ const lastIndex = cursor.getLastIndex() + 1;
2397
+ error = new ParseError(startIndex, lastIndex, this._pattern);
2398
2398
  errorAtIndex = startIndex;
2399
2399
  }
2400
2400
  else if (!isComplete && this._cursor.hasError && this._cursor.furthestError != null) {
@@ -2449,8 +2449,21 @@
2449
2449
  const errors = this._cursor.errors.filter(e => e.lastIndex === this._cursor.length);
2450
2450
  const suggestions = errors.map(e => {
2451
2451
  const tokens = this._getTokensForPattern(e.pattern);
2452
- const adjustedTokens = tokens.map(t => t.slice(e.lastIndex - e.startIndex));
2453
- return this._createSuggestions(e.lastIndex, adjustedTokens);
2452
+ const adjustedTokens = new Set();
2453
+ const currentText = this._cursor.getChars(e.startIndex, e.lastIndex);
2454
+ tokens.forEach((token) => {
2455
+ if (token.startsWith(currentText) && token.length > currentText.length) {
2456
+ const difference = token.length - currentText.length;
2457
+ const suggestedText = token.slice(-difference);
2458
+ adjustedTokens.add(suggestedText);
2459
+ }
2460
+ });
2461
+ return Array.from(adjustedTokens).map(t => {
2462
+ return {
2463
+ text: t,
2464
+ startIndex: e.lastIndex,
2465
+ };
2466
+ });
2454
2467
  });
2455
2468
  return suggestions.flat();
2456
2469
  }
@@ -2625,6 +2638,7 @@
2625
2638
  }
2626
2639
  clone(name = this._name) {
2627
2640
  const clone = new Context(name, this._pattern, Object.values(this._patterns));
2641
+ clone._id = this._id;
2628
2642
  return clone;
2629
2643
  }
2630
2644
  getTokens() {