- public Sequence makeSequence(Production p) {
- return Sequence.rewritingSequence(new TargetReducer(buildSequence(p), _bindable, isRaw()),
- p.elements, p.drops);
+ public Sequence makeSequence(final Production p) {
+
+ if (_bindable.getArgTypes().length > 0 &&
+ _bindable.getArgTypes()[0] == Input.Region.class) {
+ Functor<Input.Region,Object> func = new Functor<Input.Region,Object>() {
+ public Object invoke(final Input.Region region) {
+ return
+ new TreeBindableReducer(buildSequence(p),
+ _bindable,
+ isRaw()) {
+ public Object invoke(Iterable<Tree<Object>> t) {
+ if (_israw) return _bindable.impose(new Object[] { t });
+ ArrayList ret = new ArrayList();
+ ret.add(region);
+ for(Tree tc : t) {
+ if (tc.head() != null && tc.head() instanceof Functor)
+ ret.add(((Tree.TreeFunctor<Object,Object>)tc.head()).invoke(tc.children()));
+ else if (tc.numChildren() == 0)
+ ret.add(tc.head());
+ else {
+ System.err.println("FIXME: don't know what to do about " + tc);
+ ret.add(null);
+ }
+ }
+ Object[] o = (Object[])ret.toArray(new Object[0]);
+ int max = 0;
+ for(int i=0; i<map.length; i++) max = Math.max(map[i], max);
+ Object[] o2 = new Object[max+2];
+ for(int i=0; i<o.length; i++) o2[map[i]+1] = o[i];
+ o2[0] = region;
+ return _bindable.impose(o2);
+ }
+ };
+ }
+ };
+ return Sequence.regionRewritingSequence(func,
+ p.elements,
+ p.drops);
+ }
+
+ return Sequence.rewritingSequence(new TreeBindableReducer(buildSequence(p),
+ _bindable,
+ isRaw()),
+ p.elements,
+ p.drops);