checkpoint
authoradam <adam@megacz.com>
Thu, 12 Jan 2006 07:52:13 +0000 (02:52 -0500)
committeradam <adam@megacz.com>
Thu, 12 Jan 2006 07:52:13 +0000 (02:52 -0500)
darcs-hash:20060112075213-5007d-4fe13521e44ae92485a0982991b2c8cba7118d7d.gz

src/edu/berkeley/sbp/tib/TibDoc.java
tests/tibdoc.g

index 1a2fe23..ed6a31e 100644 (file)
@@ -40,19 +40,39 @@ public class TibDoc {
     }
 
     public static class HTMLWalker extends ReflectiveWalker {
-        public void stringify() { /*mode = HEADER;*/throw new Error(); }
+        //public void header() { throw new Error(); }
+        public String ul(Object o) { return "<ul>"+o+"</ul>"; }
+        private Tree<String> lone(String s) {
+            StringBuffer sb = new StringBuffer();
+            for(int i=0; i<s.length(); i++) {
+                switch(s.charAt(i)) {
+                    case '&':  sb.append("&amp;"); break;
+                    case '<':  sb.append("&lt;"); break;
+                    case '>':  sb.append("&gt;"); break;
+                    case '\'': sb.append("&apos;"); break;
+                    case '\"': sb.append("&quot;"); break;
+                    default:   sb.append(s.charAt(i)); break;
+                }
+            }
+            return new Tree<String>(null, sb.toString(), new Tree[0]);
+        }
         public Object walk(Tree<String> t) {
             String head = t.head();
             if ("stringify".equals(head)) {
                 StringBuffer ret = new StringBuffer();
                 for(Tree<String> child : t.child(0)) ret.append(child);
-                return new Tree<String>(null, ret.toString());
+                return lone(ret.toString());
             }
             return super.walk(t);
         }
         public Object walk(String head, Object[] children) {
-            if (children.length==0) return new Tree<String>(null, head, new Tree[0]);
-            return new Tree<String>(null, head, (Tree<String>[])Reflection.lub(children));
+            Tree<String>[] kids = new Tree[children.length];
+            for(int i=0; i<children.length; i++) {
+                if (children[i]==null) kids[i]=null;
+                else if (children[i] instanceof String) kids[i] = lone((String)children[i]);
+                else kids[i] = (Tree<String>)children[i];
+            }
+            return new Tree<String>(null, head, kids);
         }
     }
 
index e1f8a86..e77d53b 100644 (file)
@@ -66,8 +66,8 @@ pre        ::= "[verbatim]" { ~[]+ } /ws => "verbatim"   // FIXME doesn't work
 
 styled     ::= "__" text "__"      => ul
              | "((" text "))"      => footnote
-             | ( "[[" text "]]"      => tt
-               >  "[" word "]"       => citation
+             | ( "[[" text "]]"    => tt
+               >  "[" word "]"     => citation
                )
              | "!!" text "!!"      => strikethrough
              | "^^" (word|block)   => superscript
@@ -117,7 +117,7 @@ host       ::= [0-9]+ "." [0-9]+ "." [0-9]+ "." [0-9]+ => "ip"
 
 // Tokens ///////////////////////////////////////////////////////////////////
 
-word     ::= alphanum++
+word     ::= alphanum++ => stringify
            | quoted
 
 quoted   ::= "\"" ((~[\"\\] | escaped)+) "\""