clarity-pattern-parser 10.2.4 → 10.2.6
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.browser.js
CHANGED
|
@@ -2738,6 +2738,7 @@
|
|
|
2738
2738
|
this._binaryPatterns = [];
|
|
2739
2739
|
this._recursivePatterns = [];
|
|
2740
2740
|
this._recursiveNames = [];
|
|
2741
|
+
this._endsInRecursion = [];
|
|
2741
2742
|
this._binaryNames = [];
|
|
2742
2743
|
this._binaryAssociation = [];
|
|
2743
2744
|
this._precedenceMap = {};
|
|
@@ -2771,6 +2772,7 @@
|
|
|
2771
2772
|
tail.parent = this;
|
|
2772
2773
|
this._recursivePatterns.push(tail);
|
|
2773
2774
|
this._recursiveNames.push(name);
|
|
2775
|
+
this._endsInRecursion.push(this._endsWithRecursion(pattern));
|
|
2774
2776
|
finalPatterns.push(tail);
|
|
2775
2777
|
}
|
|
2776
2778
|
else {
|
|
@@ -2826,6 +2828,16 @@
|
|
|
2826
2828
|
}
|
|
2827
2829
|
return new Sequence(`${pattern.name}-tail`, pattern.children.slice(1));
|
|
2828
2830
|
}
|
|
2831
|
+
_endsWithRecursion(pattern) {
|
|
2832
|
+
if (pattern.type === "right-associated") {
|
|
2833
|
+
pattern = pattern.children[0];
|
|
2834
|
+
}
|
|
2835
|
+
const lastChild = pattern.children[pattern.children.length - 1];
|
|
2836
|
+
return pattern.type === "sequence" &&
|
|
2837
|
+
pattern.children.length > 1 &&
|
|
2838
|
+
lastChild.type === "reference" &&
|
|
2839
|
+
lastChild.name === this.name;
|
|
2840
|
+
}
|
|
2829
2841
|
parse(cursor) {
|
|
2830
2842
|
// This is a cache to help with speed
|
|
2831
2843
|
this._firstIndex = cursor.index;
|
|
@@ -2885,11 +2897,19 @@
|
|
|
2885
2897
|
if (lastBinaryNode != null && lastUnaryNode != null) {
|
|
2886
2898
|
lastBinaryNode.appendChild(lastUnaryNode);
|
|
2887
2899
|
}
|
|
2888
|
-
const frontExpression = lastBinaryNode == null ? lastUnaryNode : lastBinaryNode.findRoot();
|
|
2889
2900
|
const name = this._recursiveNames[i];
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2901
|
+
if (this._endsInRecursion[i]) {
|
|
2902
|
+
const frontExpression = lastBinaryNode == null ? lastUnaryNode : lastBinaryNode.findRoot();
|
|
2903
|
+
const recursiveNode = createNode(name, [frontExpression, ...node.children]);
|
|
2904
|
+
recursiveNode.normalize(this._firstIndex);
|
|
2905
|
+
return recursiveNode;
|
|
2906
|
+
}
|
|
2907
|
+
else {
|
|
2908
|
+
const recursiveNode = createNode(name, [lastUnaryNode, ...node.children]);
|
|
2909
|
+
recursiveNode.normalize(lastUnaryNode.startIndex);
|
|
2910
|
+
lastUnaryNode = recursiveNode;
|
|
2911
|
+
break;
|
|
2912
|
+
}
|
|
2893
2913
|
}
|
|
2894
2914
|
cursor.moveTo(onIndex);
|
|
2895
2915
|
}
|
|
@@ -2917,7 +2937,7 @@
|
|
|
2917
2937
|
}
|
|
2918
2938
|
else if (lastBinaryNode != null && lastUnaryNode != null && delimiterNode != null) {
|
|
2919
2939
|
const precedence = this._precedenceMap[name];
|
|
2920
|
-
const lastPrecendece = lastBinaryNode == null ? 0 : this._precedenceMap[lastBinaryNode.name];
|
|
2940
|
+
const lastPrecendece = lastBinaryNode == null ? 0 : this._precedenceMap[lastBinaryNode.name] || -1;
|
|
2921
2941
|
const association = this._binaryAssociation[i];
|
|
2922
2942
|
if (precedence === lastPrecendece && association === Association.right) {
|
|
2923
2943
|
const node = createNode(name, [lastUnaryNode, delimiterNode]);
|