- }
-
- static class Unwrap extends Sequence {
- private boolean[] drops;
- private final Object tag;
- public Unwrap(Element[] e, Object tag) { super(e); this.drops = null; this.tag = tag; }
- public Unwrap(Element[] e, Object tag, boolean[] drops) { super(e); this.drops = drops; this.tag = tag; }
- Sequence _clone() { return new Unwrap(elements, tag, drops); }
- public <T> Forest<T> postReduce(Input.Region 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, (T)tag, args, true);
- 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, (T)tag, args2, true);
- }
- }
-
-
-
- static class RegionRewritingSequence extends RewritingSequence {
- private Functor<Input.Region, Object> tagf;
- public RegionRewritingSequence(Functor<Input.Region,Object> tagfunctor, Element[] e, boolean[] drops) {
- super(null, e, drops);
- this.tagf = tagfunctor;
- }
- public <T> Forest<T> postReduce(Input.Region loc, Forest<T>[] args, Position p) {
- this.tag = tagf.invoke(loc);
- Forest<T> ret = super.postReduce(loc, args, p);
- this.tag = null;
- return ret;