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.js
CHANGED
|
@@ -817,9 +817,9 @@ class Reference {
|
|
|
817
817
|
};
|
|
818
818
|
}
|
|
819
819
|
parse(cursor) {
|
|
820
|
-
return this.
|
|
820
|
+
return this.getReferencePatternSafely().parse(cursor);
|
|
821
821
|
}
|
|
822
|
-
|
|
822
|
+
getReferencePatternSafely() {
|
|
823
823
|
if (this._pattern === null) {
|
|
824
824
|
let pattern = null;
|
|
825
825
|
if (this._cachedPattern == null) {
|
|
@@ -879,7 +879,7 @@ class Reference {
|
|
|
879
879
|
return node;
|
|
880
880
|
}
|
|
881
881
|
getTokens() {
|
|
882
|
-
return this.
|
|
882
|
+
return this.getReferencePatternSafely().getTokens();
|
|
883
883
|
}
|
|
884
884
|
getTokensAfter(_lastMatched) {
|
|
885
885
|
if (this._parent == null) {
|
|
@@ -894,7 +894,7 @@ class Reference {
|
|
|
894
894
|
return this.parent.getTokensAfter(this);
|
|
895
895
|
}
|
|
896
896
|
getPatterns() {
|
|
897
|
-
return this.
|
|
897
|
+
return this.getReferencePatternSafely().getPatterns();
|
|
898
898
|
}
|
|
899
899
|
getPatternsAfter(_childReference) {
|
|
900
900
|
if (this._parent == null) {
|
|
@@ -952,6 +952,21 @@ class DepthCache {
|
|
|
952
952
|
}
|
|
953
953
|
}
|
|
954
954
|
|
|
955
|
+
function isRecursivePattern(pattern) {
|
|
956
|
+
let onPattern = pattern.parent;
|
|
957
|
+
let depth = 0;
|
|
958
|
+
while (onPattern != null) {
|
|
959
|
+
if (onPattern.id === pattern.id) {
|
|
960
|
+
depth++;
|
|
961
|
+
}
|
|
962
|
+
onPattern = onPattern.parent;
|
|
963
|
+
if (depth > 1) {
|
|
964
|
+
return true;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
return false;
|
|
968
|
+
}
|
|
969
|
+
|
|
955
970
|
/*
|
|
956
971
|
The following is created to reduce the overhead of recursion check.
|
|
957
972
|
*/
|
|
@@ -1049,7 +1064,7 @@ class Options {
|
|
|
1049
1064
|
getTokens() {
|
|
1050
1065
|
const tokens = [];
|
|
1051
1066
|
for (const pattern of this._children) {
|
|
1052
|
-
if (pattern
|
|
1067
|
+
if (isRecursivePattern(pattern)) {
|
|
1053
1068
|
continue;
|
|
1054
1069
|
}
|
|
1055
1070
|
tokens.push(...pattern.getTokens());
|
|
@@ -1071,7 +1086,7 @@ class Options {
|
|
|
1071
1086
|
getPatterns() {
|
|
1072
1087
|
const patterns = [];
|
|
1073
1088
|
for (const pattern of this._children) {
|
|
1074
|
-
if (pattern
|
|
1089
|
+
if (isRecursivePattern(pattern)) {
|
|
1075
1090
|
continue;
|
|
1076
1091
|
}
|
|
1077
1092
|
patterns.push(...pattern.getPatterns());
|
|
@@ -1802,7 +1817,7 @@ class Sequence {
|
|
|
1802
1817
|
getTokens() {
|
|
1803
1818
|
const tokens = [];
|
|
1804
1819
|
for (const pattern of this._children) {
|
|
1805
|
-
if (pattern
|
|
1820
|
+
if (isRecursivePattern(pattern) && pattern === this._children[0]) {
|
|
1806
1821
|
return tokens;
|
|
1807
1822
|
}
|
|
1808
1823
|
tokens.push(...pattern.getTokens());
|
|
@@ -1827,7 +1842,7 @@ class Sequence {
|
|
|
1827
1842
|
getPatterns() {
|
|
1828
1843
|
const patterns = [];
|
|
1829
1844
|
for (const pattern of this._children) {
|
|
1830
|
-
if (pattern
|
|
1845
|
+
if (isRecursivePattern(pattern) && pattern === this._children[0]) {
|
|
1831
1846
|
return patterns;
|
|
1832
1847
|
}
|
|
1833
1848
|
patterns.push(...pattern.getPatterns());
|
|
@@ -2612,6 +2627,9 @@ class Context {
|
|
|
2612
2627
|
return this._pattern.getTokens();
|
|
2613
2628
|
}
|
|
2614
2629
|
getTokensAfter(childReference) {
|
|
2630
|
+
if (this.parent == null) {
|
|
2631
|
+
return [];
|
|
2632
|
+
}
|
|
2615
2633
|
return this._pattern.getTokensAfter(childReference);
|
|
2616
2634
|
}
|
|
2617
2635
|
getNextTokens() {
|
|
@@ -2621,7 +2639,10 @@ class Context {
|
|
|
2621
2639
|
return this._pattern.getPatterns();
|
|
2622
2640
|
}
|
|
2623
2641
|
getPatternsAfter(childReference) {
|
|
2624
|
-
|
|
2642
|
+
if (this.parent == null) {
|
|
2643
|
+
return [];
|
|
2644
|
+
}
|
|
2645
|
+
return this.parent.getPatternsAfter(childReference);
|
|
2625
2646
|
}
|
|
2626
2647
|
getNextPatterns() {
|
|
2627
2648
|
return this._pattern.getNextPatterns();
|