checkpoint
[sbp.git] / tests / meta.g
1 s             =  ws! Grammar ws!
2
3 Grammar       =  NonTerminal +/ ws
4
5 NonTerminal   =  Word "=" RHS /ws
6
7 // use 'a'-'z' or 'a-z' instead of [a-z]?
8 // EOF token?
9 // #include (with renaming?)
10 // ANTLR uses ! and ^ suffixes
11         
12 RHS           =  (Sequence +/ (ws! "|" ws!)) +/ (ws! ">" ws!)
13
14 Elements      =  e*/ws
15
16 PreSequence   = ps::  Elements
17               |       (Quoted|Word)   ^"::" PreSequence /ws
18               >       PreSequence     ^"/"      e       /ws
19               |       PreSequence     ^"->"     e       /ws
20
21 Sequence      = psx:: PreSequence
22               |       Sequence ^"&"  Elements /ws
23               |       Sequence ^"&~" Elements /ws
24
25 ec            = ~[\-\]\\]
26               | escaped
27
28 Range         = ec
29               | ec ^"-" ec
30
31 e             =                (Quoted|Word) ^":" e
32               >                NonTerminalReference
33               |                Literal
34               |                  ^"()"
35               |                  ^"{" PreSequence "}"    /ws
36               |                  ^"["  Range* "]"
37               |                e ^"++"                   /ws -> ~[/]
38               |                e ^"+"                    /ws -> ~[+]
39               |                e ^"++/" e                /ws        
40               |                e ^"+/"  e                /ws        
41               |                e ^"**"                   /ws -> ~[/]
42               |                e ^"*"                    /ws -> ~[*]
43               |                e ^"**/" e                /ws        
44               |                e ^"*/"  e                /ws        
45               |                     e ^"!"
46               |                e ^"?"                    /ws
47               |                  ^"^"   Quoted
48               |                  Quoted ^"^"
49               >                  ^"(" RHS  ")"           /ws
50               |                  ^"~" e
51
52 NonTerminalReference = Word
53 Literal              = Quoted
54 Word                 = [a-zA-Z0-9_]++
55 Quoted               = "\"" ((~[\"\\] | escaped)+) "\""
56                      | ""::   "\"\""
57
58 escaped    = "\n":: "\\n"
59            | "\r":: "\\r"
60            |        "\\" ~[nr]
61
62 w             = " " | "\n" | "\r"
63 ws            =  "()":: w**
64               |  "()":: w** "//" (~[\n])* "\n" ws
65 wp            =  w++