checkpoint
authoradam <adam@megacz.com>
Thu, 13 Jul 2006 22:12:41 +0000 (18:12 -0400)
committeradam <adam@megacz.com>
Thu, 13 Jul 2006 22:12:41 +0000 (18:12 -0400)
darcs-hash:20060713221241-5007d-280d07d02103c981c77deb6230beb640120c1a35.gz

src/edu/berkeley/sbp/meta/AnnotationGrammarBindingResolver.java
src/edu/berkeley/sbp/meta/MetaGrammarBindings.java
src/edu/berkeley/sbp/misc/RegressionTests.java
tests/meta.g
tests/testcase.g

index 761b460..8601ee7 100644 (file)
@@ -50,7 +50,6 @@ public class AnnotationGrammarBindingResolver extends GrammarBindingResolver {
         String prefix = key.indexOf('.')==-1 ? "" : key.substring(0, key.lastIndexOf('.'));
         String suffix = key.indexOf('.')==-1 ? key : key.substring(key.lastIndexOf('.')+1);
 
-        //System.err.println("suffix = " + suffix);
         MetaGrammar.Production p = new MetaGrammar.Production(suffix, suffix, els, drops);
         for(Method m : _allMethods.get(prefix))
             if (new MetaGrammar.Target(m).isCompatible(p))
index 742918b..c7952b0 100644 (file)
@@ -87,6 +87,9 @@ public class MetaGrammarBindings {
 
     public static @bind.as("#import") GrammarNode poundimport(String fileName, String as) {
         if (as==null) as = "";
+        else if ("".equals(as)) { }
+        else as = as +".";
+        
         System.err.println("#import " + fileName + " as " + as);
         try {
             Tree t = new CharParser(MetaGrammar.make()).parse(new FileInputStream(fileName)).expand1();
@@ -214,14 +217,14 @@ public class MetaGrammarBindings {
         }
         public Seq(ElementNode e) { this(new ElementNode[] { e }); }
         public Seq(ElementNode[] elements) { this.elements = elements; }
-        public Seq tag(String tag) { this.tag = tag; return this; }
+        public Seq tag(String tag) { this.tag = prefix+tag; return this; }
         public Seq follow(ElementNode follow) { this.follow = follow; return this; }
         public Seq dup() {
             Seq ret = new Seq(elements);
             ret.and.addAll(and);
             ret.not.addAll(not);
             ret.follow = follow;
-            ret.tag = tag;
+            ret.tag = prefix+tag;
             return ret;
         }
         public Seq and(Seq s) { and.add(s); s.lame = true; return this; }
@@ -246,7 +249,7 @@ public class MetaGrammarBindings {
         }
         public Sequence build0(Context cx, boolean lame, NonTerminalNode cnt) {
             boolean dropAll = lame;
-            if (tag!=null && "()".equals(tag)) dropAll = true;
+            if (tag!=null && tag.endsWith("()")) dropAll = true;
             boolean[] drops = new boolean[elements.length];
             Element[] els = new Element[elements.length];
             for(int i=0; i<elements.length; i++) {
@@ -383,8 +386,9 @@ public class MetaGrammarBindings {
     { return new Drop(e); }
 
     public static @bind.as("^")   ElementNode caret(final String s) {
+        final String thePrefix = prefix;
         return new Drop(new Constant(CharRange.string(s)) {
-                public String getOwnerTag() { return s; }
+                public String getOwnerTag() { return thePrefix+s; }
             });
     }
 
index fd76e77..21abaa5 100644 (file)
@@ -93,8 +93,8 @@ public class RegressionTests {
     public static class TestCaseMaker extends AnnotationGrammarBindingResolver {
         public TestCaseMaker() {
             super(TestCaseMakerHelper.class);
-            //add(MetaGrammarBindings.class, "grammar.");
-            add(MetaGrammarBindings.class, "");
+            add(MetaGrammarBindings.class, "grammar");
+            //add(MetaGrammarBindings.class, "");
         }
         public static class TestCaseMakerHelper {
             public static @bind.as("grammaro") @bind.raw Object grammaro(Iterable<Tree> t) {
index cc2b1d7..216d3bf 100644 (file)
@@ -7,9 +7,8 @@ s             =  ws! Grammar ws!
 Grammar       =  Declaration +/ ws
 
 Declaration   =  NonTerminal
-              |  ^"#import" ws! FileName (ws! "as" ws! Prefix)?
+              |  ^"#import" ws! FileName (ws! "as" ws! Word)?
 
-Prefix        = ([a-zA-Z] ".")+ "*"
 FileName      = FileNameChar+ -> [\r\n ]
 FileNameChar  = Space:: "\\ "
               | ~[\r\n ]
index 5212e91..01ce08b 100644 (file)
@@ -1,8 +1,9 @@
-#import tests/meta.g
+#import tests/meta.g as grammar
 
-ts         = ts:: ws! tests ws!
-tests      =      test */ ws
-test       =   tca::   "testcase" "{" input (o::(output +/ ws))   (grammaro::Grammar) "}" /ws
-           |   tcb::   "testcase" "{" input                       (grammaro::Grammar) "}" /ws
-output     =           "output" Quoted ";" /ws
-input      =           "input"  Quoted ";" /ws
+xws         = grammar.ws
+ts         = ts:: xws! tests xws!
+tests      =      test */ xws
+test       =   tca::   "testcase" "{" input (o::(output +/ xws))   (grammaro::grammar.Grammar) "}" /xws
+           |   tcb::   "testcase" "{" input                       (grammaro::grammar.Grammar) "}" /xws
+output     =           "output" grammar.Quoted ";" /xws
+input      =           "input"  grammar.Quoted ";" /xws