Immediately
- Sequence shouldn't be an Element
+ - Should Tree<T> really be type-parameterized?
+
- More topology untangling
- needs/hates/follow API ugliness
/** <font color=blue>a tree (or node in a tree); see jargon.txt for details</font> */
public class Tree<T>
extends PrintableTree<Tree<T>>
- implements Iterable<Tree<T>>,
- GraphViz.ToGraphViz {
+ implements Iterable<Tree<T>> {
private final Input.Region location;
private final T head;
private Tree<T> lifted() { return children[children.length-1]; }
/** the number of children the tree has */
- public int numChildren() {
+ public int size() {
return lift
- ? (children.length-1)+lifted().numChildren()
+ ? (children.length-1)+lifted().size()
: children.length;
}
protected boolean ignoreSingleton() { return false; }
- // ToGraphViz /////////////////////////////////////////////////////////////////////////////
-
- public GraphViz.Node toGraphViz(GraphViz gv) {
- if (gv.hasNode(this)) return gv.createNode(this);
- GraphViz.Node n = gv.createNode(this);
- n.label = head()==null ? "" : head().toString();
- for(Tree t : this) n.edge(t, null);
- return n;
- }
- public boolean isTransparent() { return false; }
- public boolean isHidden() { return false; }
-
}
for(Tree tc : t) {
if (tc.head() != null && tc.head() instanceof Functor)
ret.add(((TreeFunctor<Object,Object>)tc.head()).invoke(tc.children()));
- else if (tc.numChildren() == 0)
+ else if (tc.size() == 0)
ret.add(tc.head());
else {
System.err.println("FIXME: don't know what to do about " + tc);
for(Tree tc : t) {
if (tc.head() != null && tc.head() instanceof Functor)
ret.add(((Functor<Iterable<Tree>,Object>)tc.head()).invoke(tc.children()));
- else if (tc.numChildren() == 0)
+ else if (tc.size() == 0)
ret.add(tc.head());
else {
System.err.println("FIXME: don't know what to do about " + tc);
else if ("input".equals(tree.head())) return string(tree.children());
else if ("testcase".equals(tree.head())) {
String input = string(tree.child(0));
- String[] output = tree.numChildren()>2 ? ((String[])walk(tree, 1)) : new String[0];
- Union grammar = Grammar.create(tree.child(tree.numChildren()-1), "s", new MetaGrammarBindings());
+ String[] output = tree.size()>2 ? ((String[])walk(tree, 1)) : new String[0];
+ Union grammar = Grammar.create(tree.child(tree.size()-1), "s", new MetaGrammarBindings());
TestCase tc = new TestCase(input, output, grammar, false, false);
return tc;
} else if ("ts".equals(tree.head())) return walk(tree, 0);
else if (tree.head() == null) {
- Object[] ret = new Object[tree.numChildren()];
+ Object[] ret = new Object[tree.size()];
for(int i=0; i<ret.length; i++)
ret[i] = walk(tree.child(i));
return Reflection.lub(ret);
for(Tree<T> child : tree.children()) walk(child);
}
public Object walk(Tree<T> tree) {
- Object[] args = new Object[tree.numChildren()];
+ Object[] args = new Object[tree.size()];
int i = 0;
for(Tree<T> child : tree.children()) args[i++] = walk(child);
args = Reflection.lub(args);
import java.util.*;
import java.lang.reflect.*;
-public abstract class PrintableTree<T extends PrintableTree> implements Iterable<T>, ToJava /*, ToHTML*/ {
+public abstract class PrintableTree<T extends PrintableTree> implements Iterable<T>, ToJava /*, ToHTML*/, GraphViz.ToGraphViz {
+ protected abstract Object head();
protected abstract String headToString();
protected abstract String headToJava();
protected abstract String left();
sb.append("})");
}
+ public GraphViz.Node toGraphViz(GraphViz gv) {
+ if (gv.hasNode(this)) return gv.createNode(this);
+ GraphViz.Node n = gv.createNode(this);
+ n.label = head()==null ? "" : head().toString();
+ for(T t : this) n.edge(t, null);
+ return n;
+ }
+ public boolean isTransparent() { return false; }
+ public boolean isHidden() { return false; }
}