got rid of caret ugliness in metagrammar
[sbp.git] / tests / meta.g
1 s           ::=  !ws Grammar ws              => "gram"
2 Grammar     ::=  NonTerminal +/ ws           => "grammar"
3 NonTerminal ::=  word  ^"::=" RHS /ws
4
5 RHS         ::=  (Conjuncts +/ (!ws "|" !ws)) +/ (!ws ">" !ws)
6
7 Conjuncts   ::=  Sequence
8               |  Sequence ^"&"  Elements  /ws
9               |  Sequence ^"&~" Elements  /ws
10 Elements    ::=  e*/ws
11
12 ps          ::= Elements                           => "ps"
13 psy         ::= ps
14               | ps !wp ^"/" !ws e
15 psx         ::= psy                   => "psy"
16               | psy ^"->" e /ws
17 Sequence    ::= Quoted => "qprod"
18               > psx => "psx"
19               | psx  "=>" ^"[]"              /ws
20               | psx ^"=>" ("()"|word|Quoted) /ws
21
22 ec          ::= ~[\-\]\\]
23               | escaped
24
25 Range       ::= ec          => "range"
26               | ec ^"-" ec
27
28 e           ::=  word                          => "nonTerminal"
29               |  Quoted                        => "literal"
30               |    ^"()"
31               |    ^"{" Sequence "}"       /ws
32               |    ^"["  Range* "]"
33
34               |  e ^"++"                   /ws -> ~[/]
35               |  e ^"+"                    /ws -> ~[+]
36               |  e ^"++/" e                /ws        
37               |  e ^"+/"  e                /ws        
38               |  e ^"**"                   /ws -> ~[/]
39               |  e ^"*"                    /ws -> ~[*]
40               |  e ^"**/" e                /ws        
41               |  e ^"*/"  e                /ws        
42               |    ^"!"   e                /ws
43               |  e ^"?"                    /ws
44               |   "^" Quoted               /ws => caret
45
46               |     "(" word         ^")"  /ws
47               >    ^"(" RHS  ")"           /ws
48               |    ^"~" e
49
50 word     ::= [a-zA-Z0-9_]++
51 Quoted   ::= "\"" ((~[\"\\] | escaped)+) "\""
52            | "\"\"" => ""
53 escaped  ::= "\\n" => "\n"
54            | "\\r" => "\r"
55            | "\\" ~[nr]
56
57
58 w           ::= " " | "\n" | "\r"
59 ws          ::=  w** => ()
60               |  w** "//" ~[\n]* "\n" ws => ()
61 wp          ::=  w++