clarity-pattern-parser 11.0.7 → 11.0.8
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 -53
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +30 -53
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +30 -53
- package/dist/index.js.map +1 -1
- package/dist/patterns/Expression.d.ts +0 -1
- package/dist/patterns/Options.d.ts +0 -1
- package/dist/patterns/Reference.d.ts +4 -0
- package/dist/patterns/Sequence.d.ts +0 -1
- package/package.json +1 -1
- package/src/patterns/Expression.ts +0 -24
- package/src/patterns/Options.test.ts +2 -1
- package/src/patterns/Options.ts +0 -22
- package/src/patterns/Reference.ts +41 -0
- package/src/patterns/Sequence.ts +0 -23
package/dist/index.js
CHANGED
|
@@ -848,6 +848,8 @@ class Reference {
|
|
|
848
848
|
this._cachedPattern = null;
|
|
849
849
|
this._children = [];
|
|
850
850
|
this._firstIndex = 0;
|
|
851
|
+
this._cachedAncestors = false;
|
|
852
|
+
this._recursiveAncestors = [];
|
|
851
853
|
}
|
|
852
854
|
test(text, record = false) {
|
|
853
855
|
return testPattern(this, text, record);
|
|
@@ -857,8 +859,36 @@ class Reference {
|
|
|
857
859
|
}
|
|
858
860
|
parse(cursor) {
|
|
859
861
|
this._firstIndex = cursor.index;
|
|
862
|
+
this._cacheAncestors();
|
|
863
|
+
if (this._isBeyondRecursiveAllowance()) {
|
|
864
|
+
cursor.recordErrorAt(this._firstIndex, this._firstIndex, this);
|
|
865
|
+
return null;
|
|
866
|
+
}
|
|
860
867
|
return this.getReferencePatternSafely().parse(cursor);
|
|
861
868
|
}
|
|
869
|
+
_cacheAncestors() {
|
|
870
|
+
if (!this._cachedAncestors) {
|
|
871
|
+
let pattern = this.parent;
|
|
872
|
+
while (pattern != null) {
|
|
873
|
+
if (pattern.type === this.type && pattern.id === this._id) {
|
|
874
|
+
this._recursiveAncestors.push(pattern);
|
|
875
|
+
}
|
|
876
|
+
pattern = pattern.parent;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
_isBeyondRecursiveAllowance() {
|
|
881
|
+
let depth = 0;
|
|
882
|
+
for (let pattern of this._recursiveAncestors) {
|
|
883
|
+
if (pattern._firstIndex === this._firstIndex) {
|
|
884
|
+
depth++;
|
|
885
|
+
if (depth > 2) {
|
|
886
|
+
return true;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
return false;
|
|
891
|
+
}
|
|
862
892
|
getReferencePatternSafely() {
|
|
863
893
|
if (this._pattern === null) {
|
|
864
894
|
let pattern = null;
|
|
@@ -1044,9 +1074,6 @@ class Options {
|
|
|
1044
1074
|
return null;
|
|
1045
1075
|
}
|
|
1046
1076
|
_tryToParse(cursor) {
|
|
1047
|
-
if (this._isBeyondRecursiveAllowance()) {
|
|
1048
|
-
return null;
|
|
1049
|
-
}
|
|
1050
1077
|
const results = [];
|
|
1051
1078
|
for (const pattern of this._children) {
|
|
1052
1079
|
cursor.moveTo(this._firstIndex);
|
|
@@ -1064,20 +1091,6 @@ class Options {
|
|
|
1064
1091
|
nonNullResults.sort((a, b) => b.endIndex - a.endIndex);
|
|
1065
1092
|
return nonNullResults[0] || null;
|
|
1066
1093
|
}
|
|
1067
|
-
_isBeyondRecursiveAllowance() {
|
|
1068
|
-
let depth = 0;
|
|
1069
|
-
let pattern = this;
|
|
1070
|
-
while (pattern != null) {
|
|
1071
|
-
if (pattern.id === this.id && pattern.startedOnIndex === this.startedOnIndex) {
|
|
1072
|
-
depth++;
|
|
1073
|
-
}
|
|
1074
|
-
if (depth > 2) {
|
|
1075
|
-
return true;
|
|
1076
|
-
}
|
|
1077
|
-
pattern = pattern.parent;
|
|
1078
|
-
}
|
|
1079
|
-
return false;
|
|
1080
|
-
}
|
|
1081
1094
|
getTokens() {
|
|
1082
1095
|
const tokens = [];
|
|
1083
1096
|
for (const pattern of this._children) {
|
|
@@ -1733,10 +1746,6 @@ class Sequence {
|
|
|
1733
1746
|
return null;
|
|
1734
1747
|
}
|
|
1735
1748
|
tryToParse(cursor) {
|
|
1736
|
-
if (this._isBeyondRecursiveAllowance()) {
|
|
1737
|
-
cursor.recordErrorAt(this._firstIndex, this._firstIndex, this);
|
|
1738
|
-
return false;
|
|
1739
|
-
}
|
|
1740
1749
|
let passed = false;
|
|
1741
1750
|
for (let i = 0; i < this._children.length; i++) {
|
|
1742
1751
|
const runningCursorIndex = cursor.index;
|
|
@@ -1800,20 +1809,6 @@ class Sequence {
|
|
|
1800
1809
|
}
|
|
1801
1810
|
return nodes[nodes.length - 1];
|
|
1802
1811
|
}
|
|
1803
|
-
_isBeyondRecursiveAllowance() {
|
|
1804
|
-
let depth = 0;
|
|
1805
|
-
let pattern = this;
|
|
1806
|
-
while (pattern != null) {
|
|
1807
|
-
if (pattern.id === this.id && pattern.startedOnIndex === this.startedOnIndex) {
|
|
1808
|
-
depth++;
|
|
1809
|
-
}
|
|
1810
|
-
if (depth > 1) {
|
|
1811
|
-
return true;
|
|
1812
|
-
}
|
|
1813
|
-
pattern = pattern.parent;
|
|
1814
|
-
}
|
|
1815
|
-
return false;
|
|
1816
|
-
}
|
|
1817
1812
|
areRemainingPatternsOptional(fromIndex) {
|
|
1818
1813
|
const startOnIndex = fromIndex + 1;
|
|
1819
1814
|
const length = this._children.length;
|
|
@@ -3057,10 +3052,6 @@ class Expression {
|
|
|
3057
3052
|
return null;
|
|
3058
3053
|
}
|
|
3059
3054
|
_tryToParse(cursor) {
|
|
3060
|
-
if (this._isBeyondRecursiveAllowance()) {
|
|
3061
|
-
cursor.recordErrorAt(this._firstIndex, this._firstIndex, this);
|
|
3062
|
-
return null;
|
|
3063
|
-
}
|
|
3064
3055
|
this._shouldStopParsing = false;
|
|
3065
3056
|
while (true) {
|
|
3066
3057
|
cursor.resolveError();
|
|
@@ -3191,20 +3182,6 @@ class Expression {
|
|
|
3191
3182
|
this._shouldStopParsing = true;
|
|
3192
3183
|
}
|
|
3193
3184
|
}
|
|
3194
|
-
_isBeyondRecursiveAllowance() {
|
|
3195
|
-
let depth = 0;
|
|
3196
|
-
let pattern = this;
|
|
3197
|
-
while (pattern != null) {
|
|
3198
|
-
if (pattern.id === this.id && pattern.startedOnIndex === this.startedOnIndex) {
|
|
3199
|
-
depth++;
|
|
3200
|
-
}
|
|
3201
|
-
if (depth > 2) {
|
|
3202
|
-
return true;
|
|
3203
|
-
}
|
|
3204
|
-
pattern = pattern.parent;
|
|
3205
|
-
}
|
|
3206
|
-
return false;
|
|
3207
|
-
}
|
|
3208
3185
|
test(text, record = false) {
|
|
3209
3186
|
return testPattern(this, text, record);
|
|
3210
3187
|
}
|