-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSON.g4
More file actions
54 lines (42 loc) · 1.06 KB
/
JSON.g4
File metadata and controls
54 lines (42 loc) · 1.06 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// lexer rules start with upper case - observe this by adding reg expressions
//parser rules start with lower case
//**********Grammar - PARSER RULES*******************
grammar JSON;
json : object
;
object : '{' (property (',' property)*)? '}' //parser rule - one or more instances of property | '{''}' <- optional
// Why are you already bothered about whitespace here? | '{' WS '}'
;
property
: key ':' value
;
key : StringLiteral;
value
: object
| array
| stringValue
| booleanValue
| intValue
| nullValue
;
nullValue
: NullType
;
booleanValue
: BooleanType
;
intValue
: IntType
;
stringValue
: StringLiteral
;
array
: '[' (object (',' object)*)? ']' // parser rule - one or more instances of object :)
;
//******LEXER RULES***********
StringLiteral : '"' (~["\\])* '"' ; // Lexer Rule
BooleanType : 'true' | 'false' ;
IntType : '0' | [1-9][0-9]*; // [0-9]+
NullType : 'null';
WS : [ \t\n\r]+ -> skip ;