X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=src%2Fedu%2Fberkeley%2Fsbp%2FSequence.java;h=1adfaddfdc542912c6a76b1f71178bfee13b5e75;hb=7d1d5b9e2969e687cc07592f5a212681f8d26479;hp=2ba90968333b055a1348b0ab7c3d121d0b5eb215;hpb=fa858dc4acddd3e32126ff2558e0860315a84758;p=sbp.git diff --git a/src/edu/berkeley/sbp/Sequence.java b/src/edu/berkeley/sbp/Sequence.java index 2ba9096..1adfadd 100644 --- a/src/edu/berkeley/sbp/Sequence.java +++ b/src/edu/berkeley/sbp/Sequence.java @@ -17,7 +17,7 @@ public abstract class Sequence extends Element implements Iterable { Sequence ret = _clone(); for(Sequence s : needs) { ret.needs.add(s); s.needed.add(ret); } for(Sequence s : hates) { ret.hates.add(s); s.hated.add(ret); } - ret.noFollow = noFollow; + ret.follow = follow; return ret; } @@ -32,6 +32,7 @@ public abstract class Sequence extends Element implements Iterable { /** 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); } /** * after matching the sequence, create the specified output tree @@ -44,8 +45,8 @@ public abstract class Sequence extends Element implements Iterable { //////////////////////////////////////////////////////////////////////////////// - public Element noFollow = null; - public final Topology noFollow() { return noFollow==null ? null : Atom.toAtom(noFollow); } + public Element follow = null; + public final Topology follow() { return follow==null ? null : Atom.toAtom(follow); } Topology toAtom() { if (elements.length!=1) throw new RuntimeException("cannot invoke toAtom() on a Sequence with " + elements.length + " elements: " + this); @@ -162,6 +163,10 @@ public abstract class Sequence extends Element implements Iterable { sb.append(elements[i].toString()); sb.append(' '); } + if (follow != null) { + sb.append("-> "); + sb.append(follow); + } return sb; } @@ -238,11 +243,11 @@ public abstract class Sequence extends Element implements Iterable { } public StringBuffer toString(StringBuffer sb, boolean spacing) { int len = sb.length(); + if (tag != null) + sb.append("\""+StringUtil.escapify(tag.toString(),"\"\r\n")+"\":: "); super.toString(sb, spacing); len = sb.length()-len; if (spacing) for(int i=0; i<50-len; i++) sb.append(' '); - sb.append(" => "); - sb.append(tag); return sb; } }