clarity-pattern-parser 11.3.3 → 11.3.5

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.js CHANGED
@@ -910,7 +910,7 @@ class Reference {
910
910
  for (let pattern of this._recursiveAncestors) {
911
911
  if (pattern.startedOnIndex === this.startedOnIndex) {
912
912
  depth++;
913
- if (depth > 0) {
913
+ if (depth > 1) {
914
914
  return true;
915
915
  }
916
916
  }
@@ -2829,6 +2829,7 @@ class Expression {
2829
2829
  this._hasOrganized = false;
2830
2830
  this._patterns = [];
2831
2831
  this._precedenceTree = new PrecedenceTree({}, {});
2832
+ this._atomsIdToAncestorsMap = {};
2832
2833
  }
2833
2834
  _organizePatterns(patterns) {
2834
2835
  const finalPatterns = [];
@@ -2875,6 +2876,19 @@ class Expression {
2875
2876
  this._precedenceTree = new PrecedenceTree(this._precedenceMap, this._associationMap);
2876
2877
  return finalPatterns;
2877
2878
  }
2879
+ _cacheAncestors() {
2880
+ for (let atom of this._atomPatterns) {
2881
+ const id = atom.id;
2882
+ const ancestors = this._atomsIdToAncestorsMap[id] = [];
2883
+ let pattern = this.parent;
2884
+ while (pattern != null) {
2885
+ if (pattern.id === id) {
2886
+ ancestors.push(pattern);
2887
+ }
2888
+ pattern = pattern.parent;
2889
+ }
2890
+ }
2891
+ }
2878
2892
  _extractName(pattern) {
2879
2893
  if (pattern.type === "right-associated") {
2880
2894
  return pattern.children[0].name;
@@ -2951,6 +2965,7 @@ class Expression {
2951
2965
  if (!this._hasOrganized) {
2952
2966
  this._hasOrganized = true;
2953
2967
  this._organizePatterns(this._originalPatterns);
2968
+ this._cacheAncestors();
2954
2969
  }
2955
2970
  }
2956
2971
  parse(cursor) {
@@ -3031,6 +3046,9 @@ class Expression {
3031
3046
  for (let i = 0; i < this._atomPatterns.length; i++) {
3032
3047
  cursor.moveTo(onIndex);
3033
3048
  const pattern = this._atomPatterns[i];
3049
+ if (this._isBeyondRecursiveAllowance(pattern, onIndex)) {
3050
+ continue;
3051
+ }
3034
3052
  const node = pattern.parse(cursor);
3035
3053
  if (node != null) {
3036
3054
  this._precedenceTree.addAtom(node);
@@ -3048,6 +3066,10 @@ class Expression {
3048
3066
  }
3049
3067
  }
3050
3068
  }
3069
+ _isBeyondRecursiveAllowance(atom, onIndex) {
3070
+ const ancestors = this._atomsIdToAncestorsMap[atom.id];
3071
+ return ancestors.some(a => a.startedOnIndex === onIndex);
3072
+ }
3051
3073
  _tryToMatchPostfix(cursor) {
3052
3074
  let onIndex = cursor.index;
3053
3075
  for (let i = 0; i < this._postfixPatterns.length; i++) {