X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Fmeta%2FRepeat.java;h=800639b14f3a2afb7ea33b804be596561a7d2df1;hp=25581b2e91aef3533c908a96c473c5fb336896ff;hb=HEAD;hpb=0c8e6b67673f47003a92c496a9d005ab7d5354fa diff --git a/src/edu/berkeley/sbp/meta/Repeat.java b/src/edu/berkeley/sbp/meta/Repeat.java index 25581b2..800639b 100644 --- a/src/edu/berkeley/sbp/meta/Repeat.java +++ b/src/edu/berkeley/sbp/meta/Repeat.java @@ -1,4 +1,4 @@ -// 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.*; @@ -8,8 +8,11 @@ import java.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); } @@ -28,21 +31,34 @@ public class Repeat extends Union { ? "" : ("/"+separator)), true); - 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 (follow != null) { + Sequence s = Sequence.create(new Repeat(e, zeroOkay, manyOkay, + separator, maximal, tag, null)).followedBy(follow); + add(s); + return; + } + 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)); + add(Sequence.create(tag, + new Element[] { Repeat.this, separator, e }, + new boolean[] { false, true, false }, + new boolean[] { true, false, false } + )); + } }