- // Implementations //////////////////////////////////////////////////////////////////////////////
-
- private static class MultiForest<T> extends IterableForest<T> {
- private final FastSet<Body<T>> results;
- private boolean valid;
- public boolean valid() { return valid; }
- private MultiForest(FastSet<Body<T>> results, boolean valid) { this.results = results; this.valid = valid; }
- 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));
- this.valid = true;
- }
- public Iterator<Body<T>> iterator() { return results.iterator(); }
-
- public HashSet<Tree<T>> expand(boolean toss) {
- HashSet<Tree<T>> ret = new HashSet<Tree<T>>();
- for(Body<T> b : results)
- ret.addAll(b.expand(toss, new ArrayList<Tree<T>>(), 0, new HashSet<Tree<T>>()));
- if (toss && ret.size() > 1) throw new Parser.Ambiguous(this);
- return ret;
- }
-
- // Display //////////////////////////////////////////////////////////////////////////////
-
- private String toString = null;
- public String toString() {
- if (toString != null) return toString;
- StringBuffer ret = new StringBuffer();
- if (results.size()==1) {
- for(Forest.Body<T> r : results)
- ret.append(r);
- return toString = ret.toString();
- }
- ret.append("<?");
- boolean first = true;
- for(Forest.Body<T> r : results) {
- if (!first) ret.append(' ');
- first = false;
- ret.append(r);
- }
- ret.append("?>");
- return toString = ret.toString();
+ public boolean isTransparent() { return hp.size()==1; }
+ public boolean isHidden() { return hp.size()==0; }
+ public void edges(GraphViz.Node n) {
+ if (hp.size()==1) { hp.iterator().next().edges(n); return; }
+ for(Forest f : hp) f.edges(n);
+ }
+ public GraphViz.Node toGraphViz(GraphViz gv) {
+ //if (hp.size()==0) return null;
+ if (hp.size()==1) return hp.iterator().next().toGraphViz(gv);
+ if (gv.hasNode(this)) return gv.createNode(this);
+ GraphViz.Node n = gv.createNode(this);
+ n.label = "?";
+ n.color = "red";
+ for(Forest f : hp) n.edge(f, null);
+ return n;
+ }
+
+ public <B,C> void visit(Invokable<Forest.Body<T>,B,C> ivbc, B b, C c) {
+ if (hp==null) return;
+ for(Forest<T> f : hp)
+ f.visit(ivbc, b, c);