clean up metagrammar handling of drop and question-mark
[sbp.git] / src / edu / berkeley / sbp / meta / Repeat.java
index f21e820..25581b2 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright 2006 all rights reserved; see LICENSE file for BSD-style license
+
 package edu.berkeley.sbp.meta;
 import edu.berkeley.sbp.util.*;
 import edu.berkeley.sbp.*;
@@ -16,23 +18,31 @@ public class Repeat extends Union {
     protected Repeat(final Element e, boolean zeroOkay, boolean manyOkay, final Element separator, boolean maximal, Object tag) {
         this(e, zeroOkay, manyOkay, separator, maximal, tag, null); }
     protected Repeat(final Element e, boolean zeroOkay, boolean manyOkay, final Element separator, boolean maximal, Object tag, Atom follow) {
-        super(e+(!manyOkay ? "?" : (zeroOkay ? (maximal ? "**" : "*") : (maximal ? "++" : "+")))+(separator==null?"":("/"+separator)), true);
+        super(e
+              +(!manyOkay
+                ? "?"
+                : (zeroOkay
+                   ? (maximal ? "**" : "*")
+                   : (maximal ? "++" : "+")))
+              +(separator==null
+                ? ""
+                : ("/"+separator)),
+              true);
         if (zeroOkay && !manyOkay) {
-            add(Sequence.empty().followedBy(follow));
-            add(Sequence.singleton(e).followedBy(follow));
-            return;
-        }
-        if (zeroOkay) {
-            add(Sequence.rewritingSequence(tag, new Element[] { }, null).followedBy(follow));
+            // FIXME
+            add(Sequence.create(tag, new Element[] { }, null, false).followedBy(follow));
+            add(Sequence.create(tag, new Element[] { e }, null, false).followedBy(follow));
+        } else if (zeroOkay) {
+            add(Sequence.create(tag, new Element[] { }, null, false).followedBy(follow));
             //add(new Sequence.Constant.Empty());
             // FUGLY
-            add(Sequence.singleton(many1(e, separator, tag)).followedBy(follow));
+            add(Sequence.create(many1(e, separator, tag)).followedBy(follow));
         } else {
-            add(Sequence.rewritingSequence(tag, new Element[] { e }, null).followedBy(follow));
+            add(Sequence.create(tag, new Element[] { e }, null, false).followedBy(follow));
             if (separator==null)
-                add(Sequence.unwrap(new Element[] { e,                 Repeat.this }, tag, new boolean[] { false, false }).followedBy(follow));
+                add(Sequence.create(tag, new Element[] { e,            Repeat.this }, new boolean[] { false, false }, true).followedBy(follow));
             else
-                add(Sequence.unwrap(new Element[] { e, separator,      Repeat.this }, tag, new boolean[] { false, true, false }).followedBy(follow));
+                add(Sequence.create(tag, new Element[] { e, separator, Repeat.this }, new boolean[] { false, true, false }, true).followedBy(follow));
         }
     }