} else {
add(new Sequence.RewritingSequence(null, new Element[] { e }, null, null));
if (separator==null)
- add(new Sequence.Unwrap(new Element[] { e, Repeat.this }, null, null));
+ add(new Sequence.Unwrap(new Element[] { e, Repeat.this }));
else
- add(new Sequence.Unwrap(new Element[] { e, separator, Repeat.this }, new boolean[] { false, true, false }, null, null));
+ add(new Sequence.Unwrap(new Element[] { e, separator, Repeat.this }, new boolean[] { false, true, false }));
}
if (maximal) for(Sequence s : this) s.noFollow = separator==null ? e : separator;
}
Position firstp() { return firstp; }
public Iterator<Element> iterator() { return new ArrayIterator<Element>(elements); }
+ protected Sequence(Element[] elements) { this(elements, null, null); }
protected Sequence(Element[] elements, HashSet<Sequence> and, HashSet<Sequence> not) {
if (and!=null) for(Sequence s : and) { needs.add(s); s.needed.add(this); }
if (not!=null) for(Sequence s : not) { hates.add(s); s.hated.add(this); }
public static class Unwrap extends Sequence {
private boolean[] drops;
- public Unwrap(Element[] e, HashSet<Sequence> and, HashSet<Sequence> not) { super(e, and, not); this.drops = null; }
- public Unwrap(Element[] e, boolean[] drops, HashSet<Sequence> and, HashSet<Sequence> not) { super(e, and, not); this.drops = drops; }
- public Sequence and(Sequence s) { Sequence ret = new Unwrap(elements, drops, needs, hates); ret.needs(s); return ret; }
- public Sequence not(Sequence s) { Sequence ret = new Unwrap(elements, drops, needs, hates); ret.hates(s); return ret; }
+ public Unwrap(Element[] e) { super(e); this.drops = null; }
+ public Unwrap(Element[] e, boolean[] drops) { super(e); this.drops = drops; }
+ public Sequence and(Sequence s) { Sequence ret = new Unwrap(elements, drops); ret.needs(s); return ret; }
+ public Sequence not(Sequence s) { Sequence ret = new Unwrap(elements, drops); ret.hates(s); return ret; }
public <T> Forest<T> postReduce(Input.Location loc, Forest<T>[] args) {
for(int i=0; i<args.length; i++) if (args[i]==null) throw new Error();
if (drops==null) return Forest.create(loc, null, args, true, false);
}
Element[] expansion = o2;
Sequence ret = null;
- if (dropAll || lame) {
- ret = Sequence.drop(expansion, lame);
- for(Sequence s : and) ret = ret.and(s);
- for(Sequence s : not) ret = ret.not(s);
- }
- else if (unwrap) ret = new Sequence.Unwrap(expansion, drops, and, not);
- else if (tag!=null) {
- ret = Sequence.rewritingSequence(tag, expansion, drops);
- for(Sequence s : and) ret = ret.and(s);
- for(Sequence s : not) ret = ret.not(s);
- } else {
+ if (dropAll || lame) ret = Sequence.drop(expansion, lame);
+ else if (unwrap) ret = new Sequence.Unwrap(expansion, drops);
+ else if (tag!=null) ret = Sequence.rewritingSequence(tag, expansion, drops);
+ else {
int idx = -1;
for(int i=0; i<expansion.length; i++)
if (!drops[i])
else throw new Error("multiple non-dropped elements in sequence: " + Sequence.drop(expansion,false));
if (idx != -1) ret = Sequence.singleton(expansion, idx);
else ret = Sequence.drop(expansion, false);
- for(Sequence s : and) ret = ret.and(s);
- for(Sequence s : not) ret = ret.not(s);
}
+ for(Sequence s : and) ret = ret.and(s);
+ for(Sequence s : not) ret = ret.not(s);
set.add(ret);
if (this.noFollow != null) ret.noFollow = new Atom.Invert(new Atom.Infer(this.noFollow));
return ret;