forked from pegex-parser/json-pgx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson.pgx
56 lines (43 loc) · 984 Bytes
/
json.pgx
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
# A simple grammar for the simple JSON data language.
# See https://github.com/ingydotnet/pegex-json-pm for a Parser implementation
# that uses this grammar.
%grammar json
%version 0.0.1
json: map | seq
node: map | seq | scalar
map:
/ ~ <LCURLY> ~ /
<pair>* % / ~ <COMMA> ~ /
/ ~ <RCURLY> ~ /
pair:
string
/ ~ <COLON> ~ /
node
seq:
/ ~ <LSQUARE> ~ /
node* % / ~ <COMMA> ~ /
/ ~ <RSQUARE> ~ /
scalar:
string |
number |
boolean |
null
string: / # XXX Need to code this to spec.
<DOUBLE> # This works for simple cases,
((: # but doesn't handle all escaping yet.
<BACK><BACK> |
<BACK><DOUBLE> |
[^ <DOUBLE> <BREAK> ]
)*)
<DOUBLE>
/
number: /(
<DASH>?
(: 0 | [1-9] <DIGIT>* )
(: <DOT> <DIGIT>* )?
(: [eE] [<DASH><PLUS>]? <DIGIT>+ )?
)/
boolean: true | false
true: /true/
false: /false/
null: /null/