- public int[] buildSequence(Production p, String[] names, bind.arg[] argtags) {
- int argTagged = 0;
- for(int i=0; i<argtags.length; i++)
- if (argtags[i] != null)
- argTagged++;
-
- // FIXME: can be smarter here
- if (argTagged==p.count) {
- int[] ret = new int[argtags.length];
- int j = 0;
- for(int i=0; i<argtags.length; i++) {
- if (argtags[i]==null) continue;
- if (argtags[i].value().equals(""))
- ret[i] = j++;
- else {
- ret[i] = -1;
- for(int k=0; k<names.length; k++)
- if (argtags[i].value().equals(names[k])){
- ret[i] = k;
- break;
+ 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);