checkpoint
[sbp.git] / tests / meta.g
index 72e1665..17f0399 100644 (file)
@@ -1,21 +1,30 @@
-
 // use 'a'-'z' or 'a-z' instead of [a-z]?
 // EOF token?
 // #include (with renaming?)
-// ANTLR uses ! and ^ suffixes
 
-s             =  !ws (grammar::Grammar) !ws
-Grammar       =  NonTerminal +/ ws
-NonTerminal   =  Word ^"=" RHS /ws
-        
-RHS           =  (Sequence +/ (!ws "|" !ws)) +/ (!ws ">" !ws)
+s             =  ws! Grammar ws!
+
+Grammar       =  Declaration +/ ws
+
+Declaration   =  NonTerminal
+              |  ^"#import" ws! FileName (ws! "as" ws! Word)?
+
+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
@@ -24,15 +33,14 @@ Sequence      = psx:: PreSequence
 ec            = ~[\-\]\\]
               | escaped
 
-Range         = range:: ec
-              |         ec ^"-" ec
+Range         = ec
+              | ec "-" ec
 
 e             =                (Quoted|Word) ^":" e
-              > 
-              nonTerminal::          Word
-              | literal::       Quoted
+              >                NonTerminalReference
+              |                Literal
               |                  ^"()"
-              |                  ^"{" PreSequence "}"       /ws
+              |                  ^"{" PreSequence "}"    /ws
               |                  ^"["  Range* "]"
               |                e ^"++"                   /ws -> ~[/]
               |                e ^"+"                    /ws -> ~[+]
@@ -42,22 +50,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
+ws            =  w**
+              |  w** "//" (~[\n])*! "\n" ws!
 wp            =  w++