checkpoint
authoradam <adam@megacz.com>
Mon, 19 Dec 2005 09:05:32 +0000 (04:05 -0500)
committeradam <adam@megacz.com>
Mon, 19 Dec 2005 09:05:32 +0000 (04:05 -0500)
darcs-hash:20051219090532-5007d-74cffe8a1d8662d93fb5ae879214a01faf5c5661.gz

src/edu/berkeley/sbp/misc/MetaGrammar.java
tests/meta.g

index 031dccd..656f878 100644 (file)
@@ -119,11 +119,17 @@ public class MetaGrammar extends ReflectiveWalker {
     public Object _plus__plus_(final Element r)             { return Repeat.maximal(Repeat.many1(r)); }
     public Element _question_(final Element r)              { return Repeat.maybe(r); }
 
+    public Object walk(Tree<String> tree) {
+        String head = tree.head();
+        if (tree.numChildren()==0) return super.walk(tree);
+        if      ("\\n".equals(head)) return new Character('\n');
+        else if ("\\r".equals(head)) return new Character('\r');
+        else return super.walk(tree);
+    }
+
     public MetaGrammar grammar(Object o, Union[] u, Object x) { return this; }
     public Object gram(Object o, Object g, Object o2) { return g; }
     public MetaGrammar  grammar(Object[] o) { return this; }
-    public char    _backslash_n() { return '\n'; }
-    public char    _backslash_r() { return '\r'; }
     public Element    literal(String s) { Element ret = string(s); dropAll.add(ret); return ret; }
     public Range     _minus_(char a, char b) { return new Range(a, b); }
     public Range     range(char a)         { return new Range(a, a); }
index 0ba0548..292991c 100644 (file)
@@ -1,14 +1,15 @@
 s         ::=  ws grammar ws                  => "gram"
-ws       !::=  w**
+ws      !::=  w**
 grammar   ::=  r +/ ws                        => "grammar"
+
 r         ::=  word  ^"::=" alternatives /ws
             |  word ^"!::=" alternatives /ws
 
 alternatives  ::=  (conjuncts +/ (ws "|" ws)) +/ (ws ">" ws)
 
-conjuncts   ::=  sequence
-              |  sequence ^"&"  e*/ws   /ws
-              |  sequence ^"&~" e*/ws   /ws
+conjuncts     ::=  sequence
+                |  sequence ^"&"  e*/ws   /ws
+                |  sequence ^"&~" e*/ws   /ws
 
 ps          ::= e*/ws                              => "ps"
               | (e+/ws ws)? "^" quoted (ws e+/ws)? => "ps2"
@@ -38,7 +39,6 @@ e        ::=  word                          => "nonTerminal"
 
            |     "(" word         ^")"  /ws
            >    ^"(" alternatives  ")"  /ws
-
 w       !::= " "
            | "//" ([~\n]*) "\n"
            | "\n"