checkpoint
[sbp.git] / tests / meta.g
index 0ba0548..11cb9f8 100644 (file)
@@ -1,53 +1,74 @@
-s         ::=  ws grammar ws                  => "gram"
-ws       !::=  w**
-grammar   ::=  r +/ ws                        => "grammar"
-r         ::=  word  ^"::=" alternatives /ws
-            |  word ^"!::=" alternatives /ws
-
-alternatives  ::=  (conjuncts +/ (ws "|" ws)) +/ (ws ">" ws)
-
-conjuncts   ::=  sequence
-              |  sequence ^"&"  e*/ws   /ws
-              |  sequence ^"&~" e*/ws   /ws
-
-ps          ::= e*/ws                              => "ps"
-              | (e+/ws ws)? "^" quoted (ws e+/ws)? => "ps2"
-psx         ::= ps
-              > ps ^"/" e /ws
-sequence    ::= psx
-              | psx ^"=>" (word|quoted) /ws
-
-ec       ::= [~\-\]\\\~]
-           | escaped
-
-range    ::= ec          => "range"
-           | ec ^"-" ec
-
-e        ::=  word                          => "nonTerminal"
-           |  quoted                        => "literal"
-           |    ^"()"
-           |    ^"{" sequence "}"       /ws
-           |    ^"["  range* "]"
-           |    ^"[~" range* "]"
-
-           |  (e ws ^"**" > e ws ^"*")
-           |  e ^"*/" e                 /ws
-           |  (e ws ^"++" > e ws ^"+")
-           |  e ^"+/" e                 /ws
-           |  e ^"?"                    /ws
-
-           |     "(" word         ^")"  /ws
-           >    ^"(" alternatives  ")"  /ws
-
-w       !::= " "
-           | "//" ([~\n]*) "\n"
-           | "\n"
-           | "\r"
-word     ::= [a-zA-Z0-9_]++
-quoted   ::= "\"" (([~\"\\] | escaped)+) "\""
-           | "\"\"" => ""
-escaped  ::= "\\n" => "\n"
-           | "\\r" => "\r"
-           | "\\" [~nr]
+// 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   =  Elements
+              |  (Quoted|Word)   ^"::" PreSequence /ws
+              >  PreSequence     ^"/"      e       /ws
+              |  PreSequence     ^"->"     e       /ws
+
+Sequence      = psx:: PreSequence
+              |       Sequence ^"&"  Elements /ws
+              |       Sequence ^"&~" Elements /ws
+
+ec            = ~[\-\]\\]
+              | escaped
+
+Range         = ec
+              | ec ^"-" ec
+
+e             =                (Quoted|Word) ^":" e
+              >                NonTerminalReference
+              |                Literal
+              |                  ^"()"
+              |                  ^"{" PreSequence "}"    /ws
+              |                  ^"["  Range* "]"
+              |                e ^"++"                   /ws -> ~[/]
+              |                e ^"+"                    /ws -> ~[+]
+              |                e ^"++/" e                /ws        
+              |                e ^"+/"  e                /ws        
+              |                e ^"**"                   /ws -> ~[/]
+              |                e ^"*"                    /ws -> ~[*]
+              |                e ^"**/" e                /ws        
+              |                e ^"*/"  e                /ws        
+              |                     e ^"!"
+              |                e ^"?"                    /ws
+              |                  ^"^"   Quoted
+              >                  ^"(" RHS  ")"           /ws
+              |                  ^"~" e
+
+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
+wp            =  w++