* @param e the elements to match
* @param drops only elements of <tt>e</tt> whose corresponding <tt>boolean</tt> in <tt>drops</tt> is <i>false</i> will be included in the output tree
**/
- public static Sequence rewritingSequence(Object tag, Element[] e, boolean[] drops) { return new RewritingSequence(tag, e, drops); }
+ public static Sequence rewritingSequence(Object tag, Element[] e, Object[] labs, boolean[] drops) {
+ return new RewritingSequence(tag, e, labs, drops); }
////////////////////////////////////////////////////////////////////////////////
Sequence _clone() { return new Unwrap(elements, drops); }
public <T> Forest<T> postReduce(Input.Location loc, Forest<T>[] args, Position p) {
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, p);
+ if (drops==null) return Forest.create(loc, null, args, new Object[args.length], true, false, p);
int count = 0;
for(int i=0; i<drops.length; i++) if (!drops[i]) count++;
Forest<T>[] args2 = new Forest[count];
int j = 0;
for(int i=0; i<args.length; i++) if (!drops[i]) args2[j++] = args[i];
- return Forest.create(loc, null, args2, true, false, p);
+ return Forest.create(loc, null, args2, new Object[args.length], true, false, p);
}
}
static class RewritingSequence extends Sequence {
/*private*/public final Object tag;
private final boolean[] drops;
+ private final Object[] labs;
private int count = 0;
- Sequence _clone() { return new RewritingSequence(tag, elements, drops); }
- public RewritingSequence(Object tag, Element[] e) { this(tag, e, null); }
- public RewritingSequence(Object tag, Element[] e, boolean[] drops) {
+ Sequence _clone() { return new RewritingSequence(tag, elements, labs, drops); }
+ public RewritingSequence(Object tag, Element[] e, Object[] labs) { this(tag, e, labs, null); }
+ public RewritingSequence(Object tag, Element[] e, Object[] labs, boolean[] drops) {
super(e);
this.tag = tag;
this.drops = drops == null ? new boolean[e.length] : drops;
for(int i=0; i<this.drops.length; i++) if (!this.drops[i]) count++;
+ this.labs = labs;
}
public <T> Forest<T> postReduce(Input.Location loc, Forest<T>[] args, Position p) {
Forest<T>[] args2 = new Forest[count];
+ Object[] labs2 = new Object[count];
int j = 0;
- for(int i=0; i<args.length; i++) if (!drops[i]) args2[j++] = args[i];
+ for(int i=0; i<args.length; i++) if (!drops[i]) { labs2[j] = labs==null?null:labs[i]; args2[j++] = args[i]; }
//System.out.println("reduce \""+tag+"\"");
- return Forest.create(loc, (T)tag, args2, false, false, p);
+ return Forest.create(loc, (T)tag, args2, labs2, false, false, p);
}
public StringBuffer toString(StringBuffer sb, boolean spacing) {
int len = sb.length();