fix error caused when building error message
[sbp.git] / src / edu / berkeley / sbp / meta / GrammarBuilder.java
index d9b04c2..2b1d765 100644 (file)
@@ -84,6 +84,7 @@ public class GrammarBuilder {
         if (head.equals("Elements")) return seq2((ElementNode[])Reflection.rebuild(walkChildren(t), ElementNode[].class));
         if (head.equals("NonTerminalReference")) return new ReferenceNode(stringifyChildren(t.child(0)));
         //if (head.equals(")")) return new ReferenceNode(stringifyChildren(t.child(0)));
+        if (head.equals("{")) return new XTree((Seq)walk(t.child(0)));
         if (head.equals("::")) return tag((String)walk(t.child(0)), (Seq)walk(t.child(1)));
         if (head.equals("++")) return plusmax((ElementNode)walk(t.child(0)));
         if (head.equals("+")) return plus((ElementNode)walk(t.child(0)));
@@ -99,7 +100,7 @@ public class GrammarBuilder {
         if (head.equals("Quoted")) return stringifyChildren(t);
         if (head.equals("Literal")) return new LiteralNode((String)walk(t.child(0)));
         if (head.equals("->")) return arrow((Seq)walk(t.child(0)), (ElementNode)walk(t.child(1)));
-        if (head.equals("DropNT")) return new NonTerminalNode((String)walk(t.child(0)), (Seq[][])walk(t.child(1)), true, null, true);
+        if (head.equals("DropNT")) return new NonTerminalNode((String)walk(t.child(0)), (Seq[][])walkChildren(t.child(1)), false, null, true);
         if (head.equals("=") && t.size()==2) return new NonTerminalNode((String)walk(t.child(0)), (Seq[][])walk(t.child(1)), true, null, false);
         if (head.equals("=")) return new NonTerminalNode((String)walk(t.child(0)), (Seq[][])walk(t.child(2)), true, (String)walk(t.child(1)), false);
         if (head.equals("&")) return and2((Seq)walk(t.child(0)), (Seq)walk(t.child(1)));
@@ -326,8 +327,6 @@ public class GrammarBuilder {
                 if (!drops[i])
                     if (idx==-1) idx = i;
                     else multiNonDrop = true;
-            if (tag==null && multiNonDrop)
-                throw new Error("multiple non-dropped elements in sequence: " + Sequence.create(els, ""));
             for(int i=0; i<elements.length; i++) {
                 if (!multiNonDrop && i==idx && tag!=null && elements[i] instanceof RepeatNode) {
                     els[i] = ((RepeatNode)elements[i]).build(cx, cnt, dropall, tag);
@@ -335,6 +334,8 @@ public class GrammarBuilder {
                 } else
                     els[i] = elements[i].build(cx, cnt, dropall);
             }
+            if (tag==null && multiNonDrop)
+                throw new RuntimeException("multiple non-dropped elements in sequence: " + Sequence.create(els, ""));
             if (!multiNonDrop) {
                 if (idx == -1) 
                     ret = tag==null
@@ -501,9 +502,9 @@ public class GrammarBuilder {
 
     }
 
-    /*
-    public            class XTree                 extends ElementNode {
-        public  Seq body;
+    public class XTree extends ElementNode {
+        public Seq body;
+        public XTree(Seq seq) { this.body = seq; }
         public Element build(Context cx, NonTerminalNode cnt, boolean dropall) {
             Union u = new Union(null, false);
             Sequence s = body.build(cx, u, null, dropall);
@@ -518,5 +519,4 @@ public class GrammarBuilder {
             return u2;
         }
     }
-    */
 }