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.
@@ -912,7 +912,7 @@
912
912
  for (let pattern of this._recursiveAncestors) {
913
913
  if (pattern.startedOnIndex === this.startedOnIndex) {
914
914
  depth++;
915
- if (depth > 0) {
915
+ if (depth > 1) {
916
916
  return true;
917
917
  }
918
918
  }
@@ -2831,6 +2831,7 @@
2831
2831
  this._hasOrganized = false;
2832
2832
  this._patterns = [];
2833
2833
  this._precedenceTree = new PrecedenceTree({}, {});
2834
+ this._atomsIdToAncestorsMap = {};
2834
2835
  }
2835
2836
  _organizePatterns(patterns) {
2836
2837
  const finalPatterns = [];
@@ -2877,6 +2878,19 @@
2877
2878
  this._precedenceTree = new PrecedenceTree(this._precedenceMap, this._associationMap);
2878
2879
  return finalPatterns;
2879
2880
  }
2881
+ _cacheAncestors() {
2882
+ for (let atom of this._atomPatterns) {
2883
+ const id = atom.id;
2884
+ const ancestors = this._atomsIdToAncestorsMap[id] = [];
2885
+ let pattern = this.parent;
2886
+ while (pattern != null) {
2887
+ if (pattern.id === id) {
2888
+ ancestors.push(pattern);
2889
+ }
2890
+ pattern = pattern.parent;
2891
+ }
2892
+ }
2893
+ }
2880
2894
  _extractName(pattern) {
2881
2895
  if (pattern.type === "right-associated") {
2882
2896
  return pattern.children[0].name;
@@ -2953,6 +2967,7 @@
2953
2967
  if (!this._hasOrganized) {
2954
2968
  this._hasOrganized = true;
2955
2969
  this._organizePatterns(this._originalPatterns);
2970
+ this._cacheAncestors();
2956
2971
  }
2957
2972
  }
2958
2973
  parse(cursor) {
@@ -3033,6 +3048,9 @@
3033
3048
  for (let i = 0; i < this._atomPatterns.length; i++) {
3034
3049
  cursor.moveTo(onIndex);
3035
3050
  const pattern = this._atomPatterns[i];
3051
+ if (this._isBeyondRecursiveAllowance(pattern, onIndex)) {
3052
+ continue;
3053
+ }
3036
3054
  const node = pattern.parse(cursor);
3037
3055
  if (node != null) {
3038
3056
  this._precedenceTree.addAtom(node);
@@ -3050,6 +3068,10 @@
3050
3068
  }
3051
3069
  }
3052
3070
  }
3071
+ _isBeyondRecursiveAllowance(atom, onIndex) {
3072
+ const ancestors = this._atomsIdToAncestorsMap[atom.id];
3073
+ return ancestors.some(a => a.startedOnIndex === onIndex);
3074
+ }
3053
3075
  _tryToMatchPostfix(cursor) {
3054
3076
  let onIndex = cursor.index;
3055
3077
  for (let i = 0; i < this._postfixPatterns.length; i++) {