clarity-pattern-parser 10.1.21 → 10.1.23
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.browser.js +30 -9
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +30 -9
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +30 -9
- package/dist/index.js.map +1 -1
- package/dist/patterns/Reference.d.ts +1 -1
- package/dist/patterns/isRecursivePattern.d.ts +2 -0
- package/package.json +1 -1
- package/src/patterns/Context.ts +8 -1
- package/src/patterns/ExpressionPattern.ts +11 -3
- package/src/patterns/Options.ts +3 -2
- package/src/patterns/Reference.ts +4 -4
- package/src/patterns/Sequence.ts +3 -3
- package/src/patterns/isRecursivePattern.ts +21 -0
package/dist/index.browser.js
CHANGED
|
@@ -819,9 +819,9 @@
|
|
|
819
819
|
};
|
|
820
820
|
}
|
|
821
821
|
parse(cursor) {
|
|
822
|
-
return this.
|
|
822
|
+
return this.getReferencePatternSafely().parse(cursor);
|
|
823
823
|
}
|
|
824
|
-
|
|
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.
|
|
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.
|
|
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
|
|
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
|
|
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
|
|
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
|
|
1847
|
+
if (isRecursivePattern(pattern) && pattern === this._children[0]) {
|
|
1833
1848
|
return patterns;
|
|
1834
1849
|
}
|
|
1835
1850
|
patterns.push(...pattern.getPatterns());
|
|
@@ -2614,6 +2629,9 @@
|
|
|
2614
2629
|
return this._pattern.getTokens();
|
|
2615
2630
|
}
|
|
2616
2631
|
getTokensAfter(childReference) {
|
|
2632
|
+
if (this.parent == null) {
|
|
2633
|
+
return [];
|
|
2634
|
+
}
|
|
2617
2635
|
return this._pattern.getTokensAfter(childReference);
|
|
2618
2636
|
}
|
|
2619
2637
|
getNextTokens() {
|
|
@@ -2623,7 +2641,10 @@
|
|
|
2623
2641
|
return this._pattern.getPatterns();
|
|
2624
2642
|
}
|
|
2625
2643
|
getPatternsAfter(childReference) {
|
|
2626
|
-
|
|
2644
|
+
if (this.parent == null) {
|
|
2645
|
+
return [];
|
|
2646
|
+
}
|
|
2647
|
+
return this.parent.getPatternsAfter(childReference);
|
|
2627
2648
|
}
|
|
2628
2649
|
getNextPatterns() {
|
|
2629
2650
|
return this._pattern.getNextPatterns();
|