added more flexible handling of Repeats -- now you can specify what they get tagged...
[sbp.git] / src / edu / berkeley / sbp / Sequence.java
index 4d9e41f..7071ecb 100644 (file)
@@ -197,18 +197,19 @@ public abstract class Sequence extends Element implements Iterable<Element> {
 
     public static class Unwrap extends Sequence {
         private boolean[] drops;
-        public Unwrap(Element[] e)                  { super(e); this.drops = null; }
-        public Unwrap(Element[] e, boolean[] drops) { super(e); this.drops = 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, 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, new Object[args.length], true, false, p);
+            if (drops==null) return Forest.create(loc, (T)tag, 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, new Object[args.length], true, false, p);
+            return Forest.create(loc, (T)tag, args2, new Object[args.length], true, false, p);
         }
     }