X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Fmisc%2FDemo.java;h=dbe62666eea7a2def2f2664eb76da1edcfc68bf1;hb=80a840adb5df31ba5edd20ecac23086ad09a5ca1;hp=2b99ffbe3bf33c5c1ffee506e08aaddc8d42cf04;hpb=03e1f20f869819893205ec771571b2c62ab00421;p=sbp.git diff --git a/src/edu/berkeley/sbp/misc/Demo.java b/src/edu/berkeley/sbp/misc/Demo.java index 2b99ffb..dbe6266 100644 --- a/src/edu/berkeley/sbp/misc/Demo.java +++ b/src/edu/berkeley/sbp/misc/Demo.java @@ -89,23 +89,7 @@ public class Demo { return false; } public Object repeatTag() { - return new Reducer() { - public String toString() { return ""; } - public Object reduce(Iterable 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())); - else if (tc.numChildren() == 0) - ret.add(tc.head()); - else { - System.err.println("FIXME: don't know what to do about " + tc); - ret.add(null); - } - } - return ret.toArray(new Object[0]); - } - }; + return new Tree.ArrayBuildingTreeFunctor(); } public Sequence tryResolveTag(String tag, String nonTerminalName, Element[] els, Object[] labels, boolean[] drops) { Production p = new Production(tag, nonTerminalName, els, labels, drops); @@ -242,7 +226,7 @@ public class Demo { public abstract Object plant(Object[] fields, int[] map); public boolean isRaw() { return false; } public Object invokeRaw(Iterable t) { return null; } - public class TargetReducer implements Reducer { + public class TargetReducer implements Functor,Object> { private Production p; private int[] map; private String name; @@ -252,12 +236,12 @@ public class Demo { this.name = name; } public String toString() { return name; } - public Object reduce(Iterable t) { + public Object invoke(Iterable 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,Object>)tc.head()).invoke(tc.children())); else if (tc.numChildren() == 0) ret.add(tc.head()); else { @@ -271,10 +255,6 @@ public class Demo { } } - public static interface Reducer { - public Object reduce(Iterable t); - } - public static class TargetClass extends Target { public final Class _class; public TargetClass(Class _class) { this._class = _class; } @@ -485,8 +465,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) { - Reducer red = (Reducer)t.head(); - MG.Grammar g = (MG.Grammar)red.reduce(t.children()); + Functor,Object> red = (Functor,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) { @@ -785,8 +765,8 @@ public class Demo { } public Context(Tree t, ReflectiveMeta rm) { this.rm = rm; - Reducer red = (Reducer)t.head(); - this.grammar = (MG.Grammar)red.reduce(t.children()); + Functor,Object> red = (Functor,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); }