+ private final T head;
+ private final Forest<T>[] children;
+
+ /** if true, the last child's children are considered children of this node */
+ private final boolean lift;
+
+ private One(Input.Region loc, T head, Forest<T>[] children, boolean lift) {
+ this.location = loc;
+ this.head = head;
+ this.children = children==null ? emptyForestArray : new Forest[children.length];
+ if (children != null) System.arraycopy(children, 0, this.children, 0, children.length);
+ if (children != null) for(int i=0; i<children.length; i++) if (children[i]==null) throw new Error(i+"");
+ this.lift = lift;
+ }
+
+ public Tree<T> expand1() throws Ambiguous {
+ Tree<T>[] ret = new Tree[children.length];
+ for(int i=0; i<children.length; i++) ret[i] = children[i].expand1();
+ return new Tree<T>(location, head, ret, lift);
+ }
+
+ void gather(HashSet<Forest<T>> hf) {
+ hf.add(this);
+ for(Forest<T> f : children) f.gather(hf);
+ }
+ void expand(HashSet<Tree<T>> ht, HashSet<Forest<T>> ignore, Tree<T> bogus) {
+ if (ignore.contains(this)) { ht.add(bogus); return; }
+ expand(0, new Tree[children.length], ht, ignore, bogus);
+ }
+ private void expand(final int i, Tree<T>[] ta, HashSet<Tree<T>> ht, HashSet<Forest<T>> ignore, Tree<T> bogus) {
+ if (i==children.length) {
+ ht.add(new Tree<T>(location, head, ta, lift));
+ } else {
+ HashSet<Tree<T>> ht2 = new HashSet<Tree<T>>();
+ children[i].expand(ht2, ignore, bogus);
+ for(Tree<T> tc : ht2) {
+ ta[i] = tc;
+ expand(i+1, ta, ht, ignore, bogus);
+ ta[i] = null;
+ }
+ }
+ }
+
+ // GraphViz, ToInt //////////////////////////////////////////////////////////////////////////////