- private int[] buildSequence(Production p, String[] names, bind.arg[] argtags, Class[] types) {
- int argTagged = 0;
- boolean hasloc = types.length>0 && types[0]==Input.Region.class;
- for(int i=0; i<argtags.length; i++) {
- if (i==0 && types[0]==Input.Region.class) continue;
- if (argtags[i] != null)
- argTagged++;
- }
- int numNames = names.length;
- if (hasloc) numNames--;
-
- // 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 (i==0 && types[0]==Input.Region.class) continue;
- 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;
- }
- if (ret[i]==-1) return null;
- }
- }
- return ret;
- } else if (numNames==p.count) {
- int[] ret = new int[p.count];
- for(int i=0; i<p.count; i++) ret[i] = i+(hasloc?1:0);
- return ret;
- } else {
- return null;
- }
- }