checkpoint
authoradam <adam@megacz.com>
Sun, 2 Jul 2006 22:05:18 +0000 (18:05 -0400)
committeradam <adam@megacz.com>
Sun, 2 Jul 2006 22:05:18 +0000 (18:05 -0400)
darcs-hash:20060702220518-5007d-1bb0ad929880cc416997b0335b905f4b8074e274.gz

TODO
src/edu/berkeley/sbp/misc/Demo.java
src/edu/berkeley/sbp/misc/RegressionTests.java
tests/tibdoc.g

diff --git a/TODO b/TODO
index 1e53bb8..2cec777 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,30 +1,15 @@
 _____________________________________________________________________________
 Immediately
 
-- If a top-level rule has labels but no head-tag, like this
-    Foo = a:Bar b:Baz
-  then infer the name of the rule it belongs to
+- Migrate Demo.java -> MetaGrammar.java
+    - Figure out serialization
 
-create( $c:{...}, class ) =
-  return create($c:{...})
-
-create( h:{...}, class ) = 
-
-create( , String)
-
-create( _:{...}, String) = treat as char[]
-create( _:{...}, c[] )   = { create(.,c), create(.,c), ... }
-
-create( $c:{...} ) =
+- Clean up the prioritized-match garbage
+ - evil problems with      (x y? z /ws)
 
 
   - better ambiguity debugging tools / visualization
-
   - ParseFailed, GSS, Walk, Parser, Sequence, Forest
-
-  - Fix the metagrammar (really?)
-      - evil problems with      (x y? z /ws)
-
   - copyright notices
   - documentation
 
