Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 46 lines (38 sloc) 1.173 kB
c11ed71 @sorear Add a few things being used in testing
authored
1 grammar JSONGrammar {
4926d3c @sorear Implement caching of lexers
authored
2 rule TOP {
3 [
4 | <?before '{'> :: <object>
5 | <?before '['> :: <array>
6 ]
7 { say "parsed {$/.pos} chars" }
8 }
09519c3 @sorear Add a very simple regex optimizer. ~2% win so far
authored
9 rule object { '{' <pairlist> '}' }
4926d3c @sorear Implement caching of lexers
authored
10 rule pairlist { [ <pair> [ "," <pair> ]* ]? }
c11ed71 @sorear Add a few things being used in testing
authored
11 rule pair { <string> ':' <value> }
09519c3 @sorear Add a very simple regex optimizer. ~2% win so far
authored
12 rule array { '[' [ <value> [ "," <value> ]* ]? ']' }
c11ed71 @sorear Add a few things being used in testing
authored
13
14 proto token value {*}
15 token value:sym<number> {
16 '-'?
09519c3 @sorear Add a very simple regex optimizer. ~2% win so far
authored
17 [ 0 | <[1..9]> <[0..9]>* ]
4926d3c @sorear Implement caching of lexers
authored
18 [ "." <[0..9]>+ ]?
19 [ <[eE]> ["+"|"-"]? <[0..9]>+ ]?
c11ed71 @sorear Add a few things being used in testing
authored
20 }
21 token value:sym<true> { <sym> }
22 token value:sym<false> { <sym> }
23 token value:sym<null> { <sym> }
09519c3 @sorear Add a very simple regex optimizer. ~2% win so far
authored
24 token value:sym<object> { <?before '{'> :: <object> }
25 token value:sym<array> { <?before '['> :: <array> }
4926d3c @sorear Implement caching of lexers
authored
26 token value:sym<string> { <?before '"'> :: <string> }
c11ed71 @sorear Add a few things being used in testing
authored
27
28 token string {
4926d3c @sorear Implement caching of lexers
authored
29 '"' [ <str> || \\ <str_escape> ]* '"'
c11ed71 @sorear Add a few things being used in testing
authored
30 }
31
4926d3c @sorear Implement caching of lexers
authored
32 token str { <-[\t\n\\\"]>+ }
c11ed71 @sorear Add a few things being used in testing
authored
33
34 token xdigit {
35 <[0..9 a..f A..F]>
36 }
37
38 token str_escape {
4926d3c @sorear Implement caching of lexers
authored
39 <["\\/bfnrt]> || u <xdigit> <xdigit> <xdigit> <xdigit>
c11ed71 @sorear Add a few things being used in testing
authored
40 }
41 }
42
43 JSONGrammar.parse($*IN.slurp)
44
45 # vim: ft=perl6
Something went wrong with that request. Please try again.