clarity-pattern-parser 11.0.3 → 11.0.4
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 -6
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +26 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +26 -6
- package/dist/index.js.map +1 -1
- package/dist/patterns/PrecedenceTree.d.ts +1 -1
- package/package.json +1 -1
- package/src/patterns/PrecedenceTree.test.ts +113 -1
- package/src/patterns/PrecedenceTree.ts +35 -7
package/dist/index.esm.js
CHANGED
|
@@ -2711,9 +2711,9 @@ class PrecedenceTree {
|
|
|
2711
2711
|
this._binaryPlaceholder = Node.createNode("placeholder", "binary-placeholder");
|
|
2712
2712
|
this._atomNode = null;
|
|
2713
2713
|
this._binaryNode = null;
|
|
2714
|
-
this._orphanedAtom = null;
|
|
2715
2714
|
this._precedenceMap = precedenceMap;
|
|
2716
2715
|
this._associationMap = associationMap;
|
|
2716
|
+
this._revertBinary = () => { };
|
|
2717
2717
|
}
|
|
2718
2718
|
addPrefix(name, ...prefix) {
|
|
2719
2719
|
const lastPrefixNode = this._prefixNode;
|
|
@@ -2748,15 +2748,22 @@ class PrecedenceTree {
|
|
|
2748
2748
|
throw new Error("Cannot add a binary without an atom node.");
|
|
2749
2749
|
}
|
|
2750
2750
|
this._binaryPlaceholder.remove();
|
|
2751
|
-
this._orphanedAtom = lastAtomNode;
|
|
2752
2751
|
if (lastBinaryNode == null) {
|
|
2753
2752
|
const node = Node.createNode("expression", name, [lastAtomNode, ...delimiterNode, this._binaryPlaceholder]);
|
|
2754
2753
|
this._binaryNode = node;
|
|
2754
|
+
this._revertBinary = () => {
|
|
2755
|
+
lastAtomNode.remove();
|
|
2756
|
+
this._binaryNode = lastAtomNode;
|
|
2757
|
+
};
|
|
2755
2758
|
return;
|
|
2756
2759
|
}
|
|
2757
2760
|
if (precedence === lastPrecendece && association === Association.right) {
|
|
2758
2761
|
const node = Node.createNode("expression", name, [lastAtomNode, ...delimiterNode, this._binaryPlaceholder]);
|
|
2759
2762
|
lastBinaryNode.appendChild(node);
|
|
2763
|
+
this._revertBinary = () => {
|
|
2764
|
+
node.replaceWith(lastAtomNode);
|
|
2765
|
+
this._binaryNode = lastBinaryNode;
|
|
2766
|
+
};
|
|
2760
2767
|
this._binaryNode = node;
|
|
2761
2768
|
}
|
|
2762
2769
|
else if (precedence === lastPrecendece) {
|
|
@@ -2764,6 +2771,11 @@ class PrecedenceTree {
|
|
|
2764
2771
|
lastBinaryNode.replaceWith(node);
|
|
2765
2772
|
lastBinaryNode.appendChild(lastAtomNode);
|
|
2766
2773
|
node.append(lastBinaryNode, ...delimiterNode, this._binaryPlaceholder);
|
|
2774
|
+
this._revertBinary = () => {
|
|
2775
|
+
lastBinaryNode.remove();
|
|
2776
|
+
node.replaceWith(lastBinaryNode);
|
|
2777
|
+
this._binaryNode = lastBinaryNode;
|
|
2778
|
+
};
|
|
2767
2779
|
this._binaryNode = node;
|
|
2768
2780
|
}
|
|
2769
2781
|
else if (precedence > lastPrecendece) {
|
|
@@ -2781,11 +2793,21 @@ class PrecedenceTree {
|
|
|
2781
2793
|
const node = Node.createNode("expression", name, []);
|
|
2782
2794
|
root.replaceWith(node);
|
|
2783
2795
|
node.append(root, ...delimiterNode, this._binaryPlaceholder);
|
|
2796
|
+
this._revertBinary = () => {
|
|
2797
|
+
root.remove();
|
|
2798
|
+
node.replaceWith(root);
|
|
2799
|
+
this._binaryNode = root;
|
|
2800
|
+
};
|
|
2784
2801
|
this._binaryNode = node;
|
|
2785
2802
|
}
|
|
2786
2803
|
else {
|
|
2787
2804
|
const node = Node.createNode("expression", name, [lastAtomNode, ...delimiterNode, this._binaryPlaceholder]);
|
|
2788
2805
|
lastBinaryNode.appendChild(node);
|
|
2806
|
+
this._revertBinary = () => {
|
|
2807
|
+
lastAtomNode.remove();
|
|
2808
|
+
node.replaceWith(lastAtomNode);
|
|
2809
|
+
this._binaryNode = lastBinaryNode;
|
|
2810
|
+
};
|
|
2789
2811
|
this._binaryNode = node;
|
|
2790
2812
|
}
|
|
2791
2813
|
}
|
|
@@ -2826,14 +2848,13 @@ class PrecedenceTree {
|
|
|
2826
2848
|
return this._atomNode != null;
|
|
2827
2849
|
}
|
|
2828
2850
|
commit() {
|
|
2829
|
-
var _a;
|
|
2830
2851
|
if (this._binaryNode == null) {
|
|
2831
2852
|
return this._compileAtomNode();
|
|
2832
2853
|
}
|
|
2833
2854
|
const atomNode = this._compileAtomNode();
|
|
2834
2855
|
if (atomNode == null) {
|
|
2835
|
-
|
|
2836
|
-
|
|
2856
|
+
this._revertBinary();
|
|
2857
|
+
let root = this._binaryNode.findRoot();
|
|
2837
2858
|
this.reset();
|
|
2838
2859
|
return root;
|
|
2839
2860
|
}
|
|
@@ -2847,7 +2868,6 @@ class PrecedenceTree {
|
|
|
2847
2868
|
reset() {
|
|
2848
2869
|
this._prefixNode = null;
|
|
2849
2870
|
this._atomNode = null;
|
|
2850
|
-
this._orphanedAtom = null;
|
|
2851
2871
|
this._postfixNode = null;
|
|
2852
2872
|
this._binaryNode = null;
|
|
2853
2873
|
}
|