checkpoint
authoradam <adam@megacz.com>
Thu, 13 Jul 2006 21:43:50 +0000 (17:43 -0400)
committeradam <adam@megacz.com>
Thu, 13 Jul 2006 21:43:50 +0000 (17:43 -0400)
darcs-hash:20060713214350-5007d-4a9695efeb8dac98fe780cb7c3b699367dae496f.gz

src/edu/berkeley/sbp/meta/MetaGrammarBindings.java
tests/meta.g

index 9ccf8a8..742918b 100644 (file)
@@ -85,12 +85,17 @@ public class MetaGrammarBindings {
         }
     }
 
-    public static @bind.as("#import") GrammarNode poundimport(String fileName) {
-        System.err.println("#import " + fileName);
+    public static @bind.as("#import") GrammarNode poundimport(String fileName, String as) {
+        if (as==null) as = "";
+        System.err.println("#import " + fileName + " as " + as);
         try {
             Tree t = new CharParser(MetaGrammar.make()).parse(new FileInputStream(fileName)).expand1();
             Tree.TreeFunctor<Object,Object> red = (Tree.TreeFunctor<Object,Object>)t.head();
-            return (MetaGrammarBindings.GrammarNode)red.invoke(t);
+            String oldprefix = prefix;
+            prefix = as;
+            GrammarNode gn = (GrammarNode)red.invoke(t);
+            prefix = oldprefix;
+            return gn;
         } catch (Exception e) {
             e.printStackTrace();
             throw new RuntimeException(e);
index 51e55be..4416d55 100644 (file)
@@ -7,9 +7,9 @@ s             =  ws! Grammar ws!
 Grammar       =  Declaration +/ ws
 
 Declaration   =  NonTerminal
-              |  ^"#import" ws! FileName //(ws! "as" ws! Prefix)?
+              |  ^"#import" ws! FileName (ws! "as" ws! Prefix)?
 
-//Prefix        = ([a-zA-Z] ".")+ "*"
+Prefix        = ([a-zA-Z] ".")+ "*"
 FileName      = FileNameChar+ -> [\r\n ]
 FileNameChar  = Space:: "\\ "
               | ~[\r\n ]