clarity-pattern-parser 10.2.4 → 10.2.5
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 -5
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +25 -5
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +25 -5
- package/dist/index.js.map +1 -1
- package/dist/patterns/ExpressionPattern.d.ts +2 -0
- package/package.json +1 -1
- package/src/patterns/ExpressionPattern.ts +32 -8
package/dist/index.js
CHANGED
|
@@ -2736,6 +2736,7 @@ class ExpressionPattern {
|
|
|
2736
2736
|
this._binaryPatterns = [];
|
|
2737
2737
|
this._recursivePatterns = [];
|
|
2738
2738
|
this._recursiveNames = [];
|
|
2739
|
+
this._endsInRecursion = [];
|
|
2739
2740
|
this._binaryNames = [];
|
|
2740
2741
|
this._binaryAssociation = [];
|
|
2741
2742
|
this._precedenceMap = {};
|
|
@@ -2769,6 +2770,7 @@ class ExpressionPattern {
|
|
|
2769
2770
|
tail.parent = this;
|
|
2770
2771
|
this._recursivePatterns.push(tail);
|
|
2771
2772
|
this._recursiveNames.push(name);
|
|
2773
|
+
this._endsInRecursion.push(this._endsWithRecursion(pattern));
|
|
2772
2774
|
finalPatterns.push(tail);
|
|
2773
2775
|
}
|
|
2774
2776
|
else {
|
|
@@ -2824,6 +2826,16 @@ class ExpressionPattern {
|
|
|
2824
2826
|
}
|
|
2825
2827
|
return new Sequence(`${pattern.name}-tail`, pattern.children.slice(1));
|
|
2826
2828
|
}
|
|
2829
|
+
_endsWithRecursion(pattern) {
|
|
2830
|
+
if (pattern.type === "right-associated") {
|
|
2831
|
+
pattern = pattern.children[0];
|
|
2832
|
+
}
|
|
2833
|
+
const lastChild = pattern.children[pattern.children.length - 1];
|
|
2834
|
+
return pattern.type === "sequence" &&
|
|
2835
|
+
pattern.children.length > 1 &&
|
|
2836
|
+
lastChild.type === "reference" &&
|
|
2837
|
+
lastChild.name === this.name;
|
|
2838
|
+
}
|
|
2827
2839
|
parse(cursor) {
|
|
2828
2840
|
// This is a cache to help with speed
|
|
2829
2841
|
this._firstIndex = cursor.index;
|
|
@@ -2883,11 +2895,19 @@ class ExpressionPattern {
|
|
|
2883
2895
|
if (lastBinaryNode != null && lastUnaryNode != null) {
|
|
2884
2896
|
lastBinaryNode.appendChild(lastUnaryNode);
|
|
2885
2897
|
}
|
|
2886
|
-
const frontExpression = lastBinaryNode == null ? lastUnaryNode : lastBinaryNode.findRoot();
|
|
2887
2898
|
const name = this._recursiveNames[i];
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2899
|
+
if (this._endsInRecursion[i]) {
|
|
2900
|
+
const frontExpression = lastBinaryNode == null ? lastUnaryNode : lastBinaryNode.findRoot();
|
|
2901
|
+
const recursiveNode = createNode(name, [frontExpression, ...node.children]);
|
|
2902
|
+
recursiveNode.normalize(this._firstIndex);
|
|
2903
|
+
return recursiveNode;
|
|
2904
|
+
}
|
|
2905
|
+
else {
|
|
2906
|
+
const recursiveNode = createNode(name, [lastUnaryNode, ...node.children]);
|
|
2907
|
+
recursiveNode.normalize(this._firstIndex);
|
|
2908
|
+
lastUnaryNode = recursiveNode;
|
|
2909
|
+
break;
|
|
2910
|
+
}
|
|
2891
2911
|
}
|
|
2892
2912
|
cursor.moveTo(onIndex);
|
|
2893
2913
|
}
|
|
@@ -2915,7 +2935,7 @@ class ExpressionPattern {
|
|
|
2915
2935
|
}
|
|
2916
2936
|
else if (lastBinaryNode != null && lastUnaryNode != null && delimiterNode != null) {
|
|
2917
2937
|
const precedence = this._precedenceMap[name];
|
|
2918
|
-
const lastPrecendece = lastBinaryNode == null ? 0 : this._precedenceMap[lastBinaryNode.name];
|
|
2938
|
+
const lastPrecendece = lastBinaryNode == null ? 0 : this._precedenceMap[lastBinaryNode.name] || -1;
|
|
2919
2939
|
const association = this._binaryAssociation[i];
|
|
2920
2940
|
if (precedence === lastPrecendece && association === Association.right) {
|
|
2921
2941
|
const node = createNode(name, [lastUnaryNode, delimiterNode]);
|