UnwrapLeft, error reporting improvements
[sbp.git] / src / edu / berkeley / sbp / Forest.java
index cf64ed2..34982bd 100644 (file)
@@ -28,11 +28,18 @@ public abstract class Forest<NodeType> implements GraphViz.ToGraphViz {
 
     // Package-Private //////////////////////////////////////////////////////////////////////////////
 
-    static <NodeType> Forest<NodeType> create(Input.Region region, NodeType head, Forest<NodeType>[] children, boolean lift) {
+    static <NodeType> Forest<NodeType> create(Input.Region region, NodeType head, Forest<NodeType>[] children,
+                                              boolean lift) {
         if (region == null) throw new RuntimeException("invoked Forest.create(region=null) -- this should never happen");
         return new One<NodeType>(region, head, children, lift);
     }
 
+    static <NodeType> Forest<NodeType> create(Input.Region region, NodeType head, Forest<NodeType>[] children,
+                                              boolean lift, boolean liftLeft) {
+        if (region == null) throw new RuntimeException("invoked Forest.create(region=null) -- this should never happen");
+        return new One<NodeType>(region, head, children, lift, liftLeft);
+    }
+
     /** create a new forest */
     public static <NodeType> Forest<NodeType> create(Input.Region region, NodeType head, Forest<NodeType>[] children) {
         return Forest.create(region, head, children, false); }
@@ -53,10 +60,14 @@ public abstract class Forest<NodeType> implements GraphViz.ToGraphViz {
 
         /** if true, the last child's children are considered children of this node */
         private final boolean           lift;
+        private final boolean           liftLeft;
 
         public Input.Region getRegion() { return location; }
 
         private One(Input.Region loc, NodeType head, Forest<NodeType>[] children, boolean lift) {
+            this(loc, head, children, lift, false);
+        }
+        private One(Input.Region loc, NodeType head, Forest<NodeType>[] children, boolean lift, boolean liftLeft) {
             this.location = loc;
             this.head = head;
             if (head==null) throw new RuntimeException("invoked Forest.create(,null,,,) -- this should never happen");
@@ -64,12 +75,13 @@ public abstract class Forest<NodeType> implements GraphViz.ToGraphViz {
             if (children != null) System.arraycopy(children, 0, this.children, 0, children.length);
             if (children != null) for(int i=0; i<children.length; i++) if (children[i]==null) throw new Error(i+"");
             this.lift = lift;
+            this.liftLeft = liftLeft;
         }
 
         public Tree<NodeType> expand1() throws Ambiguous {
             Tree<NodeType>[] ret = new Tree[children.length];
             for(int i=0; i<children.length; i++) ret[i] = children[i].expand1();
-            return new Tree<NodeType>(location, head, ret, lift);
+            return new Tree<NodeType>(location, head, ret, lift, liftLeft);
         }
 
         void gather(HashSet<Forest<NodeType>> hf) {
@@ -83,7 +95,7 @@ public abstract class Forest<NodeType> implements GraphViz.ToGraphViz {
         private void expand(final int i, Tree<NodeType>[] ta, HashSet<Tree<NodeType>> ht, HashSet<Forest<NodeType>> ignore,
                             Tree<NodeType> bogus) {
             if (i==children.length) {
-                ht.add(new Tree<NodeType>(location, head, ta, lift));
+                ht.add(new Tree<NodeType>(location, head, ta, lift, liftLeft));
             } else {
                 HashSet<Tree<NodeType>> ht2 = new HashSet<Tree<NodeType>>();
                 children[i].expand(ht2, ignore, bogus);