checkpoint
[sbp.git] / tests / meta.g
index 29663f7..cc33104 100644 (file)
@@ -1,58 +1,57 @@
-s         ::=  w* Grammar w*                  => "gram"
-ws       !::= w*
-grammar   ::=  R+/ws => "grammar"
-Grammar   ::=  R+ => "grammar"
-R         ::=  word  ^"::=" Alternatives
-            |  word ^"!::=" Alternatives
-
-ec        ::=  [~\]\\\-\~] | escaped
-
-Alternatives  ::=  EquiAlt   +/ ">"
-EquiAlt       ::=  Conjuncts +/ "|"                 => "alternatives"
-
-Sequence    ::= E+ ^"/" E
-              > E+
-
-Conjuncts   ::=  Rewrite
-              |  Rewrite ^"&"  Sequence
-              |  Rewrite ^"&~" Sequence
-
-Rewrite  ::=  Sequence                             => "rewrite"
-           |  Sequence ^"=>" word
-           |  Sequence ^"=>" quoted
-           |  Sequence  "=>" "()"                  => "wrap"
-
-range    ::= ec => "range0" | ec ^"-" ec      => "range0"
-E        ::= word                             => "nonTerminalY"
-           |    [(][)] => "epsilon"
-           |    ^"{" Alternatives "}"
-           |     "[" [\~]?  range* "]"        => "range"
-           |  E ^"*/" E
-           |  E ^"+/" E
-           |  E ^"?"
-           |  E ^"~/~"
-
-           |  E ^"-"  E
-
-           |    ^"!" E
-           |     "^" quoted => "care"
-           |    ^"`" E
-           |  E ^"#"
-           |  quoted                        => "literal"
-
-           |  (E ^"**" > E ^"*")
-           |  (E ^"++" > E ^"+")
-
-           |     "(" word ^")"
-           >    ^"(" Alternatives ")"
-
-w       !::= " "
-           | "//" [~\n]* "\n"
-           | "\n"
-           | "\r"
-an       ::= [a-zA-Z0-9_]
-word     ::= an++                           => "sify"
-quoted   ::= "\"" ([~\"\\] | escaped)* "\"" => "sify"
-escaped  ::= "\\n" => "\n"
-           | "\\r" => "\r"
-           | "\\" [~nr]
+s             =  ws gram:Grammar ws
+Grammar       =  grammar:: NonTerminal +/ ws
+NonTerminal   =            word  !wp ^"=" !wp RHS
+        
+RHS           =  (Sequence +/ (!ws "|" !ws)) +/ (!ws ">" !ws)
+
+Elements      =  e*/ws
+
+PreSequence   = ps::  Elements
+              |       PreSequence !wp ^"/"  !ws e
+              |       PreSequence     ^"->"     e /ws
+              |       (Quoted|word)   ^"::" PreSequence /ws
+
+Sequence      = psx:: PreSequence
+              |       Sequence !ws ^"&"  !ws Elements
+              |       Sequence !ws ^"&~" !ws Elements
+
+ec            = ~[\-\]\\]
+              | escaped
+
+Range         = range:: ec
+              |         ec ^"-" ec
+
+e             =                (Quoted|word) ^":" e
+              > nonTerminal::          word
+              | literal::       Quoted
+              |                  ^"()"
+              |                  ^"{" Sequence "}"       /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++