- // Implementations //////////////////////////////////////////////////////////////////////////////
-
- private static class MultiForest<T> extends Forest<T> {
- private final FastSet<Body<T>> results;
- private MultiForest(FastSet<Body<T>> results) { this.results = results; }
- public MultiForest(Input.Location loc, T tag, Forest<T>[] tokens, boolean unwrap, boolean singleton) {
- this.results = new FastSet<Body<T>>(new Body(loc, tag, tokens, unwrap, singleton));
- }
- 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 Ambiguous(this);
- return ret;
+ public abstract <B,C> void visit(Invokable<Forest.Body<T>,B,C> ivbc, B b, C c);
+ 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;
+ 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 child(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);
+ }