checkpoint
[sbp.git] / src / edu / berkeley / sbp / meta / MetaGrammar.java
index aa02d5f..2077bbd 100644 (file)
@@ -127,7 +127,7 @@ public class MetaGrammar {
                 return buildSequence(p)!=null;
 
             bind b = getBind();
-            System.out.println(_bindable.getClass().getSimpleName() + ": " + _bindable.getSimpleName());
+            //System.out.println(_bindable.getClass().getSimpleName() + ": " + _bindable.getSimpleName());
             if (b != null && getName().equals(p.tag))
                 return buildSequence(p)!=null;
 
@@ -150,15 +150,27 @@ public class MetaGrammar {
                     argTagged++;
 
             // FIXME: can be smarter here
-            if (names.length==p.count) {
-                int[] ret = new int[p.count];
-                for(int i=0; i<p.count; i++) ret[i] = i;
-                return ret;
-            } else if (argTagged==p.count) {
+            if (argTagged==p.count) {
                 int[] ret = new int[argtags.length];
                 int j = 0;
-                for(int i=0; i<argtags.length; i++)
-                    ret[i] = argtags[i]==null ? -1 : (j++);
+                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;
+                            }
+                        if (ret[i]==-1) return null;
+                    }
+                }
+                return ret;
+            } else if (names.length==p.count) {
+                int[] ret = new int[p.count];
+                for(int i=0; i<p.count; i++) ret[i] = i;
                 return ret;
             } else {
                 return null;
@@ -206,7 +218,7 @@ public class MetaGrammar {
                     ret.add(null);
                 }
             }
-            System.err.println("input tree: " + t);
+            //System.err.println("input tree: " + t);
             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);
@@ -237,17 +249,14 @@ public class MetaGrammar {
     }
     public static Union make(Tree t, String s) { return make(t, s, new AnnotationGrammarBindingResolver()); }
     public static Union make(Tree t, String s, GrammarBindingResolver rm) {
-        System.out.println("Head: " + t.head());
         Tree.TreeFunctor<Object,Object> red = (Tree.TreeFunctor<Object,Object>)t.head();
         MetaGrammarBindings.Grammar g = (MetaGrammarBindings.Grammar)red.invoke(t.children());
         Context cx = new Context(g,rm);
         Union u = null;
-        for(MetaGrammarBindings.NonTerminal nt : g.nonterminals) {
-            System.out.println(nt.name);
+        for(MetaGrammarBindings.NonTerminal nt : g.values()) {
             Union el = (Union)cx.get(nt.name);
             StringBuffer st = new StringBuffer();
             el.toString(st);
-            System.err.println(st);
             if (nt.name.equals(s)) u = el;
         }
         return u;
@@ -266,7 +275,7 @@ public class MetaGrammar {
         }
         public Union build() {
             Union ret = null;
-            for(MetaGrammarBindings.NonTerminal nt : grammar.nonterminals) {
+            for(MetaGrammarBindings.NonTerminal nt : grammar.values()) {
                 Union u = get(nt.name);
                 if ("s".equals(nt.name))
                     ret = u;