/** expand this forest into a set of trees */
public abstract HashSet<Tree<T>> expand(boolean toss);
- public abstract boolean empty();
- static <T> Forest<T> singleton(Token.Location loc, Sequence creator) { return create(loc, null, new Forest[] { }, creator, false, true); }
- static <T> Forest<T> singleton(Token.Location loc, Forest<T> body, Sequence creator) { return create(loc, null, new Forest[] { body }, creator, false, true); }
- static <T> Forest<T> leaf(Token.Location loc, T tag, Sequence creator) { return create(loc, tag, null, creator, false, false); }
- public static <T> Forest<T> create(Token.Location loc, T tag, Forest<T>[] tokens, Sequence creator, boolean unwrap, boolean singleton) {
- return new MultiForest<T>(loc, tag, tokens, creator, unwrap, singleton);
+ static <T> Forest<T> singleton(Token.Location loc) { return create(loc, null, new Forest[] { }, false, true); }
+ static <T> Forest<T> singleton(Token.Location loc, Forest<T> body) { return create(loc, null, new Forest[] { body }, false, true); }
+ static <T> Forest<T> leaf(Token.Location loc, T tag) { return create(loc, tag, null, false, false); }
+ public static <T> Forest<T> create(Token.Location loc, T tag, Forest<T>[] tokens, boolean unwrap, boolean singleton) {
+ return new MultiForest<T>(loc, tag, tokens, unwrap, singleton);
}
// Body //////////////////////////////////////////////////////////////////////////////
private final Token.Location location;
private final T tag;
private final Forest<T>[] tokens;
- private final Sequence creator;
private final boolean unwrap;
private final boolean singleton;
- private Body(Token.Location loc, T tag, Forest<T>[] tokens, Sequence creator, boolean unwrap, boolean singleton) {
+ private Body(Token.Location loc, T tag, Forest<T>[] tokens, boolean unwrap, boolean singleton) {
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.creator = creator;
this.unwrap = unwrap;
this.singleton = singleton;
}
* viewed, it becomes immutable
*/
static class Ref<T> extends IterableForest<T> {
- public boolean empty() {
- if (res!=null) return res.empty();
- for(Forest f : hp) if (!f.empty()) return false;
- return true;
- }
private FastSet<Forest> hp = new FastSet<Forest>();
private Forest res = null;
public Ref() { }
// Implementations //////////////////////////////////////////////////////////////////////////////
private static class MultiForest<T> extends IterableForest<T> {
- public boolean empty() { return results.size()>0; }
private final FastSet<Body<T>> results;
private MultiForest(FastSet<Body<T>> results) { this.results = results; }
- public MultiForest(Token.Location loc, T tag, Forest<T>[] tokens, Sequence creator, boolean unwrap, boolean singleton) {
- this.results = new FastSet<Body<T>>(new Body(loc, tag, tokens, creator, unwrap, singleton));
+ public MultiForest(Token.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(); }