clarity-pattern-parser 10.1.20 → 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.
- package/dist/index.browser.js +39 -12
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +39 -12
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +39 -12
- 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/intellisense/AutoComplete.test.ts +85 -0
- package/src/patterns/ExpressionPattern.ts +36 -1
- package/src/patterns/Options.ts +9 -2
- package/src/patterns/Reference.ts +4 -4
- package/src/patterns/RightAssociatedPattern.ts +71 -0
- package/src/patterns/Sequence.ts +14 -6
- 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
|
*/
|
|
@@ -1048,8 +1063,11 @@ class Options {
|
|
|
1048
1063
|
}
|
|
1049
1064
|
getTokens() {
|
|
1050
1065
|
const tokens = [];
|
|
1051
|
-
for (const
|
|
1052
|
-
|
|
1066
|
+
for (const pattern of this._children) {
|
|
1067
|
+
if (isRecursivePattern(pattern)) {
|
|
1068
|
+
continue;
|
|
1069
|
+
}
|
|
1070
|
+
tokens.push(...pattern.getTokens());
|
|
1053
1071
|
}
|
|
1054
1072
|
return tokens;
|
|
1055
1073
|
}
|
|
@@ -1068,6 +1086,9 @@ class Options {
|
|
|
1068
1086
|
getPatterns() {
|
|
1069
1087
|
const patterns = [];
|
|
1070
1088
|
for (const pattern of this._children) {
|
|
1089
|
+
if (isRecursivePattern(pattern)) {
|
|
1090
|
+
continue;
|
|
1091
|
+
}
|
|
1071
1092
|
patterns.push(...pattern.getPatterns());
|
|
1072
1093
|
}
|
|
1073
1094
|
return patterns;
|
|
@@ -1795,9 +1816,12 @@ class Sequence {
|
|
|
1795
1816
|
}
|
|
1796
1817
|
getTokens() {
|
|
1797
1818
|
const tokens = [];
|
|
1798
|
-
for (const
|
|
1799
|
-
|
|
1800
|
-
|
|
1819
|
+
for (const pattern of this._children) {
|
|
1820
|
+
if (isRecursivePattern(pattern) && pattern === this._children[0]) {
|
|
1821
|
+
return tokens;
|
|
1822
|
+
}
|
|
1823
|
+
tokens.push(...pattern.getTokens());
|
|
1824
|
+
if (pattern.type !== "optional" && pattern.type !== "not") {
|
|
1801
1825
|
break;
|
|
1802
1826
|
}
|
|
1803
1827
|
}
|
|
@@ -1817,9 +1841,12 @@ class Sequence {
|
|
|
1817
1841
|
}
|
|
1818
1842
|
getPatterns() {
|
|
1819
1843
|
const patterns = [];
|
|
1820
|
-
for (const
|
|
1821
|
-
|
|
1822
|
-
|
|
1844
|
+
for (const pattern of this._children) {
|
|
1845
|
+
if (isRecursivePattern(pattern) && pattern === this._children[0]) {
|
|
1846
|
+
return patterns;
|
|
1847
|
+
}
|
|
1848
|
+
patterns.push(...pattern.getPatterns());
|
|
1849
|
+
if (pattern.type !== "optional" && pattern.type !== "not") {
|
|
1823
1850
|
break;
|
|
1824
1851
|
}
|
|
1825
1852
|
}
|