add LabelNode
authoradam <adam@megacz.com>
Tue, 4 Mar 2008 05:09:51 +0000 (00:09 -0500)
committeradam <adam@megacz.com>
Tue, 4 Mar 2008 05:09:51 +0000 (00:09 -0500)
darcs-hash:20080304050951-5007d-9277771831af51cbfee7ab5db853f1d4256db114.gz

src/edu/berkeley/sbp/meta/GrammarAST.java

index e039b37..586d519 100644 (file)
@@ -96,6 +96,7 @@ public class GrammarAST {
         if (head.equals("Elements")) return new Seq((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)), true);
         if (head.equals("Elements")) return new Seq((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)), true);
+        if (head.equals(":"))   return new LabelNode(stringifyChildren(t.child(0)), walkElement(t.child(1)));
         if (head.equals("::"))  return walkSeq(t.child(1)).tag(walkString(t.child(0)));
         if (head.equals("...")) return new DropNode(new RepeatNode(new TildeNode(new AtomNode()), null, true,  true,  false));
 
         if (head.equals("::"))  return walkSeq(t.child(1)).tag(walkString(t.child(0)));
         if (head.equals("...")) return new DropNode(new RepeatNode(new TildeNode(new AtomNode()), null, true,  true,  false));
 
@@ -546,6 +547,12 @@ public class GrammarAST {
         public boolean isDropped(Context cx) { return true; }
     }
 
         public boolean isDropped(Context cx) { return true; }
     }
 
+    /** provides a label on the fields of a Seq */
+    private class LabelNode extends ElementNodeWrapper {
+        public final String label;
+        public LabelNode(String label, ElementNode e) { super(e); this.label = label; }
+    }
+
     //////////////////////////////////////////////////////////////////////////////
 
     public class Context {
     //////////////////////////////////////////////////////////////////////////////
 
     public class Context {