- final HashSet<Tree<T>> hs = new HashSet<Tree<T>>();
- TreeMaker<T> ret = new TreeMaker<T>(toss) {
- public void start(T head, Input.Location loc) { }
- public void finish(T head, Input.Location loc) { hs.add(new Tree<T>(loc, head, toks.toArray(tree_hint))); }
- public void child(Tree<T> t) { toks.add(t); }
- };
- visit(ret, null, null);
- if (toss && hs.size() > 1) throw new Ambiguous(this);
- return hs;
+ final HashSetTreeConsumer<T> ret = new HashSetTreeConsumer<T>();
+ visit(new TreeMaker2<T>(toss, ret), null, null);
+ if (toss && ret.size() > 1) throw new Ambiguous(this);
+ return ret;
+ }
+
+ public static interface TreeConsumer<T> {
+ public void addTree(Tree<T> t);
+ }
+ public static class HashSetTreeConsumer<T> extends HashSet<Tree<T>> implements TreeConsumer<T> {
+ public void addTree(Tree<T> t) { super.add(t); }