- 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 expand(final int i, final TreeMaker<T> h) {
- if (singleton) {
- tokens[0].visit(h, null, i);
- return;
- }
- if (i==0) h.start(tag, location);
-
- if (i==tokens.length) {
- h.finish(tag, location);
-
- } else if (unwrap && i==tokens.length-1) {
- if (tokens[i] != null)
- tokens[i].visit(h, null, 0);
-
- } else {
- tokens[i].visit(new TreeMaker<T>(h.toss) {
- public void start(T head, Input.Location loc) { }
- public void addTree(Tree<T> t, Object label) { toks.add(t); labs.add(label); }
- public void finish(T head, Input.Location loc) {
- int old = h.toks.size();
- h.addTree(new Tree<T>(loc, head, toks.toArray(tree_hint), labs.toArray(string_hint)), labels==null?null:labels[i]);
- expand(i+1, h);
- while(h.toks.size() > old) h.toks.remove(h.toks.size()-1);
- while(h.labs.size() > old) h.labs.remove(h.labs.size()-1);
- }
- }, null, null);
- }
- }
-
- protected String headToString() { return tag==null?null:tag.toString(); }
- protected String headToJava() { return null; }