checkpoint
authoradam <adam@megacz.com>
Sun, 22 Jan 2006 09:49:39 +0000 (04:49 -0500)
committeradam <adam@megacz.com>
Sun, 22 Jan 2006 09:49:39 +0000 (04:49 -0500)
darcs-hash:20060122094939-5007d-7af168cdc6983d8bd61b0fbb67d8b3c9ede03345.gz

src/edu/berkeley/sbp/Forest.java

index 4de9fa8..5807545 100644 (file)
@@ -62,7 +62,7 @@ public abstract class Forest<T> /*extends PrintableTree<Forest.MyBody<T>>*/ impl
             this.singleton = singleton;
         }
 
-        public TreeMaker<T> expand(int i, TreeMaker<T> h) {
+        public TreeMaker<T> expand(final int i, final TreeMaker<T> h) {
             if (singleton) {
                 tokens[0].visit(h, null, i);
 
@@ -74,18 +74,14 @@ public abstract class Forest<T> /*extends PrintableTree<Forest.MyBody<T>>*/ impl
                     tokens[i].visit(h, null, 0);
 
             } else {
-                //boolean hit = false;
-                //tokens[i].visit(this, h, i);
-
-                for(Tree<T> r : tokens[i].expand(h.toss)) {
-                    //hit = true;
-                    int old = h.toks.size();
-                    h.toks.add(r);
-                    expand(i+1, h);
-                    while(h.toks.size() > old) h.toks.remove(h.toks.size()-1);
-                }
-
-                //if (!hit) throw new Error();
+                tokens[i].visit(new TreeMaker<T>(h.toss) {
+                    public void add(Tree<T> r) {
+                        int old = h.toks.size();
+                        h.toks.add(r);
+                        expand(i+1, h);
+                        while(h.toks.size() > old) h.toks.remove(h.toks.size()-1);
+                    }
+                }, null, null);
             }
             return h;
         }
@@ -126,7 +122,7 @@ public abstract class Forest<T> /*extends PrintableTree<Forest.MyBody<T>>*/ impl
     }
 
     public abstract <B,C> void visit(Invokable<Forest.Body<T>,B,C> ivbc, B b, C c);
-    private static abstract class TreeMaker<T> /*extends HashSet<Tree<T>>*/ implements Invokable<Forest.Body<T>,Boolean,Integer> {
+    private static abstract class TreeMaker<T> implements Invokable<Forest.Body<T>,Boolean,Integer> {
         public ArrayList<Tree<T>> toks = new ArrayList<Tree<T>>();
         private boolean toss;
         public TreeMaker(boolean toss) { this.toss = toss; }