X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FSequence.java;h=bb0ba4815a6212744ae9c0c27efed77172548ff3;hp=8d6709d5f4e1d0164faacedbe0a6c60eb244ad80;hb=4378d20232cd88fb2a57edc5a5114f952ab58a18;hpb=e6be1f03f79b16cd410991d7e64cfa7beab6de59 diff --git a/src/edu/berkeley/sbp/Sequence.java b/src/edu/berkeley/sbp/Sequence.java index 8d6709d..bb0ba48 100644 --- a/src/edu/berkeley/sbp/Sequence.java +++ b/src/edu/berkeley/sbp/Sequence.java @@ -33,18 +33,17 @@ public abstract class Sequence extends Element implements Iterable { } /** the empty sequence (matches the empty string) */ - static final Sequence empty = new Sequence.Constant.Empty(); - public static Sequence empty() { return empty; } + public static Sequence newEmptySequence() { return new Sequence.Constant.Empty(); } /** after matching the sequence, do not add anything to the output tree */ - public static Sequence drop(Element[] e) { return new Constant.Drop(e); } + public static Sequence newDropSequence(Element[] e) { return new Constant.Drop(e); } /** after matching the sequence, insert a constant into the output tree */ - public static Sequence constant(Element[] e, Object o) { return new Constant(e, o); } + public static Sequence newConstantSequence(Element[] e, Object o) { return new Constant(e, o); } /** after matching the sequence, place the result of the idxth match in the output tree */ - public static Sequence singleton(Element[] e, int idx) { return new Singleton(e, idx); } - public static Sequence singleton(Element e) { return singleton(new Element[] { e }, 0); } + public static Sequence newSingletonSequence(Element[] e, int idx) { return new Singleton(e, idx); } + public static Sequence newSingletonSequence(Element e) { return newSingletonSequence(new Element[] { e }, 0); } /** * after matching the sequence, create the specified output tree @@ -53,16 +52,20 @@ public abstract class Sequence extends Element implements Iterable { * @param drops only elements of e whose corresponding boolean in drops * is false will be included in the output tree **/ - public static Sequence rewritingSequence(Object tag, Element[] e, boolean[] drops) { + public static Sequence newRewritingSequence(Object tag, Element[] e, boolean[] drops) { return new RewritingSequence(tag, e, drops); } - public static Sequence regionRewritingSequence(Functor tagfunctor, Element[] e, boolean[] drops) { - return new RegionRewritingSequence(tagfunctor, e, drops); } + public static Sequence newUnwrapSequence(Element[] e, Object tag, boolean[] drops) { return new Unwrap(e, tag, drops); } //////////////////////////////////////////////////////////////////////////////// + /** return a new sequence identical to this one, but with a positive conjunct s */ public Sequence and(Sequence s) { Sequence ret = dup(); ret.needs.add(s); return ret; } + + /** return a new sequence identical to this one, but with a negative conjunct s */ public Sequence not(Sequence s) { Sequence ret = dup(); ret.hates.add(s); s.hated.add(ret); return ret; } + + /** return a new sequence identical to this one, but with a follow-set restricted to a */ public Sequence followedBy(Atom a) { Sequence ret = dup(); ret.follow = a; return ret; } Iterable needs() { return needs; } @@ -200,7 +203,6 @@ public abstract class Sequence extends Element implements Iterable { Sequence _clone() { return new Singleton(elements,idx); } } - public static Sequence unwrap(Element[] e, Object tag, boolean[] drops) { return new Unwrap(e, tag, drops); } static class Unwrap extends Sequence { private boolean[] drops; private final Object tag;