clarity-pattern-parser 11.0.18 → 11.0.20
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 +26 -12
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +26 -12
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +26 -12
- package/dist/index.js.map +1 -1
- package/dist/patterns/Expression.d.ts +1 -0
- package/package.json +1 -1
- package/src/grammar/Grammar.ts +6 -5
- package/src/patterns/Expression.ts +27 -8
package/dist/index.browser.js
CHANGED
|
@@ -2924,12 +2924,10 @@
|
|
|
2924
2924
|
this._associationMap = {};
|
|
2925
2925
|
this._precedenceMap = {};
|
|
2926
2926
|
this._originalPatterns = patterns;
|
|
2927
|
-
this._patterns = this._organizePatterns(patterns);
|
|
2928
2927
|
this._shouldStopParsing = false;
|
|
2929
|
-
this.
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
}
|
|
2928
|
+
this._hasOrganized = false;
|
|
2929
|
+
this._patterns = [];
|
|
2930
|
+
this._precedenceTree = new PrecedenceTree({}, {});
|
|
2933
2931
|
}
|
|
2934
2932
|
_organizePatterns(patterns) {
|
|
2935
2933
|
const finalPatterns = [];
|
|
@@ -2972,6 +2970,8 @@
|
|
|
2972
2970
|
finalPatterns.push(binary);
|
|
2973
2971
|
}
|
|
2974
2972
|
});
|
|
2973
|
+
this._patterns = finalPatterns;
|
|
2974
|
+
this._precedenceTree = new PrecedenceTree(this._precedenceMap, this._associationMap);
|
|
2975
2975
|
return finalPatterns;
|
|
2976
2976
|
}
|
|
2977
2977
|
_extractName(pattern) {
|
|
@@ -3028,7 +3028,10 @@
|
|
|
3028
3028
|
}
|
|
3029
3029
|
_unwrapAssociationIfNecessary(pattern) {
|
|
3030
3030
|
if (pattern.type === "right-associated") {
|
|
3031
|
-
|
|
3031
|
+
pattern = pattern.children[0];
|
|
3032
|
+
}
|
|
3033
|
+
if (pattern.type === "reference") {
|
|
3034
|
+
pattern = pattern.getReferencePatternSafely();
|
|
3032
3035
|
}
|
|
3033
3036
|
return pattern;
|
|
3034
3037
|
}
|
|
@@ -3039,10 +3042,20 @@
|
|
|
3039
3042
|
if (pattern == null) {
|
|
3040
3043
|
return false;
|
|
3041
3044
|
}
|
|
3042
|
-
return pattern.
|
|
3045
|
+
return pattern.name === this.name;
|
|
3043
3046
|
}
|
|
3044
3047
|
parse(cursor) {
|
|
3045
3048
|
this._firstIndex = cursor.index;
|
|
3049
|
+
if (!this._hasOrganized) {
|
|
3050
|
+
this._hasOrganized = true;
|
|
3051
|
+
this._organizePatterns(this._originalPatterns);
|
|
3052
|
+
}
|
|
3053
|
+
// If there are not any atom nodes then nothing can be found.
|
|
3054
|
+
if (this._atomPatterns.length < 1) {
|
|
3055
|
+
cursor.moveTo(this._firstIndex);
|
|
3056
|
+
cursor.recordErrorAt(this._firstIndex, this._firstIndex, this);
|
|
3057
|
+
return null;
|
|
3058
|
+
}
|
|
3046
3059
|
const node = this._tryToParse(cursor);
|
|
3047
3060
|
if (node != null) {
|
|
3048
3061
|
node.normalize(this._firstIndex);
|
|
@@ -3550,8 +3563,8 @@
|
|
|
3550
3563
|
return options;
|
|
3551
3564
|
}
|
|
3552
3565
|
_isRecursive(name, pattern) {
|
|
3553
|
-
if (pattern.type === "right-associated"
|
|
3554
|
-
|
|
3566
|
+
if (pattern.type === "right-associated") {
|
|
3567
|
+
pattern = pattern.children[0];
|
|
3555
3568
|
}
|
|
3556
3569
|
return this._isRecursivePattern(name, pattern);
|
|
3557
3570
|
}
|
|
@@ -3562,9 +3575,10 @@
|
|
|
3562
3575
|
const firstChild = pattern.children[0];
|
|
3563
3576
|
const lastChild = pattern.children[pattern.children.length - 1];
|
|
3564
3577
|
const isLongEnough = pattern.children.length >= 2;
|
|
3565
|
-
return pattern.type === "
|
|
3566
|
-
(
|
|
3567
|
-
|
|
3578
|
+
return pattern.type === "reference" ||
|
|
3579
|
+
(pattern.type === "sequence" && isLongEnough &&
|
|
3580
|
+
(firstChild.name === name) ||
|
|
3581
|
+
(lastChild.name === name));
|
|
3568
3582
|
}
|
|
3569
3583
|
_buildPattern(node) {
|
|
3570
3584
|
const type = node.name;
|