X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2FSequence.java;h=e5db6c8360e8535bf4ff04255a8620aa5070b731;hp=e09ff720a3cab47f5356130662b5b04ef164bf91;hb=a26089cd0d7c95cad657b745e836cb4cba35a97a;hpb=b205c5ee125119b0372328b70e8a66164df18fd0 diff --git a/src/edu/berkeley/sbp/Sequence.java b/src/edu/berkeley/sbp/Sequence.java index e09ff72..e5db6c8 100644 --- a/src/edu/berkeley/sbp/Sequence.java +++ b/src/edu/berkeley/sbp/Sequence.java @@ -42,8 +42,11 @@ public abstract class Sequence extends Element implements Iterable { * @param drops only elements of e whose corresponding boolean in drops * is false will be included in the output tree **/ - public static Sequence rewritingSequence(Object tag, Element[] e, Object[] labs, boolean[] drops) { - return new RewritingSequence(tag, e, labs, drops); } + public static Sequence rewritingSequence(Object tag, Element[] e, boolean[] drops) { + return new RewritingSequence(tag, e, drops); } + + public static Sequence regionRewritingSequence(Functor tagfunctor, Element[] e, boolean[] drops) { + return new RegionRewritingSequence(tagfunctor, e, drops); } //////////////////////////////////////////////////////////////////////////////// @@ -85,7 +88,7 @@ public abstract class Sequence extends Element implements Iterable { return epsilonForm; } - protected abstract Forest postReduce(Input.Location loc, Forest[] args, Position p); + protected abstract Forest postReduce(Input.Region loc, Forest[] args, Position p); // Position ////////////////////////////////////////////////////////////////////////////// @@ -127,8 +130,8 @@ public abstract class Sequence extends Element implements Iterable { // Position ///////////////////////////////////////////////////////////////////////////////// - final Forest rewrite(Input.Location loc) { return rewrite(loc, true); } - private final Forest rewrite(Input.Location loc, boolean epsilonCheck) { + final Forest rewrite(Input.Region loc) { return rewrite(loc, true); } + private final Forest rewrite(Input.Region loc, boolean epsilonCheck) { if (epsilonCheck && this==firstp()) return epsilonForm(); for(int i=0; i { private final Object result; public Constant(Element[] e, Object result) { super(e); this.result = result; } Sequence _clone() { return new Constant(elements, result); } - public Forest postReduce(Input.Location loc, Forest[] args, Position p) { - return (Forest)Forest.leaf(loc, result, p); + public Forest postReduce(Input.Region loc, Forest[] args, Position p) { + return (Forest)Forest.create(loc, result, null, false); } static class Drop extends Constant { Sequence _clone() { return new Drop(elements, lame); } @@ -199,7 +202,7 @@ public abstract class Sequence extends Element implements Iterable { private final int idx; public Singleton(Element e) { this(new Element[] { e }, 0); } public Singleton(Element[] e, int idx) { super(e); this.idx = idx; } - public Forest postReduce(Input.Location loc, Forest[] args, Position p) { return (Forest)Forest.singleton(loc, args[idx], p); } + public Forest postReduce(Input.Region loc, Forest[] args, Position p) { return args[idx]; } Sequence _clone() { return new Singleton(elements,idx); } } @@ -210,39 +213,52 @@ public abstract class Sequence extends Element implements Iterable { 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 Forest postReduce(Input.Location loc, Forest[] args, Position p) { + public Forest postReduce(Input.Region loc, Forest[] args, Position p) { for(int i=0; i[] args2 = new Forest[count]; int j = 0; for(int i=0; i tagf; + public RegionRewritingSequence(Functor tagfunctor, Element[] e, boolean[] drops) { + super(null, e, drops); + this.tagf = tagfunctor; + } + public Forest postReduce(Input.Region loc, Forest[] args, Position p) { + this.tag = tagf.invoke(loc); + Forest ret = super.postReduce(loc, args, p); + this.tag = null; + return ret; } } static class RewritingSequence extends Sequence { - /*private*/public final Object tag; + /*private*/public /*final*/ Object tag; private final boolean[] drops; - private final Object[] labs; private int count = 0; - 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) { + 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) { super(e); this.tag = tag; this.drops = drops == null ? new boolean[e.length] : drops; for(int i=0; i Forest postReduce(Input.Location loc, Forest[] args, Position p) { + public Forest postReduce(Input.Region loc, Forest[] args, Position p) { Forest[] args2 = new Forest[count]; - Object[] labs2 = new Object[count]; int j = 0; - for(int i=0; i