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