-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSON.g4
More file actions
40 lines (30 loc) · 847 Bytes
/
Copy pathJSON.g4
File metadata and controls
40 lines (30 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
grammar JSON;
// Parser rules
json: object
| array
;
object: '{' pair (',' pair)* '}' # AnObject
| '{' '}' # EmptyObject
;
pair: STRING ':' value ;
array: '[' value (',' value)* ']' # ArrayOfValues
| '[' ']' # EmptyArray
;
value: STRING # String
| NUMBER # Atom
| object # ObjectValue
| array # ArrayValue
| 'true' # Atom
| 'false' # Atom
| 'null' # Atom
;
// Lexer rules
STRING: '"' (ESC | SAFECODEPOINT)* '"';
fragment ESC: '\\' (["\\/bfnrt] | UNICODE);
fragment UNICODE: 'u' HEX HEX HEX HEX;
fragment HEX: [0-9a-fA-F];
fragment SAFECODEPOINT: ~["\\\u0000-\u001F];
NUMBER: '-'? INT ('.' [0-9]+)? EXP?;
fragment INT: '0' | [1-9] [0-9]*;
fragment EXP: [Ee] [\-+]? [0-9]+;
WS: [ \t\n\r]+ -> skip;