checkpoint
[sbp.git] / src / edu / berkeley / sbp / tib / TibDoc.java
index a86fb2b..26f8174 100644 (file)
@@ -44,8 +44,8 @@ public class TibDoc {
         public Body   body;
         public void toHTML(ToHTML.HTML sb) { sb.tag("html", body); }
         public static class Header extends HashMap<String, Text[]> {
-            public static class kv { public String key; public Text[] val; }
-            public void attrs(kv[] kvs) { for(int i=0; i<kvs.length; i++) this.put(kvs[i].key, kvs[i].val); }
+            public static class KeyVal { public String key; public Text[] val; }
+            public void attrs(KeyVal[] KeyVals) { for(int i=0; i<KeyVals.length; i++) this.put(KeyVals[i].key, KeyVals[i].val); }
         }
         public static class Body implements ToHTML {
             public Section[] sections;
@@ -324,49 +324,46 @@ toContex ll = prefix ++ (concatMap tl ll) ++ suffix
 
     // Main //////////////////////////////////////////////////////////////////////////////
 
+    public static class Dump implements Reflection.Show {
+        public String toString() { return Reflection.show(this); }
+    }
+
     public static class TD {
 
-        public @nonterminal("Doc") static class Doc {
+        public @nonterminal static class Doc extends Dump {
             public @arg("head") Header head;
             public @arg("body") Body body;
-            public String toString() { return "doc:{"+head+","/*+body*/+"}"; }
         }
 
-        public @nonterminal("Header") static class Header {
-            public @arg("attrs") KV[] attrs;
+        public @nonterminal static class Header extends Dump {
+            public @arg("attrs") KeyVal[] attrs;
             // FIXME: it would be nice to be able to
-            // void kv(String, String) { ... } imperatively
-            public String toString() {
-                StringBuffer ret = new StringBuffer();
-                ret.append("<");
-                for(KV kv : attrs) ret .append(kv);
-                ret.append(">");
-                return ret.toString();
-            }
+            // void KeyVal(String, String) { ... } imperatively
         }
         
-        public @nonterminal("Body") static class Body {
+        public @nonterminal static class Body extends Dump {
             public Section[] sections;
             // FIXME: it would be nice to be able to
-            // void kv(String, String) { ... } imperatively
-            public String toString() {
-                StringBuffer ret = new StringBuffer();
-                ret.append("<");
-                for(Object kv : sections) ret .append(kv);
-                ret.append(">");
-                return ret.toString();
-            }
+            // void KeyVal(String, String) { ... } imperatively
         }
         
-        public @nonterminal("Section") static class Section {
-            public Object   @arg header;
-            public Object[] @arg paragraphs;
+        public @nonterminal("Section") static class Section extends Dump {
+            public String      header;
+            public Paragraph[] paragraphs;
         }
         
-        public @nonterminal("kv") static class KV {
+        public @nonterminal static class KeyVal extends Dump {
             public @arg("key") String key;
             public @arg("val") Object val;
-            public String toString() { return "KV["+key+"="+val+"]"; }
+        }
+
+        public static class Paragraph extends Dump { }
+        public @tag("P") static class P extends Paragraph {
+            Object text;
+        }
+        public @tag("HR") static class HR extends Paragraph { }
+        public @tag("Blockquote") static class Blockquote extends Paragraph {
+            Object text;
         }
     }
 
@@ -380,7 +377,11 @@ toContex ll = prefix ++ (concatMap tl ll) ++ suffix
                                             TibDoc.TD.Header.class,
                                             TibDoc.TD.Section.class,
                                             TibDoc.TD.Body.class,
-                                            TibDoc.TD.KV.class
+                                            TibDoc.TD.Paragraph.class,
+                                            TibDoc.TD.P.class,
+                                            TibDoc.TD.HR.class,
+                                            TibDoc.TD.Blockquote.class,
+                                            TibDoc.TD.KeyVal.class
                                         });
             Tree<String> res = new CharParser(MetaGrammar.make()).parse(new FileInputStream(s[0])).expand1();
             MetaGrammar.Meta.MetaGrammarFile mgf = m.new MetaGrammarFile(res);