checkpoint
authoradam <adam@megacz.com>
Mon, 19 Dec 2005 06:52:06 +0000 (01:52 -0500)
committeradam <adam@megacz.com>
Mon, 19 Dec 2005 06:52:06 +0000 (01:52 -0500)
darcs-hash:20051219065206-5007d-2aa8ff25730450bcdac5560eae05d333d315dc0c.gz

src/edu/berkeley/sbp/misc/MetaGrammar.java

index bc171da..13da0ca 100644 (file)
@@ -152,16 +152,25 @@ public class MetaGrammar extends ReflectiveWalker {
 
         public PreSequence sparse(Object e) {
             Object[] ret;
-            if (o.length <= 1) ret = o;
-            else {
+            boolean[] drops;
+            if (o.length <= 1) {
+                ret = o;
+                drops = new boolean[this.drops.length];
+                System.arraycopy(this.drops, 0, drops, 0, this.drops.length);
+            } else {
                 ret = new Object[o.length * 2 - 1];
+                drops = new boolean[o.length * 2 - 1];
                 for(int i=0; i<o.length; i++) {
                     Object oi = o[i];
                     ret[i*2]   = oi;
-                    if (i*2+1<ret.length) ret[i*2+1] = new MyDrop(e);
+                    drops[i*2] = this.drops[i];
+                    if (i*2+1<ret.length) {
+                        ret[i*2+1] = new MyDrop(e);
+                        drops[i*2+1] = true;
+                    }
                 }
             }
-            PreSequence p = new PreSequence(ret, tag);
+            PreSequence p = new PreSequence(ret, tag, drops);
             p.not.addAll(not);
             p.and.addAll(and);
             return p;
@@ -170,9 +179,15 @@ public class MetaGrammar extends ReflectiveWalker {
         public PreSequence not(Sequence s) { not.add(s); return this; }
         public PreSequence and(Sequence s) { and.add(s); return this; }
 
+        boolean[] drops = null;
         public PreSequence(Object o) { this(new Object[] { o }, null); }
         public PreSequence(Object[] o) { this(o, null); }
-        public PreSequence(Object[] o, String tag) { this.o = o; this.tag = tag; }
+        public PreSequence(Object[] o, String tag) { this(o, tag, null); }
+        public PreSequence(Object[] o, String tag, boolean[] drops) {
+            this.o = o;
+            this.tag = tag;
+            this.drops = drops==null ? new boolean[o.length] : drops;
+        }
 
         public Union    buildUnion() {
             Union u = new Union("???");
@@ -186,9 +201,7 @@ public class MetaGrammar extends ReflectiveWalker {
             HashSet<Sequence> set = new HashSet<Sequence>();
             Element[] o2 = o==null ? new Element[0] : new Element[o.length];
             int nonDrop = 0;
-            boolean[] drops = null;
             if (o != null) {
-                drops = new boolean[o.length];
                 int j = 0;
                 for(int i=0; i<o.length; i++) {
                     Object oi = o[i];