X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FRepeat.java;h=3e9b2b6c7fe8f949db881e8918ea94ad3246c584;hp=bc6626ab520f9037bbaf76e9564f35a8ac339a98;hb=242a8711e98cbd3ed6d05271bf910fde38e9be9a;hpb=7783442fcff4e640ecdcbdb6149463048d32f7a7 diff --git a/src/edu/berkeley/sbp/Repeat.java b/src/edu/berkeley/sbp/Repeat.java index bc6626a..3e9b2b6 100644 --- a/src/edu/berkeley/sbp/Repeat.java +++ b/src/edu/berkeley/sbp/Repeat.java @@ -20,6 +20,7 @@ public class Repeat extends Union { public static Repeat many1(Element e) { return new Repeat(e, false, true); } /** repeat one or more times, separated by sep */ public static Repeat many1(Element e, Element sep) { return new Repeat(e, false, true, sep); } + /** repeat zero or more times, matching a maximal sequence of atoms */ public static Repeat maximal0(Element e) { return new Repeat(e, true, true, null, true); } /** repeat one or more times, matching a maximal sequence of atoms */ @@ -43,24 +44,18 @@ public class Repeat extends Union { this.zeroOkay = zeroOkay; this.manyOkay = manyOkay; this.separator = separator; - Union who = this; - if (maximal) { - who = new Union(this+"++"); - add(new Sequence.Singleton(who, null, null) { - public Topology noFollow() { return separator==null ? e.toAtom() : separator.toAtom(); } - }); - } if (zeroOkay) { - who.add(new Sequence.Constant.Empty()); - if (manyOkay) who.add(new Sequence.Singleton(many1(e, separator), null, null)); - else who.add(new Sequence.Singleton(e, null, null)); + add(new Sequence.Constant.Empty()); + if (manyOkay) add(new Sequence.Singleton(many1(e, separator), null, null)); + else add(new Sequence.Singleton(e, null, null)); } else { - who.add(new Sequence.RewritingSequence(null, new Element[] { e }, null, null)); + add(new Sequence.RewritingSequence(null, new Element[] { e }, null, null)); if (this.separator==null) { - who.add(new Sequence.Unwrap(new Element[] { e, Repeat.this }, null, null)); + add(new Sequence.Unwrap(new Element[] { e, Repeat.this }, null, null)); } else { - who.add(new Sequence.Unwrap(new Element[] { e, this.separator, Repeat.this }, new boolean[] { false, true, false }, null, null)); + add(new Sequence.Unwrap(new Element[] { e, this.separator, Repeat.this }, new boolean[] { false, true, false }, null, null)); } } + if (maximal) for(Sequence s : this) s.noFollow = separator==null ? e : separator; } }