Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: f52f360c59
Fetching contributors…

Cannot retrieve contributors at this time

47 lines (39 sloc) 1.204 kb
use DEBUG;
grammar JSONGrammar {
rule TOP {
[
| <?before '{'> :: <object>
| <?before '['> :: <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> { <?before '{'> :: <object> }
token value:sym<array> { <?before '['> :: <array> }
token value:sym<string> { <?before '"'> :: <string> }
token string {
'"' [ <str> || \\ <str_escape> ]* '"'
}
token str { <-[\t\n\\\"]>+ }
token xdigit {
<[0..9 a..f A..F]>
}
token str_escape {
<["\\/bfnrt]> || u <xdigit> <xdigit> <xdigit> <xdigit>
}
}
JSONGrammar.parse(eval 'local $/; <STDIN>')
# vim: ft=perl6
Jump to Line
Something went wrong with that request. Please try again.