checkpoint
[sbp.git] / tests / meta.g
index 0d2be6f..11cb9f8 100644 (file)
@@ -1,31 +1,47 @@
-s             =  ws grammar:Grammar ws
-Grammar       =  NonTerminal +/ ws
-NonTerminal   =  Word  !wp ^"=" !wp RHS
-        
-RHS           =  (Sequence +/ (!ws "|" !ws)) +/ (!ws ">" !ws)
+// use 'a'-'z' or 'a-z' instead of [a-z]?
+// EOF token?
+// #include (with renaming?)
+
+s             =  ws! Grammar ws!
+
+Grammar       =  Declaration +/ ws
+
+Declaration   =  NonTerminal
+              |  ^"#import" ws! FileName //(ws! "as" ws! Prefix)?
+
+//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 !wp ^"/"   !ws e
-              |       PreSequence     ^"->"     e /ws
+PreSequence   =  Elements
+              |  (Quoted|Word)   ^"::" PreSequence /ws
+              >  PreSequence     ^"/"      e       /ws
+              |  PreSequence     ^"->"     e       /ws
 
 Sequence      = psx:: PreSequence
-              |       Sequence !ws ^"&"  !ws Elements
-              |       Sequence !ws ^"&~" !ws Elements
+              |       Sequence ^"&"  Elements /ws
+              |       Sequence ^"&~" Elements /ws
 
 ec            = ~[\-\]\\]
               | escaped
 
-Range         = range:: ec
-              |         ec ^"-" ec
+Range         = ec
+              | ec ^"-" ec
 
 e             =                (Quoted|Word) ^":" e
-              > nonTerminal::          Word
-              | literal::       Quoted
+              >                NonTerminalReference
+              |                Literal
               |                  ^"()"
-              |                  ^"{" Sequence "}"       /ws
+              |                  ^"{" PreSequence "}"    /ws
               |                  ^"["  Range* "]"
               |                e ^"++"                   /ws -> ~[/]
               |                e ^"+"                    /ws -> ~[+]
@@ -35,22 +51,24 @@ e             =                (Quoted|Word) ^":" e
               |                e ^"*"                    /ws -> ~[*]
               |                e ^"**/" e                /ws        
               |                e ^"*/"  e                /ws        
-              |                  ^"!"   e                /ws
+              |                     e ^"!"
               |                e ^"?"                    /ws
               |                  ^"^"   Quoted
-              |     "(" Word     ^")"                    /ws
               >                  ^"(" RHS  ")"           /ws
               |                  ^"~" e
-              >  "^^"::           "^"   e
 
-Word       = [a-zA-Z0-9_]++
-Quoted     = "\"" ((~[\"\\] | escaped)+) "\""
-           | ""::   "\"\""
+NonTerminalReference = Word
+Literal              = Quoted
+Word                 = [a-zA-Z0-9_]++
+Quoted               = "\"" ((~[\"\\] | escaped)+) "\""
+                     | EmptyString
+                       EmptyString = "\"\""
+
 escaped    = "\n":: "\\n"
            | "\r":: "\\r"
            |        "\\" ~[nr]
 
 w             = " " | "\n" | "\r"
 ws            =  "()":: w**
-              |  "()":: w** "//" ~[\n]* "\n" ws
+              |  "()":: w** "//" (~[\n])* "\n" ws
 wp            =  w++