checkpoint
authoradam <adam@megacz.com>
Tue, 13 Dec 2005 06:29:13 +0000 (01:29 -0500)
committeradam <adam@megacz.com>
Tue, 13 Dec 2005 06:29:13 +0000 (01:29 -0500)
darcs-hash:20051213062913-5007d-4c2ccc4dca9a776503811c6424b6d6e6b21469a0.gz

src/edu/berkeley/sbp/misc/MetaGrammar.java
tests/meta.g
tests/testcase.g

index bfddf72..1b4f1d9 100644 (file)
@@ -72,6 +72,15 @@ public class MetaGrammar extends ReflectiveWalker {
         public Object  _backslash__leftbrace_(String s)      { return SELF; }
         public Object  _leftbrace_(String s)                 { return SELF; }
         public Object _plus_(final Element r) { return new Rep(r, null, false, false); }
+    public Object[] _slash_(Object[] o, Object sep) {
+        if (o.length <= 1) return o;
+        Object[] ret = new Object[o.length * 2 - 1];
+        for(int i=0; i<o.length; i++) {
+            ret[i*2]   = o[i];
+            if (i*2+1<ret.length) ret[i*2+1] = new MyDrop(sep);
+        }
+        return ret;
+    }
     //public Element _tilde__slash__tilde_(final Element r) { return Repeat.maximal(r); }
     public Object _plus__slash_(final Element r, Object s) {
         if (s instanceof String) s = CharToken.string((String)s);
@@ -238,13 +247,15 @@ public class MetaGrammar extends ReflectiveWalker {
                 drops = new boolean[o.length];
                 int j = 0;
                 for(int i=0; i<o.length; i++) {
-                    if      (o[i] instanceof PreSequence) o2[j] = ((PreSequence)o[i]).buildUnion(ws);
-                    else if (o[i]==SELF)                  o2[j] = u.new Subset("(("+u+"))", set);
-                    else if (o[i] instanceof MyLift)      { o2[j] = CharToken.string(tag = ((MyLift)o[i]).s); drops[j] = true; }
-                    else if (o[i] instanceof String)      { o2[j] = CharToken.string(      ((String)o[i])  ); drops[j] = true; }
-                    else if (o[i] instanceof Rep)         o2[j] = ((Rep)o[i]).build(ws);
-                    //else if (o[i] instanceof PreBrace)    o2[j]
-                    else                                  o2[j] = (Element)o[i];
+                    Object oi = o[i];
+                    if (oi instanceof MyDrop)      { oi = ((MyDrop)oi).o; drops[j] = true; }
+                    if      (oi instanceof PreSequence) o2[j] = ((PreSequence)oi).buildUnion(ws);
+                    else if (oi==SELF)                  o2[j] = u.new Subset("(("+u+"))", set);
+                    else if (oi instanceof MyLift)      { o2[j] = CharToken.string(tag = ((MyLift)oi).s); drops[j] = true; }
+                    else if (oi instanceof String)      { o2[j] = CharToken.string(      ((String)oi)  ); drops[j] = true; }
+                    else if (oi instanceof Rep)         o2[j] = ((Rep)oi).build(ws);
+                    //else if (oi instanceof PreBrace)    o2[j]
+                    else                                  o2[j] = (Element)oi;
 
                     if (dropAll.contains(o2[j])) drops[j] = true;
 
@@ -343,6 +354,10 @@ public class MetaGrammar extends ReflectiveWalker {
         public final String s;
         public MyLift(String s) { this.s = s; }
     }
+    public static class MyDrop {
+        public final Object o;
+        public MyDrop(Object o) { this.o = o; }
+    }
 
     private static final Tree meta =
 
index 8c3a343..ceb82ac 100644 (file)
@@ -8,7 +8,9 @@ ec        ::=  [~\]\\\-\~] | escaped
 Alternatives  ::=  EquiAlt   +/ ">"
 EquiAlt       ::=  Conjuncts +/ "|"                 => "alternatives"
 
-Sequence    ::= E+
+Sequence    ::= E+ ^"/" E
+              > E+
+
 Conjuncts   ::=  Rewrite
               |  Rewrite ^"&"  Sequence
               |  Rewrite ^"&~" Sequence
index 9993dce..7245db8 100644 (file)
@@ -1,7 +1,7 @@
 ts       ::= ws Ts ws => ts
 Ts       ::= Test*
 ws      !::= w*
-Test     ::= ^"testcase" "{" Input Output+ Grammar "}"
+Test     ::= ^"testcase" "{" Input output+ Grammar "}"
            | ^"testcase" "{" Input         Grammar "}"
-Output   ::= "output" quoted ";"
+output   ::= "output" quoted ";" / w*
 Input    ::= "input"  quoted ";"