- for(int i=0; i<tokens.length; i++) {
- if (i==tokens.length-1 && unwrap && !tokens[i].ambiguous()) {
- tokens[i].edges(n);
- } else {
- n.edge(tokens[i], labels==null?null:labels[i]);
- }
- }
- }
-
- public <B,C> void visit(Invokable<Forest.Body<T>,B,C> ivbc, B b, C c) {
- ivbc.invoke(this, b, c);
- }
-
- private final Input.Location location;
- private final T tag;
- private final Forest<T>[] tokens;
- private final Object[] labels;
- private final boolean unwrap;
- private final boolean singleton;
- private final Sequence.Position reduction;
-
- private MyBody(Input.Location loc, T tag, Forest<T>[] tokens, Object[] labels, boolean unwrap, boolean singleton, Position reduction) {
- this.location = loc;
- this.tag = tag;
- this.tokens = tokens==null ? emptyForestArray : new Forest[tokens.length];
- if (tokens != null) System.arraycopy(tokens, 0, this.tokens, 0, tokens.length);
- if (tokens != null) for(int i=0; i<tokens.length; i++) if (tokens[i]==null) throw new Error(i+"");
- this.unwrap = unwrap;
- this.singleton = singleton;
- this.reduction = reduction;
- this.labels = labels;
- }
- public void gather(TaskList tl, HashSet<Tree<T>>[] ht, HashSet<Tree<T>> target) {
- gather(tl, ht, target, new Tree[ht.length], 0);
- }
- private void gather(TaskList tl, HashSet<Tree<T>>[] ht, HashSet<Tree<T>> target, Tree[] trees, int i) {
- if (i==ht.length) {
- target.add(new Tree<T>(null, tag, trees));
- return;
- }
- for(Tree<T> tree : ht[i]) {
- if (unwrap && i==trees.length-1) {
- // I think this is wrong
- Tree[] trees2 = new Tree[trees.length - 1 + tree.numChildren()];
- System.arraycopy(trees, 0, trees2, 0, trees.length-1);
- for(int j=0; j<tree.numChildren(); j++)
- trees2[trees.length-1+j] = tree.child(j);
- target.add(new Tree<T>(null, tag, trees2));