checkpoint
authoradam <adam@megacz.com>
Wed, 5 Jul 2006 00:26:49 +0000 (20:26 -0400)
committeradam <adam@megacz.com>
Wed, 5 Jul 2006 00:26:49 +0000 (20:26 -0400)
darcs-hash:20060705002649-5007d-dedd077450906dd2a768f21fd7c63235444e4691.gz

src/edu/berkeley/sbp/misc/Demo.java
src/edu/berkeley/sbp/misc/RegressionTests.java
src/edu/berkeley/sbp/tib/TibDoc.java

index 2b99ffb..b6c0524 100644 (file)
@@ -89,13 +89,13 @@ public class Demo {
             return false;
         }
         public Object repeatTag() {
             return false;
         }
         public Object repeatTag() {
-            return new Reducer() {
+            return new Functor<Iterable<Tree>,Object>() {
                     public String toString() { return ""; }
                     public String toString() { return ""; }
-                    public Object reduce(Iterable<Tree> t) {
+                    public Object invoke(Iterable<Tree> t) {
                         ArrayList ret = new ArrayList();
                         for(Tree tc : t) {
                         ArrayList ret = new ArrayList();
                         for(Tree tc : t) {
-                            if (tc.head() != null && tc.head() instanceof Reducer)
-                                ret.add(((Reducer)tc.head()).reduce(tc.children()));
+                            if (tc.head() != null && tc.head() instanceof Functor)
+                                ret.add(((Functor<Iterable<Tree>,Object>)tc.head()).invoke(tc.children()));
                             else if (tc.numChildren() == 0)
                                 ret.add(tc.head());
                             else {
                             else if (tc.numChildren() == 0)
                                 ret.add(tc.head());
                             else {
@@ -242,7 +242,7 @@ public class Demo {
         public abstract Object plant(Object[] fields, int[] map);
         public boolean isRaw() { return false; }
         public Object invokeRaw(Iterable<Tree> t) { return null; }
         public abstract Object plant(Object[] fields, int[] map);
         public boolean isRaw() { return false; }
         public Object invokeRaw(Iterable<Tree> t) { return null; }
-        public class TargetReducer implements Reducer {
+        public class TargetReducer implements Functor<Iterable<Tree>,Object> {
             private Production p;
             private int[] map;
             private String name;
             private Production p;
             private int[] map;
             private String name;
@@ -252,12 +252,12 @@ public class Demo {
                 this.name = name;
             }
             public String toString() { return name; }
                 this.name = name;
             }
             public String toString() { return name; }
-            public Object reduce(Iterable<Tree> t) {
+            public Object invoke(Iterable<Tree> t) {
                 if (isRaw()) return invokeRaw(t);
                 ArrayList ret = new ArrayList();
                 for(Tree tc : t) {
                 if (isRaw()) return invokeRaw(t);
                 ArrayList ret = new ArrayList();
                 for(Tree tc : t) {
-                    if (tc.head() != null && tc.head() instanceof Reducer)
-                        ret.add(((Reducer)tc.head()).reduce(tc.children()));
+                    if (tc.head() != null && tc.head() instanceof Functor)
+                        ret.add(((Functor<Iterable<Tree>,Object>)tc.head()).invoke(tc.children()));
                     else if (tc.numChildren() == 0)
                         ret.add(tc.head());
                     else {
                     else if (tc.numChildren() == 0)
                         ret.add(tc.head());
                     else {
@@ -271,10 +271,6 @@ public class Demo {
         }
     }
 
         }
     }
 
-    public static interface Reducer {
-        public Object reduce(Iterable<Tree> t);
-    }
-
     public static class TargetClass extends Target {
         public final Class _class;
         public TargetClass(Class _class) { this._class = _class; }
     public static class TargetClass extends Target {
         public final Class _class;
         public TargetClass(Class _class) { this._class = _class; }
@@ -485,8 +481,8 @@ public class Demo {
     }
     public static Union make(Tree t, String s) { return make(t, s, new ReflectiveMeta()); }
     public static Union make(Tree t, String s, ReflectiveMeta rm) {
     }
     public static Union make(Tree t, String s) { return make(t, s, new ReflectiveMeta()); }
     public static Union make(Tree t, String s, ReflectiveMeta rm) {
-        Reducer red = (Reducer)t.head();
-        MG.Grammar g = (MG.Grammar)red.reduce(t.children());
+        Functor<Iterable<Tree>,Object> red = (Functor<Iterable<Tree>,Object>)t.head();
+        MG.Grammar g = (MG.Grammar)red.invoke(t.children());
         Context cx = new Context(g,rm);
         Union u = null;
         for(MG.NonTerminal nt : g.nonterminals) {
         Context cx = new Context(g,rm);
         Union u = null;
         for(MG.NonTerminal nt : g.nonterminals) {
@@ -785,8 +781,8 @@ public class Demo {
         }
         public Context(Tree t, ReflectiveMeta rm) {
             this.rm = rm;
         }
         public Context(Tree t, ReflectiveMeta rm) {
             this.rm = rm;
-            Reducer red = (Reducer)t.head();
-            this.grammar = (MG.Grammar)red.reduce(t.children());
+            Functor<Iterable<Tree>,Object> red = (Functor<Iterable<Tree>,Object>)t.head();
+            this.grammar = (MG.Grammar)red.invoke(t.children());
         }
         public Union peek(String name) { return map.get(name); }
         public void  put(String name, Union u) { map.put(name, u); }
         }
         public Union peek(String name) { return map.get(name); }
         public void  put(String name, Union u) { map.put(name, u); }
index dc52644..02a5eee 100644 (file)
@@ -59,7 +59,7 @@ public class RegressionTests {
             System.err.println("expanding...");
 
             Tree t = r2.expand1();
             System.err.println("expanding...");
 
             Tree t = r2.expand1();
-            TestCase[] expanded = (TestCase[])((Demo.Reducer)t.head()).reduce(t.children());
+            TestCase[] expanded = (TestCase[])((Functor)t.head()).invoke(t.children());
             System.err.println("executing...");
             for(TestCase tc : expanded) {
                 tc.execute();
             System.err.println("executing...");
             for(TestCase tc : expanded) {
                 tc.execute();
index 00ef9ce..a32c529 100644 (file)
@@ -522,8 +522,7 @@ toContex ll = prefix ++ (concatMap tl ll) ++ suffix
             Tree t = new CharParser(tibgram).parse(new Tib(new FileInputStream(s[1]))).expand1();
             System.out.println("tree:\n" + t.toPrettyString());
             
             Tree t = new CharParser(tibgram).parse(new Tib(new FileInputStream(s[1]))).expand1();
             System.out.println("tree:\n" + t.toPrettyString());
             
-            Reducer red = (Reducer)t.head();
-            Object result = red.reduce(t);
+            Object result = ((Functor)t.head()).invoke(t);
             System.out.println((TD.Doc)result);
             /*
             System.out.println("parsing " + s[0]);
             System.out.println((TD.Doc)result);
             /*
             System.out.println("parsing " + s[0]);