examples: annotate examples
[nit.git] / contrib / nitcc / examples / json.sablecc
1 Grammar json;
2
3 Lexer
4
5 number = int frac? exp?;
6 int = '-'? d+;
7 d = '0'..'9';
8 frac = '.' d+;
9 exp = e d+;
10 e = ('e'|'E') ('+'|'-')?;
11
12 hexdig = '0'..'9' | 'a'..'z' | 'A'..'Z';
13 string = '"' (Any - '\\' - '"' | '\\' (
14                 '\\' |
15                 '"' |
16                 '/' |
17                 'b' |
18                 'f' |
19                 'n' |
20                 'r' |
21                 't' |
22                 'u' hexdig hexdig hexdig hexdig
23         ))* '"';
24
25 blank = (' '|'\n'|'\t')+;
26
27 Parser
28 Ignored blank;
29
30 value =
31         {object:} '{' members? '}' |
32         {array:} '[' elements? ']' |
33         {number:} number |
34         {string:} string |
35         {true:} 'true' |
36         {false:} 'false' |
37         {null:} 'null' ;
38
39 members = {tail:} members ',' pair | {head:} pair ;
40 pair = string ':' value ;
41 elements = {tail:} elements ',' value | {head:} value ;