checkpoint
authoradam <adam@megacz.com>
Sun, 15 Jan 2006 21:39:25 +0000 (16:39 -0500)
committeradam <adam@megacz.com>
Sun, 15 Jan 2006 21:39:25 +0000 (16:39 -0500)
darcs-hash:20060115213925-5007d-251fdc1aa64c6dc89bf6ed5ebfe43d656150e5fb.gz

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

index 9b6d6bb..aa91a64 100644 (file)
@@ -41,9 +41,9 @@ public class Repeat extends Union {
         } else {
             add(new Sequence.RewritingSequence(null, new Element[] { e }, null, null));
             if (separator==null)
-                add(new Sequence.Unwrap(new Element[] { e,                 Repeat.this }, null, null));
+                add(new Sequence.Unwrap(new Element[] { e,                 Repeat.this }));
             else
-                add(new Sequence.Unwrap(new Element[] { e, separator,      Repeat.this }, new boolean[] { false, true, false }, null, null));
+                add(new Sequence.Unwrap(new Element[] { e, separator,      Repeat.this }, new boolean[] { false, true, false }));
         }
         if (maximal) for(Sequence s : this) s.noFollow = separator==null ? e : separator;
     }
index 8995b5c..f21bb80 100644 (file)
@@ -62,6 +62,7 @@ public abstract class Sequence extends Element implements Iterable<Element> {
     Position firstp() { return firstp; }
 
     public Iterator<Element> iterator()    { return new ArrayIterator<Element>(elements); }
+    protected Sequence(Element[] elements) { this(elements, null, null); }
     protected Sequence(Element[] elements, HashSet<Sequence> and, HashSet<Sequence> not) {
         if (and!=null) for(Sequence s : and) { needs.add(s); s.needed.add(this); }
         if (not!=null) for(Sequence s : not) { hates.add(s); s.hated.add(this); }
@@ -198,10 +199,10 @@ public abstract class Sequence extends Element implements Iterable<Element> {
 
     public static class Unwrap extends Sequence {
         private boolean[] drops;
-        public Unwrap(Element[] e, HashSet<Sequence> and, HashSet<Sequence> not)                  { super(e, and, not); this.drops = null; }
-        public Unwrap(Element[] e, boolean[] drops, HashSet<Sequence> and, HashSet<Sequence> not) { super(e, and, not); this.drops = drops; }
-        public Sequence and(Sequence s) { Sequence ret = new Unwrap(elements, drops, needs, hates); ret.needs(s); return ret; }
-        public Sequence not(Sequence s) { Sequence ret = new Unwrap(elements, drops, needs, hates); ret.hates(s); return ret; }
+        public Unwrap(Element[] e)                  { super(e); this.drops = null; }
+        public Unwrap(Element[] e, boolean[] drops) { super(e); this.drops = drops; }
+        public Sequence and(Sequence s) { Sequence ret = new Unwrap(elements, drops); ret.needs(s); return ret; }
+        public Sequence not(Sequence s) { Sequence ret = new Unwrap(elements, drops); ret.hates(s); return ret; }
         public <T> Forest<T> postReduce(Input.Location loc, Forest<T>[] args) {
             for(int i=0; i<args.length; i++) if (args[i]==null) throw new Error();
             if (drops==null) return Forest.create(loc, null, args, true, false);
index f628813..e4592a8 100644 (file)
@@ -258,17 +258,10 @@ public class MetaGrammar extends StringWalker {
             }
             Element[] expansion = o2;
             Sequence ret = null;
-            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);
-                for(Sequence s : and) ret = ret.and(s);
-                for(Sequence s : not) ret = ret.not(s);
-            } else {
+            if (dropAll || lame) ret = Sequence.drop(expansion, lame);
+            else if (unwrap)    ret = new Sequence.Unwrap(expansion, drops);
+            else if (tag!=null) ret = Sequence.rewritingSequence(tag, expansion, drops);
+            else {
                 int idx = -1;
                 for(int i=0; i<expansion.length; i++)
                     if (!drops[i])
@@ -276,9 +269,9 @@ public class MetaGrammar extends StringWalker {
                         else throw new Error("multiple non-dropped elements in sequence: " + Sequence.drop(expansion,false));
                 if (idx != -1) ret = Sequence.singleton(expansion, idx);
                 else           ret = Sequence.drop(expansion, false);
-                for(Sequence s : and) ret = ret.and(s);
-                for(Sequence s : not) ret = ret.not(s);
             }
+            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));
             return ret;