checkpoint
authoradam <adam@megacz.com>
Thu, 22 Dec 2005 03:13:11 +0000 (22:13 -0500)
committeradam <adam@megacz.com>
Thu, 22 Dec 2005 03:13:11 +0000 (22:13 -0500)
darcs-hash:20051222031311-5007d-f6c3e3445e33fad94c8852988c27d0cafa9af855.gz

src/edu/berkeley/sbp/misc/MetaGrammar.java
src/edu/berkeley/sbp/tib/Tib.java
tests/regression.tc

index 1f0d205..49befee 100644 (file)
@@ -15,7 +15,7 @@ public class MetaGrammar extends StringWalker {
         return ret.toString();
     }
 
-    private static HashSet<Element> dropAll = new HashSet<Element>();
+    public /*private*/ static HashSet<Element> dropAll = new HashSet<Element>();
 
     // Statics //////////////////////////////////////////////////////////////////////////////
 
index 59336df..eabc9ee 100644 (file)
@@ -289,6 +289,10 @@ public class Tib implements Token.Stream<CharToken> {
 
     public static class Grammar extends MetaGrammar {
         private int anon = 0;
+        private final Element ws = Repeat.maximal(Repeat.many0(nonTerminal("w")));
+        public Grammar() {
+            dropAll.add(ws);
+        }
         public Object walk(Tree<String> tree) {
             String head = tree.head();
             if (tree.numChildren()==0) return super.walk(tree);
@@ -297,9 +301,9 @@ public class Tib implements Token.Stream<CharToken> {
                                    new PreSequence[][] {
                                        new PreSequence[] {
                                            new PreSequence(new Element[] { CharToken.leftBrace,
-                                                                           Repeat.maximal(Repeat.many0(nonTerminal("w"))),
-                                                                           ((PreSequence)walk(tree, 0)).buildUnion(),
-                                                                           Repeat.maximal(Repeat.many0(nonTerminal("w"))),
+                                                                           ws,
+                                                                           ((PreSequence)walk(tree, 0)).sparse(ws).buildUnion(),
+                                                                           ws,
                                                                            CharToken.rightBrace
                                            })
                                        }
index 9a7ef50..ce43a84 100644 (file)
@@ -32,7 +32,7 @@ tibcase {
     s        ::= { Hello } => "yep"
     w        ::= " " | "\n"
     ws      !::= w**
-    Hello    ::= "hello" ws { ws "there" ws "how" ws { { "are" } ws } }
+    Hello    ::= "hello" ws { "there" "how" { { "are" } } }
 }
 
 testcase {