backported some stuff
authoradam <adam@megacz.com>
Mon, 2 Jan 2006 02:03:29 +0000 (21:03 -0500)
committeradam <adam@megacz.com>
Mon, 2 Jan 2006 02:03:29 +0000 (21:03 -0500)
darcs-hash:20060102020329-5007d-4f42b90d881f898c630d76dae5922ccaa9fb3b54.gz

src/edu/berkeley/sbp/misc/MetaGrammar.java

index 49befee..b2db78e 100644 (file)
@@ -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;