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.esm.js
CHANGED
|
@@ -2732,6 +2732,7 @@ class ExpressionPattern {
|
|
|
2732
2732
|
this._binaryPatterns = [];
|
|
2733
2733
|
this._recursivePatterns = [];
|
|
2734
2734
|
this._recursiveNames = [];
|
|
2735
|
+
this._endsInRecursion = [];
|
|
2735
2736
|
this._binaryNames = [];
|
|
2736
2737
|
this._binaryAssociation = [];
|
|
2737
2738
|
this._precedenceMap = {};
|
|
@@ -2765,6 +2766,7 @@ class ExpressionPattern {
|
|
|
2765
2766
|
tail.parent = this;
|
|
2766
2767
|
this._recursivePatterns.push(tail);
|
|
2767
2768
|
this._recursiveNames.push(name);
|
|
2769
|
+
this._endsInRecursion.push(this._endsWithRecursion(pattern));
|
|
2768
2770
|
finalPatterns.push(tail);
|
|
2769
2771
|
}
|
|
2770
2772
|
else {
|
|
@@ -2820,6 +2822,16 @@ class ExpressionPattern {
|
|
|
2820
2822
|
}
|
|
2821
2823
|
return new Sequence(`${pattern.name}-tail`, pattern.children.slice(1));
|
|
2822
2824
|
}
|
|
2825
|
+
_endsWithRecursion(pattern) {
|
|
2826
|
+
if (pattern.type === "right-associated") {
|
|
2827
|
+
pattern = pattern.children[0];
|
|
2828
|
+
}
|
|
2829
|
+
const lastChild = pattern.children[pattern.children.length - 1];
|
|
2830
|
+
return pattern.type === "sequence" &&
|
|
2831
|
+
pattern.children.length > 1 &&
|
|
2832
|
+
lastChild.type === "reference" &&
|
|
2833
|
+
lastChild.name === this.name;
|
|
2834
|
+
}
|
|
2823
2835
|
parse(cursor) {
|
|
2824
2836
|
// This is a cache to help with speed
|
|
2825
2837
|
this._firstIndex = cursor.index;
|
|
@@ -2879,11 +2891,19 @@ class ExpressionPattern {
|
|
|
2879
2891
|
if (lastBinaryNode != null && lastUnaryNode != null) {
|
|
2880
2892
|
lastBinaryNode.appendChild(lastUnaryNode);
|
|
2881
2893
|
}
|
|
2882
|
-
const frontExpression = lastBinaryNode == null ? lastUnaryNode : lastBinaryNode.findRoot();
|
|
2883
2894
|
const name = this._recursiveNames[i];
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2895
|
+
if (this._endsInRecursion[i]) {
|
|
2896
|
+
const frontExpression = lastBinaryNode == null ? lastUnaryNode : lastBinaryNode.findRoot();
|
|
2897
|
+
const recursiveNode = createNode(name, [frontExpression, ...node.children]);
|
|
2898
|
+
recursiveNode.normalize(this._firstIndex);
|
|
2899
|
+
return recursiveNode;
|
|
2900
|
+
}
|
|
2901
|
+
else {
|
|
2902
|
+
const recursiveNode = createNode(name, [lastUnaryNode, ...node.children]);
|
|
2903
|
+
recursiveNode.normalize(this._firstIndex);
|
|
2904
|
+
lastUnaryNode = recursiveNode;
|
|
2905
|
+
break;
|
|
2906
|
+
}
|
|
2887
2907
|
}
|
|
2888
2908
|
cursor.moveTo(onIndex);
|
|
2889
2909
|
}
|
|
@@ -2911,7 +2931,7 @@ class ExpressionPattern {
|
|
|
2911
2931
|
}
|
|
2912
2932
|
else if (lastBinaryNode != null && lastUnaryNode != null && delimiterNode != null) {
|
|
2913
2933
|
const precedence = this._precedenceMap[name];
|
|
2914
|
-
const lastPrecendece = lastBinaryNode == null ? 0 : this._precedenceMap[lastBinaryNode.name];
|
|
2934
|
+
const lastPrecendece = lastBinaryNode == null ? 0 : this._precedenceMap[lastBinaryNode.name] || -1;
|
|
2915
2935
|
const association = this._binaryAssociation[i];
|
|
2916
2936
|
if (precedence === lastPrecendece && association === Association.right) {
|
|
2917
2937
|
const node = createNode(name, [lastUnaryNode, delimiterNode]);
|