X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FSequence.java;h=5ee8433431ef5d25137fead50bdb7a8debedd86a;hp=28f656470cf8d46efb8d198ff2682ef157e3ee7e;hb=0e17670bcfa7b0fe8eb3a2cac81f4b080a09fc98;hpb=24112db237318c030b4d4f457d90c34fd69d652b diff --git a/src/edu/berkeley/sbp/Sequence.java b/src/edu/berkeley/sbp/Sequence.java index 28f6564..5ee8433 100644 --- a/src/edu/berkeley/sbp/Sequence.java +++ b/src/edu/berkeley/sbp/Sequence.java @@ -7,18 +7,29 @@ import java.util.*; import java.lang.reflect.*; import java.lang.ref.*; -/** juxtaposition; zero or more adjacent Elements; can specify a rewriting */ +/** juxtaposition; zero or more adjacent Elements; can specify a rewriting */ public abstract class Sequence extends Element implements Iterable { + protected final Element[] elements; + + final HashSet hated = new HashSet(); + + final HashSet needs = new HashSet(); + final HashSet hates = new HashSet(); + + final Position firstp; + + public Atom follow = null; + public final Topology follow() { return follow; } + // Static Constructors ////////////////////////////////////////////////////////////////////////////// abstract Sequence _clone(); Sequence dup() { Sequence ret = _clone(); - for(Sequence s : needs) { ret.needs.add(s); s.needed.add(ret); } + for(Sequence s : needs) { ret.needs.add(s); } for(Sequence s : hates) { ret.hates.add(s); s.hated.add(ret); } ret.follow = follow; - ret.lame = lame; return ret; } @@ -26,7 +37,7 @@ public abstract class Sequence extends Element implements Iterable { public static final Sequence empty = new Sequence.Constant.Empty(); /** after matching the sequence, do not add anything to the output tree */ - public static Sequence drop(Element[] e, boolean lame) { return new Constant.Drop(e, lame); } + public static Sequence drop(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); } @@ -50,24 +61,12 @@ public abstract class Sequence extends Element implements Iterable { //////////////////////////////////////////////////////////////////////////////// - public Atom follow = null; - public final Topology follow() { return follow; } - - public Sequence and(Sequence s) { Sequence ret = dup(); ret.needs.add(s); s.needed.add(ret); return ret; } + public Sequence and(Sequence s) { Sequence ret = dup(); ret.needs.add(s); return ret; } public Sequence not(Sequence s) { Sequence ret = dup(); ret.hates.add(s); s.hated.add(ret); return ret; } public Iterable needs() { return needs; } public Iterable hates() { return hates; } - protected final Element[] elements; - - final HashSet needed = new HashSet(); - final HashSet hated = new HashSet(); - final HashSet needs = new HashSet(); - final HashSet hates = new HashSet(); - public boolean lame = false; - - final Position firstp; Position firstp() { return firstp; } public Iterator iterator() { return new ArrayIterator(elements); } @@ -184,15 +183,12 @@ public abstract class Sequence extends Element implements Iterable { return (Forest)Forest.create(loc, result, null, false); } static class Drop extends Constant { - Sequence _clone() { return new Drop(elements, lame); } - public Drop(Element[] e, boolean lame) { - super(e, null); - this.lame = lame; - } + Sequence _clone() { return new Drop(elements); } + public Drop(Element[] e) { super(e, null); } } static class Empty extends Sequence.Constant.Drop { Sequence _clone() { return new Empty(); } - public Empty() { super(new Element[] { }, false); } } + public Empty() { super(new Element[] { }); } } } static class Singleton extends Sequence {