checkpoint
authoradam <adam@megacz.com>
Sun, 15 Jan 2006 21:31:34 +0000 (16:31 -0500)
committeradam <adam@megacz.com>
Sun, 15 Jan 2006 21:31:34 +0000 (16:31 -0500)
darcs-hash:20060115213134-5007d-5cc1fb1af596fd9cc8ab18f5ccac2128c0403912.gz

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

index 68e311e..328550d 100644 (file)
@@ -22,7 +22,7 @@ public abstract class Sequence extends Element implements Iterable<Element> {
     public static final Sequence empty = new Sequence.Constant.Empty();
 
     /** after matching the sequence, do not add anything to the output tree */
-    public static Sequence drop(Element[] e, HashSet<Sequence> and, HashSet<Sequence> not, boolean lame) { return new Constant.Drop(e, and, not, lame); }
+    public static Sequence drop(Element[] e, boolean lame) { return new Constant.Drop(e, null, null, lame); }
 
     /** after matching the sequence, insert a constant into the output tree */
     public static Sequence constant(Element[] e, Object o, HashSet<Sequence> and, HashSet<Sequence> not) { return new Constant(e, o, and, not); }
index 4348dec..b1a3e8c 100644 (file)
@@ -258,7 +258,11 @@ public class MetaGrammar extends StringWalker {
             }
             Element[] expansion = o2;
             Sequence ret = null;
-            if (dropAll || lame) ret = Sequence.drop(expansion, and, not, lame);
+            if (dropAll || lame) {
+                ret = Sequence.drop(expansion, lame);
+                for(Sequence s : and) ret = ret.and(s);
+                for(Sequence s : not) ret = ret.not(s);
+            }
             else if (unwrap)    ret = new Sequence.Unwrap(expansion, drops, and, not);
             else if (tag!=null) ret = Sequence.rewritingSequence(tag, expansion, drops, and, not);
             else {
@@ -266,9 +270,13 @@ public class MetaGrammar extends StringWalker {
                 for(int i=0; i<expansion.length; i++)
                     if (!drops[i])
                         if (idx==-1) idx = i;
-                        else throw new Error("multiple non-dropped elements in sequence: " + Sequence.drop(expansion,null,null,false));
+                        else throw new Error("multiple non-dropped elements in sequence: " + Sequence.drop(expansion,false));
                 if (idx != -1) ret = Sequence.singleton(expansion, idx, and, not);
-                else           ret = Sequence.drop(expansion, and, not, false);
+                else           {
+                    ret = Sequence.drop(expansion, false);
+                    for(Sequence s : and) ret = ret.and(s);
+                    for(Sequence s : not) ret = ret.not(s);
+                }
             }
             set.add(ret);
             if (this.noFollow != null) ret.noFollow = new Atom.Invert(new Atom.Infer(this.noFollow));