- // Implementations //////////////////////////////////////////////////////////////////////////////
-
- private static class MultiForest<T> extends IterableForest<T> {
- private final FastSet<Body<T>> results;
- private boolean valid;
- public boolean valid() { return valid; }
- private MultiForest(FastSet<Body<T>> results, boolean valid) { this.results = results; this.valid = valid; }
- public MultiForest(Token.Location loc, T tag, Forest<T>[] tokens, Sequence creator, boolean unwrap, boolean singleton) {
- this.results = new FastSet<Body<T>>(new Body(loc, tag, tokens, creator, unwrap, singleton));
- this.valid = true;
- }
- public Iterator<Body<T>> iterator() { return results.iterator(); }
-
- public HashSet<Tree<T>> expand(boolean toss) {
- HashSet<Tree<T>> ret = new HashSet<Tree<T>>();
- for(Body<T> b : results)
- ret.addAll(b.expand(toss, new ArrayList<Tree<T>>(), 0, new HashSet<Tree<T>>()));
- if (toss && ret.size() > 1) throw new Parser.Ambiguous(this);
- return ret;
- }
-
- // Display //////////////////////////////////////////////////////////////////////////////
-
- private String toString = null;
- public String toString() {
- if (toString != null) return toString;
- StringBuffer ret = new StringBuffer();
- ret.append("<?");
- boolean first = true;
- for(Forest.Body<T> r : results) {
- if (!first) ret.append(' ');
- first = false;
- ret.append(r);
+ 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)));; }
+ public void start(T head, Input.Location loc) { }
+ public void addTree(Tree<T> t) { toks.add(t); }
+ }
+ private static abstract class TreeMaker<T> implements Invokable<Forest.Body<T>,Boolean,Integer>, TreeConsumer<T> {
+ public ArrayList<Tree<T>> toks = new ArrayList<Tree<T>>();
+ 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);
+ 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>>();
+ bod.expand(0, this);
+ this.toks = toks;
+ } else {
+ bod.expand(i, this);