checkpoint
[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 NamedElements    ::=  (e | word ^":" e) */ ws
12
13 PreSequence ::= NamedElements => "ps"
14               | PreSequence !wp ^"/"  !ws e
15               | PreSequence     ^"->"     e /ws
16               | PreSequence     ^"=>" ("[]"|"()"|word|Quoted) /ws
17 Sequence    ::= PreSequence    => "psx"
18
19 ec          ::= ~[\-\]\\]
20               | escaped
21
22 Range       ::= ec          => "range"
23               | ec ^"-" ec
24
25 e           ::=  word                          => "nonTerminal"
26               |  Quoted                        => "literal"
27               |    ^"()"
28               |    ^"{" Sequence "}"       /ws
29               |    ^"["  Range* "]"
30
31               |  e ^"++"                   /ws -> ~[/]
32               |  e ^"+"                    /ws -> ~[+]
33               |  e ^"++/" e                /ws        
34               |  e ^"+/"  e                /ws        
35               |  e ^"**"                   /ws -> ~[/]
36               |  e ^"*"                    /ws -> ~[*]
37               |  e ^"**/" e                /ws        
38               |  e ^"*/"  e                /ws        
39               |    ^"!"   e                /ws
40               |  e ^"?"                    /ws
41               |    ^"^" Quoted             /ws
42
43               |     "(" word         ^")"  /ws
44               >    ^"(" RHS  ")"           /ws
45               |    ^"~" e
46
47 word     ::= [a-zA-Z0-9_]++
48 Quoted   ::= "\"" ((~[\"\\] | escaped)+) "\""
49            | "\"\"" => ""
50 escaped  ::= "\\n" => "\n"
51            | "\\r" => "\r"
52            | "\\" ~[nr]
53
54
55 w           ::= " " | "\n" | "\r"
56 ws          ::=  w** => ()
57               |  w** "//" ~[\n]* "\n" ws => ()
58 wp          ::=  w++