checkpoint
[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               > nonTerminal::          Word
32               | literal::       Quoted
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                /ws
45               |                e ^"?"                    /ws
46               |                  ^"^"   Quoted
47               |     "(" Word     ^")"                    /ws
48               >                  ^"(" RHS  ")"           /ws
49               |                  ^"~" e
50               >  "^^"::           "^"   e
51
52 Word       = [a-zA-Z0-9_]++
53 Quoted     = "\"" ((~[\"\\] | escaped)+) "\""
54            | ""::   "\"\""
55 escaped    = "\n":: "\\n"
56            | "\r":: "\\r"
57            |        "\\" ~[nr]
58
59 w             = " " | "\n" | "\r"
60 ws            =  "()":: w**
61               |  "()":: w** "//" ~[\n]* "\n" ws
62 wp            =  w++