clarity-pattern-parser 11.0.18 → 11.0.19
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 +25 -11
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +25 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +25 -11
- 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 +26 -7
package/dist/index.esm.js
CHANGED
|
@@ -2918,12 +2918,10 @@ class Expression {
|
|
|
2918
2918
|
this._associationMap = {};
|
|
2919
2919
|
this._precedenceMap = {};
|
|
2920
2920
|
this._originalPatterns = patterns;
|
|
2921
|
-
this._patterns = this._organizePatterns(patterns);
|
|
2922
2921
|
this._shouldStopParsing = false;
|
|
2923
|
-
this.
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
}
|
|
2922
|
+
this._hasOrganized = false;
|
|
2923
|
+
this._patterns = [];
|
|
2924
|
+
this._precedenceTree = new PrecedenceTree({}, {});
|
|
2927
2925
|
}
|
|
2928
2926
|
_organizePatterns(patterns) {
|
|
2929
2927
|
const finalPatterns = [];
|
|
@@ -2966,6 +2964,8 @@ class Expression {
|
|
|
2966
2964
|
finalPatterns.push(binary);
|
|
2967
2965
|
}
|
|
2968
2966
|
});
|
|
2967
|
+
this._patterns = finalPatterns;
|
|
2968
|
+
this._precedenceTree = new PrecedenceTree(this._precedenceMap, this._associationMap);
|
|
2969
2969
|
return finalPatterns;
|
|
2970
2970
|
}
|
|
2971
2971
|
_extractName(pattern) {
|
|
@@ -3022,7 +3022,10 @@ class Expression {
|
|
|
3022
3022
|
}
|
|
3023
3023
|
_unwrapAssociationIfNecessary(pattern) {
|
|
3024
3024
|
if (pattern.type === "right-associated") {
|
|
3025
|
-
|
|
3025
|
+
pattern = pattern.children[0];
|
|
3026
|
+
}
|
|
3027
|
+
if (pattern.type === "reference") {
|
|
3028
|
+
pattern = pattern.getReferencePatternSafely();
|
|
3026
3029
|
}
|
|
3027
3030
|
return pattern;
|
|
3028
3031
|
}
|
|
@@ -3037,6 +3040,16 @@ class Expression {
|
|
|
3037
3040
|
}
|
|
3038
3041
|
parse(cursor) {
|
|
3039
3042
|
this._firstIndex = cursor.index;
|
|
3043
|
+
if (!this._hasOrganized) {
|
|
3044
|
+
this._hasOrganized = true;
|
|
3045
|
+
this._organizePatterns(this._originalPatterns);
|
|
3046
|
+
}
|
|
3047
|
+
// If there are not any atom nodes then nothing can be found.
|
|
3048
|
+
if (this._atomPatterns.length < 1) {
|
|
3049
|
+
cursor.moveTo(this._firstIndex);
|
|
3050
|
+
cursor.recordErrorAt(this._firstIndex, this._firstIndex, this);
|
|
3051
|
+
return null;
|
|
3052
|
+
}
|
|
3040
3053
|
const node = this._tryToParse(cursor);
|
|
3041
3054
|
if (node != null) {
|
|
3042
3055
|
node.normalize(this._firstIndex);
|
|
@@ -3544,8 +3557,8 @@ class Grammar {
|
|
|
3544
3557
|
return options;
|
|
3545
3558
|
}
|
|
3546
3559
|
_isRecursive(name, pattern) {
|
|
3547
|
-
if (pattern.type === "right-associated"
|
|
3548
|
-
|
|
3560
|
+
if (pattern.type === "right-associated") {
|
|
3561
|
+
pattern = pattern.children[0];
|
|
3549
3562
|
}
|
|
3550
3563
|
return this._isRecursivePattern(name, pattern);
|
|
3551
3564
|
}
|
|
@@ -3556,9 +3569,10 @@ class Grammar {
|
|
|
3556
3569
|
const firstChild = pattern.children[0];
|
|
3557
3570
|
const lastChild = pattern.children[pattern.children.length - 1];
|
|
3558
3571
|
const isLongEnough = pattern.children.length >= 2;
|
|
3559
|
-
return pattern.type === "
|
|
3560
|
-
(
|
|
3561
|
-
|
|
3572
|
+
return pattern.type === "reference" ||
|
|
3573
|
+
(pattern.type === "sequence" && isLongEnough &&
|
|
3574
|
+
(firstChild.type === "reference" && firstChild.name === name) ||
|
|
3575
|
+
(lastChild.type === "reference" && lastChild.name === name));
|
|
3562
3576
|
}
|
|
3563
3577
|
_buildPattern(node) {
|
|
3564
3578
|
const type = node.name;
|