checkpoint
[sbp.git] / src / edu / berkeley / sbp / meta / MetaGrammarBindings.java
index ca253f1..da0204a 100644 (file)
@@ -47,14 +47,23 @@ public class MetaGrammarBindings {
     }
 
     public static class NonTerminal extends Un {
+        public boolean rep;
         public String  name = null;
-        public @bind NonTerminal(@bind.arg String name,
-                                 @bind.arg Seq[][] sequences) {
+        public String sep = null;
+        public @bind NonTerminal(@bind.arg String name, @bind.arg Seq[][] sequences) { this(name, sequences, false); }
+        public NonTerminal(String name, Seq[][] sequences, boolean rep) { this(name, sequences, rep, null); }
+        public NonTerminal(String name, Seq[][] sequences, boolean rep, String sep) {
             this.name = name;
             this.sequences = sequences;
+            this.rep = rep;
+            this.sep = sep;
         }
         public Element build(MetaGrammar.Context cx) { return cx.get(name); }
     }
+    public static @bind.as("=") NonTerminal go(@bind.arg String name, @bind.arg Seq[][] sequences) { return new NonTerminal(name, sequences, true); }
+    public static @bind.as("=") NonTerminal go(@bind.arg String name, @bind.arg String sep, @bind.arg Seq[][] sequences) {
+        return new NonTerminal(name, sequences, true, sep);
+    }
 
     public static class AnonUn extends Un {
         public @bind.as("(") AnonUn(Seq[][] sequences) {
@@ -172,13 +181,14 @@ public class MetaGrammarBindings {
             return ret;
         }
     }
-    public static @bind.as("&")   Seq  and(Seq s,         El[] elements) { return s.and(seq(elements)); }
-    public static @bind.as("&~")  Seq  andnot(Seq s,      El[] elements) { return s.andnot(seq(elements)); }
+    public static @bind.as("&")   Seq  and2(Seq s,        Seq a) { return s.and(a); }
+    public static @bind.as("&~")  Seq  andnot2(Seq s,     Seq a) { return s.andnot(a); }
     public static @bind.as("->")  Seq  arrow(Seq s, El e)                { return s.follow(e); }
     public static @bind.as("::")  Seq  tag(String tagname, Seq s)        { return s.tag(tagname); }
     public static @bind.as("/")   Seq  slash(Seq s, El e)                { return s.separate(e); }
 
-    public static @bind.as("ps")  Seq  seq(El[] elements)                { return new Seq(elements); }
+    public static Seq  seq(El[] elements)               { return new Seq(elements); }
+    public static @bind.as("Elements")  Seq  seq2(El[] elements)               { return new Seq(elements); }
     public static @bind.as        Seq  psx(Seq s)                        { return s; }
     public static @bind.as(":")   El   colon(String s, El e)             { return new Label(s, e); }
     public static @bind.as(")")   void close(String foo)                 { throw new Error("not supported"); }
@@ -208,7 +218,17 @@ public class MetaGrammarBindings {
     public static @bind.as("{")           class XTree                 extends El {
         public @bind.arg Seq body;
         public Element build(MetaGrammar.Context cx) {
-            throw new Error();
+            Union u = new Union();
+            Sequence s = body.build(cx, u, false);
+            Union u2 = new Union();
+            u2.add(Sequence.singleton(new Element[] {
+                CharRange.leftBrace,
+                cx.get("ws"),
+                u,
+                cx.get("ws"),
+                CharRange.rightBrace
+            }, 2));
+            return u2;
         }
     }
 
@@ -266,12 +286,12 @@ public class MetaGrammarBindings {
 
     //public static @bind.as("(")   El subexpression(Seq[][] rhs)                { return new NonTerminal(rhs); }
 
-    public static @bind.as("Word")    String word(String s) { return s; }
-    public static @bind.as("Quoted")  String quoted(String s) { return s; }
-    public static @bind.as("escaped") String c(char c) { return c+""; }
-    public static @bind.as("\"\"")    String emptystring() { return ""; }
-    public static @bind.as("\n")      String retur() { return "\n"; }
-    public static @bind.as("\r")      String lf() { return "\r"; }
+    public static @bind.as("Word")        String word(String s) { return s; }
+    public static @bind.as("Quoted")      String quoted(String s) { return s; }
+    public static @bind.as("escaped")     String c(char c) { return c+""; }
+    public static @bind.as("EmptyString") String emptystring() { return ""; }
+    public static @bind.as("\n")          String retur() { return "\n"; }
+    public static @bind.as("\r")          String lf() { return "\r"; }
 
     static Atom infer(Element e)  { return infer((Topology<Character>)Atom.toAtom(e)); }
     static Atom infer(Topology<Character> t) { return new CharRange(new CharTopology(t)); }