- private Body(Token.Location loc, T tag, Forest<T>[] tokens, Sequence creator, 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;
- }
+ static <NodeType> Forest<NodeType> create(Input.Region region, NodeType head, Forest<NodeType>[] children,
+ boolean lift, boolean liftLeft) {
+ if (region == null) throw new RuntimeException("invoked Forest.create(region=null) -- this should never happen");
+ return new One<NodeType>(region, head, children, lift, liftLeft);
+ }
+
+ /** create a new forest */
+ public static <NodeType> Forest<NodeType> create(Input.Region region, NodeType head, Forest<NodeType>[] children) {
+ return Forest.create(region, head, children, false); }
+
+ abstract void expand(HashSet<Tree<NodeType>> ht, HashSet<Forest<NodeType>> ignore, Tree<NodeType> bogus);
+ abstract void gather(HashSet<Forest<NodeType>> ignore);
+ abstract void edges(GraphViz.Node n);
+ boolean ambiguous() { return false; }
+
+ // One //////////////////////////////////////////////////////////////////////////////
+
+ /** A "single" forest with a head and child subforests */
+ private static class One<NodeType> extends Forest<NodeType> {
+
+ private final Input.Region location;
+ private final NodeType head;
+ private final Forest<NodeType>[] children;
+
+ /** if true, the last child's children are considered children of this node */
+ private final boolean lift;
+ private final boolean liftLeft;