clarity-pattern-parser 11.0.16 → 11.0.19

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.
@@ -885,7 +885,7 @@
885
885
  for (let pattern of this._recursiveAncestors) {
886
886
  if (pattern._firstIndex === this._firstIndex) {
887
887
  depth++;
888
- if (depth > 1) {
888
+ if (depth > 0) {
889
889
  return true;
890
890
  }
891
891
  }
@@ -2924,12 +2924,10 @@
2924
2924
  this._associationMap = {};
2925
2925
  this._precedenceMap = {};
2926
2926
  this._originalPatterns = patterns;
2927
- this._patterns = this._organizePatterns(patterns);
2928
2927
  this._shouldStopParsing = false;
2929
- this._precedenceTree = new PrecedenceTree(this._precedenceMap, this._associationMap);
2930
- if (this._atomPatterns.length === 0) {
2931
- throw new Error("Need at least one terminating pattern with an 'expression' pattern.");
2932
- }
2928
+ this._hasOrganized = false;
2929
+ this._patterns = [];
2930
+ this._precedenceTree = new PrecedenceTree({}, {});
2933
2931
  }
2934
2932
  _organizePatterns(patterns) {
2935
2933
  const finalPatterns = [];
@@ -2972,6 +2970,8 @@
2972
2970
  finalPatterns.push(binary);
2973
2971
  }
2974
2972
  });
2973
+ this._patterns = finalPatterns;
2974
+ this._precedenceTree = new PrecedenceTree(this._precedenceMap, this._associationMap);
2975
2975
  return finalPatterns;
2976
2976
  }
2977
2977
  _extractName(pattern) {
@@ -3028,7 +3028,10 @@
3028
3028
  }
3029
3029
  _unwrapAssociationIfNecessary(pattern) {
3030
3030
  if (pattern.type === "right-associated") {
3031
- return pattern.children[0];
3031
+ pattern = pattern.children[0];
3032
+ }
3033
+ if (pattern.type === "reference") {
3034
+ pattern = pattern.getReferencePatternSafely();
3032
3035
  }
3033
3036
  return pattern;
3034
3037
  }
@@ -3043,6 +3046,16 @@
3043
3046
  }
3044
3047
  parse(cursor) {
3045
3048
  this._firstIndex = cursor.index;
3049
+ if (!this._hasOrganized) {
3050
+ this._hasOrganized = true;
3051
+ this._organizePatterns(this._originalPatterns);
3052
+ }
3053
+ // If there are not any atom nodes then nothing can be found.
3054
+ if (this._atomPatterns.length < 1) {
3055
+ cursor.moveTo(this._firstIndex);
3056
+ cursor.recordErrorAt(this._firstIndex, this._firstIndex, this);
3057
+ return null;
3058
+ }
3046
3059
  const node = this._tryToParse(cursor);
3047
3060
  if (node != null) {
3048
3061
  node.normalize(this._firstIndex);
@@ -3550,8 +3563,8 @@
3550
3563
  return options;
3551
3564
  }
3552
3565
  _isRecursive(name, pattern) {
3553
- if (pattern.type === "right-associated" && this._isRecursivePattern(name, pattern.children[0])) {
3554
- return true;
3566
+ if (pattern.type === "right-associated") {
3567
+ pattern = pattern.children[0];
3555
3568
  }
3556
3569
  return this._isRecursivePattern(name, pattern);
3557
3570
  }
@@ -3562,9 +3575,10 @@
3562
3575
  const firstChild = pattern.children[0];
3563
3576
  const lastChild = pattern.children[pattern.children.length - 1];
3564
3577
  const isLongEnough = pattern.children.length >= 2;
3565
- return pattern.type === "sequence" && isLongEnough &&
3566
- (firstChild.type === "reference" && firstChild.name === name) ||
3567
- (lastChild.type === "reference" && lastChild.name === name);
3578
+ return pattern.type === "reference" ||
3579
+ (pattern.type === "sequence" && isLongEnough &&
3580
+ (firstChild.type === "reference" && firstChild.name === name) ||
3581
+ (lastChild.type === "reference" && lastChild.name === name));
3568
3582
  }
3569
3583
  _buildPattern(node) {
3570
3584
  const type = node.name;