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 NonTerminalReference = Word
32
33 e             =                (Quoted|Word) ^":" e
34               >                NonTerminalReference
35               | literal::       Quoted
36               |                  ^"()"
37               |                  ^"{" PreSequence "}"    /ws
38               |                  ^"["  Range* "]"
39               |                e ^"++"                   /ws -> ~[/]
40               |                e ^"+"                    /ws -> ~[+]
41               |                e ^"++/" e                /ws        
42               |                e ^"+/"  e                /ws        
43               |                e ^"**"                   /ws -> ~[/]
44               |                e ^"*"                    /ws -> ~[*]
45               |                e ^"**/" e                /ws        
46               |                e ^"*/"  e                /ws        
47               |                  ^"!"   e                /ws
48               |                e ^"?"                    /ws
49               |                  ^"^"   Quoted
50               |     "(" Word     ^")"                    /ws
51               >                  ^"(" RHS  ")"           /ws
52               |                  ^"~" e
53               >  "^^"::           "^" e
54
55 Word       = [a-zA-Z0-9_]++
56 Quoted     = "\"" ((~[\"\\] | escaped)+) "\""
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++