checkpoint
[sbp.git] / tests / meta.g
1 s         ::=  ws grammar ws                  => "gram"
2 ws       !::=  w**
3 grammar   ::=  r +/ ws                        => "grammar"
4 r         ::=  word  ^"::=" alternatives /ws
5             |  word ^"!::=" alternatives /ws
6
7 alternatives  ::=  (conjuncts +/ (ws "|" ws)) +/ (ws ">" ws)
8
9 conjuncts   ::=  sequence
10               |  sequence ^"&"  e*/ws   /ws
11               |  sequence ^"&~" e*/ws   /ws
12
13 sequence    ::= e*/ws
14                 (ws "/" e)?
15                 (ws "=>" ws (word|quoted))?              => "seq"
16
17 ec       ::= [~\-\]\\\~]
18            | escaped
19
20 range    ::= ec          => "range"
21            | ec ^"-" ec
22
23 e        ::=  word                          => "nonTerminal"
24            |  quoted                        => "literal"
25            |    ^"()"
26            |    ^"{" sequence "}"       /ws
27            |    ^"["  (range*) "]"
28            |    ^"[~" (range*) "]"
29            |    ^"^" quoted             /ws
30            |    ^"!" e                  /ws
31
32            |  (e ws ^"**" > e ws ^"*")
33            |  e ^"*/" e                 /ws
34            |  (e ws ^"++" > e ws ^"+")
35            |  e ^"+/" e                 /ws
36            |  e ^"?"                    /ws
37
38            |     "(" word         ^")"  /ws
39            >    ^"(" alternatives  ")"  /ws
40
41 w       !::= " "
42            | "//" ([~\n]*) "\n"
43            | "\n"
44            | "\r"
45 word     ::= [a-zA-Z0-9_]++
46 quoted   ::= "\"" (([~\"\\] | escaped)+) "\""
47            | "\"\"" => ""
48 escaped  ::= "\\n" => "\n"
49            | "\\r" => "\r"
50            | "\\" [~nr]
51
52