bb7cd114d94bf05ab028246df247490f0b38e86d
[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  ::=  equiAlt   +/ (ws ">" ws)
8 equiAlt       ::=  conjuncts +/ (ws "|" ws)
9
10 conjuncts   ::=  sequence
11               |  sequence ^"&"  e*/ws   /ws
12               |  sequence ^"&~" e*/ws   /ws
13
14 sequence    ::= e*/ws
15                 (ws "/" e)?
16                 (ws "=>" ws (word|quoted))?              => "seq"
17
18 ec       ::= [~\-\]\\\~]
19            | escaped
20
21 range    ::= ec          => "range"
22            | ec ^"-" ec
23
24 e        ::= word                             => "nonTerminal"
25            |    [(][)]                        => "epsilon"
26            |    ^"{" alternatives "}"   /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            |  quoted                        => "literal"
39
40            |     "(" word ^")"          /ws
41            >    ^"(" alternatives ")"   /ws
42
43 w       !::= " "
44            | "//" ([~\n]*) "\n"
45            | "\n"
46            | "\r"
47 word     ::= [a-zA-Z0-9_]++
48 quoted   ::= "\"" (([~\"\\] | escaped)+) "\""
49            | "\"\"" => ""
50 escaped  ::= "\\n" => "\n"
51            | "\\r" => "\r"
52            | "\\" [~nr]
53
54