checkpoint
authoradam <adam@megacz.com>
Thu, 6 Jul 2006 07:46:07 +0000 (03:46 -0400)
committeradam <adam@megacz.com>
Thu, 6 Jul 2006 07:46:07 +0000 (03:46 -0400)
darcs-hash:20060706074607-5007d-71c755196f8260a73f61602fd95e0eddf70ef6e4.gz

src/edu/berkeley/sbp/meta/MetaGrammarBindings.java
tests/tibdoc.g

index da0204a..2d06422 100644 (file)
@@ -59,6 +59,36 @@ public class MetaGrammarBindings {
             this.sep = sep;
         }
         public Element build(MetaGrammar.Context cx) { return cx.get(name); }
+        public void build(MetaGrammar.Context cx, Union u) {
+            if (!rep) { super.build(cx, u); return; }
+            HashSet<Sequence> bad2 = new HashSet<Sequence>();
+
+            Union urep = new Union();
+            urep.add(Sequence.empty);
+            urep.add(Sequence.singleton(new Element[] { cx.get(sep), u }, 1));
+
+            for(int i=0; i<sequences.length; i++) {
+                Seq[] group = sequences[i];
+                Union u2 = new Union();
+                if (sequences.length==1) u2 = u;
+                for(int j=0; j<group.length; j++) {
+                    Union u3 = new Union();
+                    group[j].build(cx, u3, false);
+                    Sequence s = Sequence.unwrap(new Element[] { u3, urep },
+                                                 cx.rm.repeatTag(),
+                                                 new boolean[] { false, false });
+                    u2.add(s);
+                }
+                if (sequences.length==1) break;
+                Sequence seq = Sequence.singleton(u2);
+                for(Sequence s : bad2) {
+                    s.lame = true;
+                    seq = seq.not(s);
+                }
+                u.add(seq);
+                bad2.add(Sequence.singleton(u2));
+            }
+        }
     }
     public static @bind.as("=") NonTerminal go(@bind.arg String name, @bind.arg Seq[][] sequences) { return new NonTerminal(name, sequences, true); }
     public static @bind.as("=") NonTerminal go(@bind.arg String name, @bind.arg String sep, @bind.arg Seq[][] sequences) {
@@ -111,6 +141,12 @@ public class MetaGrammarBindings {
         El follow;
         String tag = null;
         boolean lame;
+        public void append(El e) {
+            El[] elements = new El[this.elements.length+1];
+            System.arraycopy(this.elements, 0, elements, 0, this.elements.length);
+            this.elements = elements;
+            elements[elements.length-1] = e;
+        }
         public Seq(El e) { this(new El[] { e }); }
         public Seq(El[] elements) { this.elements = elements; }
         public Seq tag(String tag) { this.tag = tag; return this; }
index 1c02f11..51e66e1 100644 (file)
@@ -84,19 +84,22 @@ oli          = ("# "|onums)! (ws! text &~ any (oli|uli)!)
 text         = Item
 Itemx        = ws! Item
              | ()
-Item         =
-// "[]":: blockquote                 Itemx
+Item
+//*/ws
+     =
+// "[]":: blockquote                 ((ws! Item) | ())
 //             >
- "[]":: { UL:: uli+/ws }           Itemx
-             | "[]":: { OL:: oli+/ws }           Itemx
-             > "[]":: pre                        Itemx
-             > "[]":: link                       Itemx
-             > "[]":: structured                 Itemx
-             > "[]":: styled                     Itemx
-             > "[]":: (Chars:: alphanum++)       Itemx
-             > "[]":: "\"" text "\""             Itemx
-             > "[]":: (Symbol:: sym++)           Itemx
-             > "[]":: { Block:: text }           Itemx
+ "[]":: { UL:: uli+/ws }           ((ws! Item) | ())
+             | "[]":: { OL:: oli+/ws }           ((ws! Item) | ())
+             > "[]":: pre                        ((ws! Item) | ())
+             > "[]":: link                       ((ws! Item) | ())
+             > "[]":: structured                 ((ws! Item) | ())
+             > "[]":: styled                     ((ws! Item) | ())
+             > "[]":: (Chars:: alphanum++)       ((ws! Item) | ())
+             > "[]":: "\"" text "\""             ((ws! Item) | ())
+             > "[]":: (Symbol:: sym++)           ((ws! Item) | ())
+             > "[]":: { Block:: text }           ((ws! Item) | ())
+
 
 //blockquote   = Blockquote:: "\"\"" (block | text "\"\"")