index dd56ea0..92c9194 100644 (file)
@@ -17,26 +17,13 @@ public class Demo {
         Tree<String> res = new CharParser(MetaGrammar.make()).parse(new FileInputStream(s[0])).expand1();
         MetaGrammar.Meta.MetaGrammarFile mgf = m.new MetaGrammarFile(res);
         MetaGrammar.BuildContext bc = new MetaGrammar.BuildContext(mgf);
+
         Union meta = mgf.get("s").build(bc);
-        System.err.println("parsing " + s[1]);
         Tree t = new CharParser(meta).parse(new FileInputStream(s[1])).expand1();
-        System.out.println("tree:\n" + t.toPrettyString());
 
-        Reducer red = (Reducer)t.head();
-        MG.Grammar g = (MG.Grammar)red.reduce(t);
-        System.out.println(g);
-        
-        Context cx = new Context(g,m);
-        Element u = null;
-        for(MG.NonTerminal nt : g.nonterminals) {
-            Union el = (Union)cx.get(nt.name);
-            StringBuffer st = new StringBuffer();
-            el.toString(st);
-            System.err.println(st);
-            if (nt.name.equals("s")) u = el;
-        }
-        System.err.println();
+        Union u = Demo.make(t, "s");
 
+        System.err.println();
         System.err.println("== parsing with parsed grammar =================================================================================");
         t = new CharParser((Union)u).parse(new FileInputStream(s[1])).expand1();
         System.out.println(t.toPrettyString());
@@ -442,6 +429,22 @@ public class Demo {
         return o;
     }
 
+    public static Union make(Tree t, String s) {
+        ReflectiveMeta rm = new ReflectiveMeta();
+        Reducer red = (Reducer)t.head();
+        MG.Grammar g = (MG.Grammar)red.reduce(t);
+        Context cx = new Context(g,rm);
+        Union u = null;
+        for(MG.NonTerminal nt : g.nonterminals) {
+            Union el = (Union)cx.get(nt.name);
+            StringBuffer st = new StringBuffer();
+            el.toString(st);
+            System.err.println(st);
+            if (nt.name.equals(s)) u = el;
+        }
+        return u;
+    }
+
     public static class MG {
         public static @tag("grammar") class Grammar {
             public NonTerminal get(String s) {
index 6501727..7a8e502 100644 (file)
@@ -29,12 +29,8 @@ public class RegressionTests {
                 s = s2;
             }
 
-            //MetaGrammar mg0 = new MetaGrammar();
-            //mg0.walk(MetaGrammar.meta);
-            //System.out.println(mg0);
             System.err.println("parsing " + s[0]);
             Tree<String> res = new CharParser(MetaGrammar.make()).parse(new FileInputStream(s[0])).expand1();
-            //System.out.println(mg);
             Union meta = MetaGrammar.make(res, "s");
             System.err.println("parsing " + s[1]);
             SequenceInputStream sis = new SequenceInputStream(new FileInputStream(s[0]), new FileInputStream(s[1]));
@@ -193,96 +189,6 @@ public class RegressionTests {
             }
         }
     }
-    /*
-    public static class JavaGrammar extends MetaGrammar {
-        public Object convertLabel(String label) { return new ClassMark(label); }
-        public Object convertFieldLabel(String label) { return new FieldMark(label); }
-
-        private static class FieldMark {
-            public final String field;
-            public FieldMark(String field) { this.field = field; }
-            public String toString() { return "."+field; }
-        }
-        private static class ClassMark {
-            public final String clazz;
-            public ClassMark(String clazz) { this.clazz = clazz; }
-            public String toString() { return clazz+"$"; }
-        }
-
-        public static Object build(Tree<Object> t, Class c) throws Exception {
-            System.out.println("** build " + c.getName() + " " + t.toPrettyString());
-            Object h = t.head();
-            if (h instanceof ClassMark) return build2(t, Class.forName(JavaGrammar.class.getName()+"$"+((ClassMark)h).clazz));
-            Object o = null;
-            if (t.numChildren()==0) o = t.head();
-            else if (t.head()==null) return build2(t, c);
-            else if (t.head() instanceof FieldMark) {
-                return build2(new Tree(null, new Tree[] { t }), c);
-            } else {
-                throw new Exception("don't know how to cope: " + c.getName() + " <- " + t.toPrettyString());
-            }
-            return Reflection.rebuild(o, c);
-        }
-        private static Object build2(Tree<Object> t, Class c) throws Exception {
-            System.out.println("** build2 " + c.getName() + " " + t.toPrettyString());
-            if (!Reflection.isConcrete(c)) {
-                Field f = c.getField("subclasses");
-                if (f==null) throw new Exception("don't know how to cope: " + c.getName() + " <- " + t.toPrettyString());
-                Class[] subs = (Class[])f.get(null);
-                OUTER: for(int i=0; i<subs.length; i++) {
-                    for(Tree<Object> t2 : t) {
-                        Object o2 = t2.head();
-                        System.out.println("checking  " + o2 + " in " + subs[i].getName());
-                        if (o2 instanceof FieldMark) {
-                            if (subs[i].getField(((FieldMark)o2).field)==null) continue OUTER;
-                        }
-                    }
-                    c = subs[i];
-                    break;
-                }
-            }
-            Object o = c.newInstance();
-            for(Tree<Object> t2 : t) {
-                Object o2 = t2.head();
-                if (o2 instanceof FieldMark) {
-                    FieldMark f = (FieldMark)o2;
-                    Field field = c.getField(ReflectiveWalker.mangle(f.field));
-                    Object tgt = build(t2.child(0), field.getType());
-                    System.out.println("setting " + f.field +
-                                       " on a " + o.getClass().getName() +
-                                       " to " + (tgt==null?"null":tgt.getClass().getName()));
-                    field.set(o, tgt);
-                }
-            }
-            System.out.println("returning a " + o.getClass().getName());
-            return o;
-        }
-        public static Object build(Tree<Object> t) throws Exception {
-            Object h = t.head();
-            if (h instanceof ClassMark) {
-                ClassMark cm = (ClassMark)h;
-                Class c = Class.forName(JavaGrammar.class.getName() + "$" + ReflectiveWalker.mangle(cm.clazz));
-                return build2(t, c);
-            }
-            
-            return h==null ? null : h.toString();
-        }
-        
-        public static interface Expr {
-            public static Class[] subclasses = new Class[] { _plus_.class, num.class };
-        }
-        public static class _plus_ implements Expr {
-            public Expr left;
-            public Expr right;
-            public String toString() { return left + "+" + right; }
-        }
-        public static class num implements Expr {
-            public String val;
-            public String toString() { return "["+val+"]"; }
-        }
-
-    }
-    */
     private static String pad(int i,String s) { return s.length() >= i ? s : pad(i-1,s)+" "; }
 }
 
index 88ee6f8..4dc497f 100644 (file)
@@ -59,7 +59,7 @@ s                   = Doc
 Doc                 = head:{Header} body:Body  /ws
 Header              = "header" attrs:{ KeyVal */ ws }  /ws
 Body                = {Section}*/ws
-Section             = SectionHeader Paragraphs /ws
+Section             = SectionHeader Paragraph* /ws
 SectionHeader       = "==" SectionHeaderBody "=="
 SectionHeaderBody   =  "=" SectionHeaderBody "="
                     >      !ws alphanum++ !ws
@@ -70,10 +70,10 @@ blank    = !sp "\n" !sp "\n" !ws
 KeyVal       = key:word "=" val:text /ws
 wp           = w++
 num          = [0-9]++
-Paragraphs   = "[]":: { Blockquote:: "\"\" "    text } Paragraphs
-             > "[]":: { HR::         "---" "-"*      } Paragraphs
-             > "[]":: { P::          text            } Paragraphs
-             > ()
+
+Paragraph   = Blockquote:: { "\"\" "    text }
+            > HR::         { "---" "-"*      }
+            > P::          { text            }
 
 onums        = nums !(". "|") ")
 any          = ~[]*
@@ -84,7 +84,7 @@ oli          = !("# "|onums) (!ws text &~ any !(oli|uli))
 text         = Item
 Itemx        = !ws Item
              | ()
-Item         = blockquote
+Item         = "[]":: blockquote                 Itemx
              > "[]":: { UL:: uli+/ws }           Itemx
              | "[]":: { OL:: oli+/ws }           Itemx
              > "[]":: pre                        Itemx
@@ -96,8 +96,7 @@ Item         = blockquote
              > "[]":: (Symbol:: sym++)           Itemx
              > "[]":: { Block:: text }           Itemx
 
-blockquote   = Blockquote:: "\"\"" text "\"\""
-             | Blockquote:: "\"\"" block
+blockquote   = Blockquote:: "\"\"" (block | text "\"\"")
              
 pre          = Verbatim:: "[verbatim]" { ~[]+ } /ws   // FIXME doesn't work