checkpoint
[sbp.git] / src / edu / berkeley / sbp / misc / MetaGrammar.java
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 =