update metagrammar
[sbp.git] / tests / meta.g
1 s             = ws Grammar ws
2
3 Grammar::     = Declaration +/ ws
4
5 Declaration   = NonTerminal
6               | ^"#import" FileName            /ws
7               | ^"#import" FileName "as" Word  /ws
8
9 FileName::    = (~[\r\n ] | escaped)+ -> [\r\n ]
10
11 NonTerminal   = NonTerminal:: Word            ws  "=" ws RHS
12               | DropNT::      Word  "!"       ws  "=" ws RHS
13               | Colons::      Word  "::"      ws  "=" ws RHS
14               |               Word  "*"       ws ^"=" ws RHS
15               |               Word  "*/" Word ws ^"=" ws RHS
16        
17 RHS::         = ("|":: Sequence +/ (ws "|" ws)) +/ (ws ">" ws)
18
19 Elements::    = e*/ws
20
21 PreSequence   = Elements
22               | (Quoted|Word)   ^"::" PreSequence /ws
23               > PreSequence     ^"/"      e       /ws
24               | PreSequence     ^"->"     e       /ws
25
26 Sequence      = PreSequence
27               | Sequence ^"&"  Elements /ws
28               | Sequence ^"&~" Elements /ws
29
30 e             =                                   e ^"!"
31               >                (Quoted|Word) ^":" e
32               >                NonTerminalReference:: 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               |                  ^"^"   Quoted
47               |                   "(" Word  ^")"
48               >                  ^"(" RHS  ")"           /ws
49               |                  ^"~" e
50               |                  ^"\\{"
51               |                  ^"\\}"
52
53 Word::        = [.a-zA-Z0-9_]++
54 Quoted::      = "\"" (~[\"\\] | escaped)+ "\""
55               | "\"\""
56
57 Range::       = ec
58               | ec "-" ec
59
60 ec            = ~[\-\]\\]
61               | escaped
62 escaped       = "\n"::  "\\n"
63               | "\r"::  "\\r"
64               |         "\\" ~[nr]
65
66 ws!           = [ \r\n]** ("//" ~[\n]* "\n" ws)?
67