- private Forest.Ref epsilonForm = null;
- Forest epsilonForm() {
- if (epsilonForm != null) return epsilonForm;
- epsilonForm = new Forest.Ref();
+ public boolean contains(Sequence s) {
+ viewed = true;
+ return alternatives.contains(s);
+ }
+
+ /** iterator over this Union's Sequences */
+ public Iterator<Sequence> iterator() {
+ viewed = true;
+ return alternatives.iterator();
+ }
+
+ /** adds an alternative */
+ public Union add(Sequence s) {
+ if (viewed)
+ throw new RuntimeException("once Union.contains() or Union.iterator() has been invoked, "+
+ "you may not add any more Sequences to it\n "+
+ " union in question: " + this);
+ if (s.needed_or_hated)
+ throw new RuntimeException("you may not add a conjunct directly to a Union");
+ s.in_a_union = true;
+ if (alternatives.contains(s)) return this;
+ alternatives.add(s);
+ return this;
+ }
+
+ /** adds a one-element sequence */
+ public void add(Element e) {
+ add(Sequence.create(e));
+ }
+
+ /** the Forest which results from matching this Union against the empty string at region <tt>region</tt> */
+ Forest epsilonForm(Input.Region region, Grammar cache) {
+ viewed = true;
+ Forest.Many epsilonForm = new Forest.Many();