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.esm.js CHANGED
@@ -906,7 +906,7 @@ class Reference {
906
906
  for (let pattern of this._recursiveAncestors) {
907
907
  if (pattern.startedOnIndex === this.startedOnIndex) {
908
908
  depth++;
909
- if (depth > 0) {
909
+ if (depth > 1) {
910
910
  return true;
911
911
  }
912
912
  }
@@ -2825,6 +2825,7 @@ class Expression {
2825
2825
  this._hasOrganized = false;
2826
2826
  this._patterns = [];
2827
2827
  this._precedenceTree = new PrecedenceTree({}, {});
2828
+ this._atomsIdToAncestorsMap = {};
2828
2829
  }
2829
2830
  _organizePatterns(patterns) {
2830
2831
  const finalPatterns = [];
@@ -2871,6 +2872,19 @@ class Expression {
2871
2872
  this._precedenceTree = new PrecedenceTree(this._precedenceMap, this._associationMap);
2872
2873
  return finalPatterns;
2873
2874
  }
2875
+ _cacheAncestors() {
2876
+ for (let atom of this._atomPatterns) {
2877
+ const id = atom.id;
2878
+ const ancestors = this._atomsIdToAncestorsMap[id] = [];
2879
+ let pattern = this.parent;
2880
+ while (pattern != null) {
2881
+ if (pattern.id === id) {
2882
+ ancestors.push(pattern);
2883
+ }
2884
+ pattern = pattern.parent;
2885
+ }
2886
+ }
2887
+ }
2874
2888
  _extractName(pattern) {
2875
2889
  if (pattern.type === "right-associated") {
2876
2890
  return pattern.children[0].name;
@@ -2947,6 +2961,7 @@ class Expression {
2947
2961
  if (!this._hasOrganized) {
2948
2962
  this._hasOrganized = true;
2949
2963
  this._organizePatterns(this._originalPatterns);
2964
+ this._cacheAncestors();
2950
2965
  }
2951
2966
  }
2952
2967
  parse(cursor) {
@@ -3027,6 +3042,9 @@ class Expression {
3027
3042
  for (let i = 0; i < this._atomPatterns.length; i++) {
3028
3043
  cursor.moveTo(onIndex);
3029
3044
  const pattern = this._atomPatterns[i];
3045
+ if (this._isBeyondRecursiveAllowance(pattern, onIndex)) {
3046
+ continue;
3047
+ }
3030
3048
  const node = pattern.parse(cursor);
3031
3049
  if (node != null) {
3032
3050
  this._precedenceTree.addAtom(node);
@@ -3044,6 +3062,10 @@ class Expression {
3044
3062
  }
3045
3063
  }
3046
3064
  }
3065
+ _isBeyondRecursiveAllowance(atom, onIndex) {
3066
+ const ancestors = this._atomsIdToAncestorsMap[atom.id];
3067
+ return ancestors.some(a => a.startedOnIndex === onIndex);
3068
+ }
3047
3069
  _tryToMatchPostfix(cursor) {
3048
3070
  let onIndex = cursor.index;
3049
3071
  for (let i = 0; i < this._postfixPatterns.length; i++) {