-
- // Display //////////////////////////////////////////////////////////////////////////////
-
- private String toString = null;
- public String toString() {
- if (toString != null) return toString;
- StringBuffer ret = new StringBuffer();
- if (results.size()==1) {
- for(Forest.Body<T> r : results)
- ret.append(r);
- return toString = ret.toString();
- }
- ret.append("<?");
- boolean first = true;
- for(Forest.Body<T> r : results) {
- if (!first) ret.append(' ');
- first = false;
- ret.append(r);
+
+ public <B,C> void visit(Invokable<Forest.Body<T>,B,C> ivbc, B b, C c) {
+ if (hp==null) return;
+ for(Forest<T> f : hp)
+ f.visit(ivbc, b, c);
+ }
+ public Forest resolve() { return this; }
+ }
+
+ public abstract <B,C> void visit(Invokable<Forest.Body<T>,B,C> ivbc, B b, C c);
+ private static class TreeMaker2<T> extends TreeMaker<T> {
+ private TreeConsumer<T> tc;
+ public TreeMaker2(boolean toss, TreeConsumer<T> tc) { super(toss); this.tc = tc; }
+ public void finish(T head, Input.Location loc) { tc.addTree(new Tree<T>(loc, head, toks.toArray(tree_hint), labs.toArray(string_hint)));; }
+ public void start(T head, Input.Location loc) { }
+ public void addTree(Tree<T> t, Object label) { toks.add(t); labs.add(label); }
+ }
+ private static abstract class TreeMaker<T> implements Invokable<Forest.Body<T>,Boolean,Integer>/*, TreeConsumer<T>*/ {
+ public ArrayList<Tree<T>> toks = new ArrayList<Tree<T>>();
+ public ArrayList<Object> labs = new ArrayList<Object>();
+ private boolean toss;
+ protected T head;
+ public TreeMaker(boolean toss) { this.toss = toss; }
+ public abstract void start(T head, Input.Location loc);
+ public abstract void finish(T head, Input.Location loc);
+ public abstract void addTree(Tree<T> t, Object label);
+ public void invoke(Forest.Body<T> bod, Boolean o, Integer i) {
+ if (i==null) {
+ ArrayList<Tree<T>> toks = this.toks;
+ this.toks = new ArrayList<Tree<T>>();
+ ArrayList<Object> labs = this.labs;
+ this.labs = new ArrayList<Object>();
+ bod.expand(0, this);
+ this.toks = toks;
+ this.labs = labs;
+ } else {
+ bod.expand(i, this);