d8353a6af910c65d699e57c8c7c9f76e3e30bbe7
[sbp.git] / tests / meta.g
1
2 // use 'a'-'z' or 'a-z' instead of [a-z]?
3 // EOF token?
4 // #include (with renaming?)
5 // ANTLR uses ! and ^ suffixes
6
7 s             =  !ws (grammar::Grammar) !ws
8 Grammar       =  NonTerminal +/ ws
9 NonTerminal   =  Word ^"=" RHS /ws
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         = range:: ec
28               |         ec ^"-" ec
29
30 e             =//                (Quoted|Word) ^":" e
31 //              > 
32               nonTerminal::          Word
33               | literal::       Quoted
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                /ws
46               |                e ^"?"                    /ws
47               |                  ^"^"   Quoted
48               |     "(" Word     ^")"                    /ws
49               >                  ^"(" RHS  ")"           /ws
50               |                  ^"~" e
51               >  "^^"::           "^"   e
52
53 Word       = [a-zA-Z0-9_]++
54 Quoted     = "\"" ((~[\"\\] | escaped)+) "\""
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++