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