new checkpoint
[sbp.git] / src / edu / berkeley / sbp / misc / MetaGrammar.java
index 1f0d205..53c194d 100644 (file)
@@ -15,7 +15,7 @@ public class MetaGrammar extends StringWalker {
         return ret.toString();
     }
 
-    private static HashSet<Element> dropAll = new HashSet<Element>();
+    public /*private*/ static HashSet<Element> dropAll = new HashSet<Element>();
 
     // Statics //////////////////////////////////////////////////////////////////////////////
 
@@ -44,6 +44,8 @@ public class MetaGrammar extends StringWalker {
         startSymbol = str;
         nt = new HashMap<String,Union>();
         dropAll = new HashSet<Element>();
+        dropAll.add(leftBrace());
+        dropAll.add(rightBrace());
         nt.put(str, g);
         return ret;
     }
@@ -227,11 +229,12 @@ public class MetaGrammar extends StringWalker {
             else if (tag!=null) ret = Sequence.rewritingSequence(tag, expansion, drops, and, not);
             else {
                 int idx = -1;
-                for(int i=0; i<expansion.length; i++) {
-                    if (!drops[i]) idx = i;
-                    else expansion[i] = expansion[i];
-                }
-                ret = idx==-1 ? Sequence.drop(expansion, and, not, false) : Sequence.singleton(expansion, idx, and, not);
+                for(int i=0; i<expansion.length; i++)
+                    if (!drops[i])
+                        if (idx==-1) idx = i;
+                        else throw new Error("multiple non-dropped elements in sequence: " + Sequence.drop(expansion,null,null,false));
+                if (idx != -1) return Sequence.singleton(expansion, idx, and, not);
+                return Sequence.drop(expansion, and, not, false);
             }
             set.add(ret);
             return ret;