checkpoint
[sbp.git] / src / edu / berkeley / sbp / misc / MetaGrammar.java
index 2751db7..3501ee6 100644 (file)
@@ -4,7 +4,7 @@ import edu.berkeley.sbp.*;
 import java.util.*;
 import java.io.*;
 
-public class MetaGrammar extends ReflectiveWalker {
+public class MetaGrammar extends StringWalker {
 
     public static Union make() throws Exception {
         return ((MetaGrammar)new MetaGrammar().walk(meta)).done();
@@ -71,10 +71,15 @@ public class MetaGrammar extends ReflectiveWalker {
         return n;
     }
 
+    public String string(Iterable<Tree<String>> children) {
+        String ret = "";
+        for(Tree<String> t : children) ret += string(t);
+        return ret;
+    }
     public String string(Tree<String> tree) {
         String ret = "";
         if (tree.head()!=null) ret += tree.head();
-        for(Tree<String> t : tree.children()) ret += string(t);
+        ret += string(tree.children());
         return ret;
     }
 
@@ -148,6 +153,13 @@ public class MetaGrammar extends ReflectiveWalker {
     }
 
 
+    public Object walk(String tag, Object[] argo) {
+        if (argo.length==0) return super.walk(tag, argo);
+        if (argo==null) return tag;
+        if (tag==null || "".equals(tag)) return argo;
+        return super.walk(tag, argo);
+    }
+
     //////////////////////////////////////////////////////////////////////////////
 
     public class PreSequence {