final <T> Forest<T> rewrite(Token.Location loc) {
if (this==firstp() && eps) return epsilonForm;
eps = true;
- for(int i=pos; i<elements.length; i++) if (holder[i]==null) holder[i] = elements[i].epsilonForm();
+ for(int i=0; i<pos; i++) if (holder[i]==null) throw new Error("realbad " + i);
+ for(int i=pos; i<elements.length; i++) {
+ if (holder[i]==null) holder[i] = elements[i].epsilonForm();
+ if (holder[i]==null) throw new Error("bad " + i);
+ }
Forest<T> ret = Sequence.this.postReduce(loc, holder);
for(int k=0; k<pos; k++) holder[k] = null; // to help GC
if (this==firstp()) { if (epsilonForm==null) epsilonForm=new Forest.Ref(); epsilonForm.merge(ret); return epsilonForm; }
public <T> Forest<T> postReduce(Token.Location loc, Forest<T>[] args) { return (Forest<T>)Forest.singleton(loc, args[idx], this); }
}
- static class Unwrap extends Sequence {
+ 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 <T> Forest<T> postReduce(Token.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, this, true, false);
int count = 0;
for(int i=0; i<drops.length; i++) if (!drops[i]) count++;
}
static class RewritingSequence extends Sequence {
- private final Object tag;
+ /*private*/public final Object tag;
private final boolean[] drops;
private int count = 0;
public RewritingSequence(Object tag, Element[] e, HashSet<Sequence> and, HashSet<Sequence> not) { this(tag, e, null, and, not); }