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