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