checkpoint
[sbp.git] / tests / meta.g
index eb793c5..11cb9f8 100644 (file)
@@ -1,22 +1,31 @@
+// use 'a'-'z' or 'a-z' instead of [a-z]?
+// EOF token?
+// #include (with renaming?)
+
 s             =  ws! Grammar ws!
 
-Grammar       =  NonTerminal +/ ws
+Grammar       =  Declaration +/ ws
 
-NonTerminal   =  Word "=" RHS /ws
+Declaration   =  NonTerminal
+              |  ^"#import" ws! FileName //(ws! "as" ws! Prefix)?
 
-// use 'a'-'z' or 'a-z' instead of [a-z]?
-// EOF token?
-// #include (with renaming?)
-// ANTLR uses ! and ^ suffixes
-        
+//Prefix        = ([a-zA-Z] ".")+ "*"
+FileName      = FileNameChar+ -> [\r\n ]
+FileNameChar  = Space:: "\\ "
+              | ~[\r\n ]
+
+NonTerminal   =  Word           "="     RHS /ws
+              |  Word  "*" ws! ^"=" ws! RHS
+              |  Word  "*/" Word ws! ^"=" ws! RHS
+       
 RHS           =  (Sequence +/ (ws! "|" ws!)) +/ (ws! ">" ws!)
 
 Elements      =  e*/ws
 
-PreSequence   = ps::  Elements
-              |       (Quoted|Word)   ^"::" PreSequence /ws
-              >       PreSequence     ^"/"      e       /ws
-              |       PreSequence     ^"->"     e       /ws
+PreSequence   =  Elements
+              |  (Quoted|Word)   ^"::" PreSequence /ws
+              >  PreSequence     ^"/"      e       /ws
+              |  PreSequence     ^"->"     e       /ws
 
 Sequence      = psx:: PreSequence
               |       Sequence ^"&"  Elements /ws
@@ -45,7 +54,6 @@ e             =                (Quoted|Word) ^":" e
               |                     e ^"!"
               |                e ^"?"                    /ws
               |                  ^"^"   Quoted
-              |                  Quoted ^"^"
               >                  ^"(" RHS  ")"           /ws
               |                  ^"~" e
 
@@ -53,7 +61,8 @@ NonTerminalReference = Word
 Literal              = Quoted
 Word                 = [a-zA-Z0-9_]++
 Quoted               = "\"" ((~[\"\\] | escaped)+) "\""
-                     | ""::   "\"\""
+                     | EmptyString
+                       EmptyString = "\"\""
 
 escaped    = "\n":: "\\n"
            | "\r":: "\\r"