protected final Element[] elements;
+ public boolean needed_or_hated = false;
+
final HashSet<Sequence> hated = new HashSet<Sequence>();
final HashSet<Sequence> needs = new HashSet<Sequence>();
////////////////////////////////////////////////////////////////////////////////
/** return a new sequence identical to this one, but with a positive conjunct <tt>s</tt> */
- public Sequence and(Sequence s) { Sequence ret = dup(); ret.needs.add(s); return ret; }
+ public Sequence and(Sequence s) { Sequence ret = dup(); ret.needs.add(s); s.needed_or_hated=true; return ret; }
/** return a new sequence identical to this one, but with a negative conjunct <tt>s</tt> */
- public Sequence andnot(Sequence s) { Sequence ret = dup(); ret.hates.add(s); s.hated.add(ret); return ret; }
+ public Sequence andnot(Sequence s) { Sequence ret = dup(); ret.hates.add(s); s.hated.add(ret); s.needed_or_hated=true; return ret; }
/** return a new sequence identical to this one, but with a follow-set restricted to <tt>a</tt> */
public Sequence followedBy(Atom a) { Sequence ret = dup(); ret.follow = a; return ret; }
+ boolean hatesAny(Iterable<Sequence> it) {
+ if (hates.isEmpty()) return false;
+ for(Sequence s : it) if (hates.contains(s)) return true;
+ return false;
+ }
+
Iterable<Sequence> needs() { return needs; }
Iterable<Sequence> hates() { return hates; }