checkpoint
[sbp.git] / tests / meta.g
1 s             =  !ws (grammar::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         = range:: ec
29               |         ec ^"-" ec
30
31 e             =                (Quoted|Word) ^":" e
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++