-
Notifications
You must be signed in to change notification settings - Fork 15
/
JsonTinyG.pl
48 lines (41 loc) · 1.15 KB
/
JsonTinyG.pl
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
grammar JSONGrammar {
rule TOP { [<object> |<array> ] { say "parsed {$/.pos} chars" } }
rule object {'{' <pairlist> '}' }
rule pairlist { [ <pair> [ \, <pair> ]* ]? }
rule pair { <string> ':' <value> }
rule array {'[' [ <value> [ \, <value> ]* ]? ']' }
proto token value {*}
token value:sym<number> {
'-'?
[ 0 | <[1..9]> <[0..9]>* ]
[ \. <[0..9]>+ ]?
[ <[eE]> [\+|\-]? <[0..9]>+ ]?
}
token value:sym<true> { <sym> }
token value:sym<false> { <sym> }
token value:sym<null> { <sym> }
token value:sym<object> { <object> }
token value:sym<array> { <array> }
token value:sym<string> { <string> }
token string {
\" [ <str> | \\ <str_escape> ]* \"
}
token str {
[
<!before \t>
<!before \n>
<!before \\>
<!before \">
.
]+
# <-["\\\t\n]>+
}
token xdigit {
<[0..9 a..f A..F]>
}
token str_escape {
<["\\/bfnrt]> | u <xdigit> <xdigit> <xdigit> <xdigit>
}
}
JSONGrammar.parse($*IN.slurp)
# vim: ft=perl6