-// Copyright 2006 all rights reserved; see LICENSE file for BSD-style license
+// Copyright 2007 all rights reserved; see LICENSE file for BSD-style license
package edu.berkeley.sbp.meta;
import edu.berkeley.sbp.util.*;
import java.lang.reflect.*;
import java.lang.ref.*;
-/** currently this class exports only static methods to create repetitions; there are no public instance methods or constructors */
-public class Repeat extends Union {
+/**
+ * Currently this class exports only static methods to create repetitions;
+ * there are no public instance methods or constructors
+ */
+class Repeat extends Union {
public Repeat(final Element e, boolean zeroOkay, boolean manyOkay, Object tag) {
this(e, zeroOkay, manyOkay, null, false, tag); }
: ("/"+separator)),
true);
if (follow != null) {
- Sequence s = Sequence.create(new Repeat(e, zeroOkay, manyOkay, separator, maximal, tag, null)).followedBy(follow);
+ Sequence s = Sequence.create(new Repeat(e, zeroOkay, manyOkay,
+ separator, maximal, tag, null)).followedBy(follow);
add(s);
return;
}
- if (zeroOkay && !manyOkay) {
- // 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
+ if (zeroOkay)
+ add(Sequence.create(tag, new Element[] { }, null).followedBy(follow));
+ if (!(zeroOkay && manyOkay))
+ add(Sequence.create(tag, new Element[] { e }, null).followedBy(follow));
+
+ // FEATURE: stringify ~[]* as ...
+ if (zeroOkay && manyOkay && separator!=null) {
add(Sequence.create(many1(e, separator, tag)).followedBy(follow));
- } else {
- add(Sequence.create(tag, new Element[] { e }, null, false).followedBy(follow));
- /*
+
+ } else if (manyOkay) {
if (separator==null)
- add(Sequence.create(tag, new Element[] { e, Repeat.this }, new boolean[] { false, false }, true).followedBy(follow));
+ add(Sequence.create(tag,
+ new Element[] { Repeat.this, e },
+ new boolean[] { false, false },
+ new boolean[] { true, false }));
else
- add(Sequence.create(tag, new Element[] { e, separator, Repeat.this }, new boolean[] { false, true, false }, true).followedBy(follow));
- */
- if (separator==null)
- /*
- add(Sequence.create(tag, new Element[] { e, Repeat.this }, new boolean[] { false, false }, true).followedBy(follow));
- */
- add(Sequence.createLeft(tag, new Element[] { Repeat.this, e },
- new boolean[] { false, false }, true));
- else {
- /*
- add(Sequence.create(tag, new Element[] { e, separator, Repeat.this }, new boolean[] { false, true, false }, true).followedBy(follow));
- */
- add(Sequence.createLeft(tag, new Element[] { Repeat.this, separator, e },
- new boolean[] { false, true, false }, true));
- }
+ add(Sequence.create(tag,
+ new Element[] { Repeat.this, separator, e },
+ new boolean[] { false, true, false },
+ new boolean[] { true, false, false }
+ ));
}
}