checkpoint
[sbp.git] / tests / meta.g
index 4b4df1f..845af52 100644 (file)
@@ -1,54 +1,63 @@
-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"
-psx         ::= ps
-              > ps ws ^"/" e
-sequence    ::= psx
-              | psx ^"=>" (word|quoted) /ws
-
-ec       ::= [~\-\]\\\~]
-           | escaped
-
-range    ::= ec          => "range"
-           | ec ^"-" ec
-
-e        ::=  word                          => "nonTerminal"
-           |  quoted                        => "literal"
-           |    ^"()"
-           |    ^"{" sequence "}"       /ws
-           |    ^"["  (range*) "]"
-           |    ^"[~" (range*) "]"
-           |    ^"^" quoted             /ws
-           |    ^"!" e                  /ws
-
-           |  (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]
-
-
+Grammar       =  NonTerminal +/ ws
+s             =  !ws (grammar::Grammar) !ws
+NonTerminal   =  Word ^"=" RHS /ws
+
+// use 'a'-'z' or 'a-z' instead of [a-z]?
+// EOF token?
+// #include (with renaming?)
+// ANTLR uses ! and ^ suffixes
+
+blah = "Grammar"
+        
+RHS           =  (Sequence +/ (!ws "|" !ws)) +/ (!ws ">" !ws)
+
+Elements      =  e*/ws
+
+PreSequence   = ps::  Elements
+              |       (Quoted|Word)   ^"::" PreSequence /ws
+              >       PreSequence     ^"/"      e       /ws
+              |       PreSequence     ^"->"     e       /ws
+
+Sequence      = psx:: PreSequence
+              |       Sequence ^"&"  Elements /ws
+              |       Sequence ^"&~" Elements /ws
+
+ec            = ~[\-\]\\]
+              | escaped
+
+Range         = range:: ec
+              |         ec ^"-" ec
+
+e             =                (Quoted|Word) ^":" e
+              > nonTerminal::          Word
+              | literal::       Quoted
+              |                  ^"()"
+              |                  ^"{" PreSequence "}"    /ws
+              |                  ^"["  Range* "]"
+              |                e ^"++"                   /ws -> ~[/]
+              |                e ^"+"                    /ws -> ~[+]
+              |                e ^"++/" e                /ws        
+              |                e ^"+/"  e                /ws        
+              |                e ^"**"                   /ws -> ~[/]
+              |                e ^"*"                    /ws -> ~[*]
+              |                e ^"**/" e                /ws        
+              |                e ^"*/"  e                /ws        
+              |                  ^"!"   e                /ws
+              |                e ^"?"                    /ws
+              |                  ^"^"   Quoted
+              |     "(" Word     ^")"                    /ws
+              >                  ^"(" RHS  ")"           /ws
+              |                  ^"~" e
+              >  "^^"::           "^" e
+
+Word       = [a-zA-Z0-9_]++
+Quoted     = "\"" ((~[\"\\] | escaped)+) "\""
+           | ""::   "\"\""
+escaped    = "\n":: "\\n"
+           | "\r":: "\\r"
+           |        "\\" ~[nr]
+
+w             = " " | "\n" | "\r"
+ws            =  "()":: w**
+              |  "()":: w** "//" (~[\n])* "\n" ws
+wp            =  w++