-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathjson.grammar.js
83 lines (69 loc) · 2.21 KB
/
json.grammar.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* How to run:
*
* Basic example:
*
* ./bin/syntax \
* --grammar examples/json.grammar.js \
* --mode slr1 \
* --parse '{"x": 10}'
*
* Parsing table, canonical collection or LR items, etc:
*
* ./bin/syntax \
* --grammar examples/json.grammar.js \
* --mode slr1 \
* --collection \
* --table \
* --parse '{"x": 10, "y": {"z": [1, 2, 3]}}'
*/
{
"_info": "Based on: https://github.com/zaach/jison/blob/master/examples/json.js",
"lex": {
"macros": {
"digit": "[0-9]",
"esc": "\\\\",
"int": "-?(?:[0-9]|[1-9][0-9]+)",
"exp": "(?:[eE][-+]?[0-9]+)",
"frac": "(?:\\.[0-9]+)"
},
"rules": [
["\\s+", "/* skip whitespace */"],
["{int}{frac}?{exp}?\\b", "return 'NUMBER';"],
["\"(?:{esc}[\"bfnrt/{esc}]|{esc}u[a-fA-F0-9]{4}|[^\"{esc}])*\"", "return 'STRING';"],
["\\{", "return '{'"],
["\\}", "return '}'"],
["\\[", "return '['"],
["\\]", "return ']'"],
[",", "return ','"],
[":", "return ':'"],
["true\\b", "return 'TRUE'"],
["false\\b", "return 'FALSE'"],
["null\\b", "return 'NULL'"]
]
},
"tokens": "STRING NUMBER { } [ ] , : TRUE FALSE NULL",
"start": "JSONText",
"bnf": {
"JSONText": [ "JSONValue" ],
"JSONString": [ "STRING" ],
"JSONNullLiteral": [ "NULL" ],
"JSONNumber": [ "NUMBER" ],
"JSONBooleanLiteral": [ "TRUE", "FALSE" ],
"JSONValue": [ "JSONNullLiteral",
"JSONBooleanLiteral",
"JSONString",
"JSONNumber",
"JSONObject",
"JSONArray" ],
"JSONObject": [ "{ }",
"{ JSONMemberList }" ],
"JSONMember": [ "JSONString : JSONValue" ],
"JSONMemberList": [ "JSONMember",
"JSONMemberList , JSONMember" ],
"JSONArray": [ "[ ]",
"[ JSONElementList ]" ],
"JSONElementList": [ "JSONValue",
"JSONElementList , JSONValue" ]
}
}