clarity-pattern-parser 10.1.21 → 10.1.22

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.
@@ -819,9 +819,9 @@
819
819
  };
820
820
  }
821
821
  parse(cursor) {
822
- return this._getPatternSafely().parse(cursor);
822
+ return this.getReferencePatternSafely().parse(cursor);
823
823
  }
824
- _getPatternSafely() {
824
+ getReferencePatternSafely() {
825
825
  if (this._pattern === null) {
826
826
  let pattern = null;
827
827
  if (this._cachedPattern == null) {
@@ -881,7 +881,7 @@
881
881
  return node;
882
882
  }
883
883
  getTokens() {
884
- return this._getPatternSafely().getTokens();
884
+ return this.getReferencePatternSafely().getTokens();
885
885
  }
886
886
  getTokensAfter(_lastMatched) {
887
887
  if (this._parent == null) {
@@ -896,7 +896,7 @@
896
896
  return this.parent.getTokensAfter(this);
897
897
  }
898
898
  getPatterns() {
899
- return this._getPatternSafely().getPatterns();
899
+ return this.getReferencePatternSafely().getPatterns();
900
900
  }
901
901
  getPatternsAfter(_childReference) {
902
902
  if (this._parent == null) {
@@ -954,6 +954,21 @@
954
954
  }
955
955
  }
956
956
 
957
+ function isRecursivePattern(pattern) {
958
+ let onPattern = pattern.parent;
959
+ let depth = 0;
960
+ while (onPattern != null) {
961
+ if (onPattern.id === pattern.id) {
962
+ depth++;
963
+ }
964
+ onPattern = onPattern.parent;
965
+ if (depth > 1) {
966
+ return true;
967
+ }
968
+ }
969
+ return false;
970
+ }
971
+
957
972
  /*
958
973
  The following is created to reduce the overhead of recursion check.
959
974
  */
@@ -1051,7 +1066,7 @@
1051
1066
  getTokens() {
1052
1067
  const tokens = [];
1053
1068
  for (const pattern of this._children) {
1054
- if (pattern.type === "reference" && pattern.name === this.name) {
1069
+ if (isRecursivePattern(pattern)) {
1055
1070
  continue;
1056
1071
  }
1057
1072
  tokens.push(...pattern.getTokens());
@@ -1073,7 +1088,7 @@
1073
1088
  getPatterns() {
1074
1089
  const patterns = [];
1075
1090
  for (const pattern of this._children) {
1076
- if (pattern.type === "reference" && pattern.name === this.name) {
1091
+ if (isRecursivePattern(pattern)) {
1077
1092
  continue;
1078
1093
  }
1079
1094
  patterns.push(...pattern.getPatterns());
@@ -1804,7 +1819,7 @@
1804
1819
  getTokens() {
1805
1820
  const tokens = [];
1806
1821
  for (const pattern of this._children) {
1807
- if (pattern.type === "reference" && pattern.name === this.name && pattern === this.children[0]) {
1822
+ if (isRecursivePattern(pattern) && pattern === this._children[0]) {
1808
1823
  return tokens;
1809
1824
  }
1810
1825
  tokens.push(...pattern.getTokens());
@@ -1829,7 +1844,7 @@
1829
1844
  getPatterns() {
1830
1845
  const patterns = [];
1831
1846
  for (const pattern of this._children) {
1832
- if (pattern.type === "reference" && pattern.name === this.name && pattern === this.children[0]) {
1847
+ if (isRecursivePattern(pattern) && pattern === this._children[0]) {
1833
1848
  return patterns;
1834
1849
  }
1835
1850
  patterns.push(...pattern.getPatterns());