ackage Pegex::JSON;
BEGIN { $ENV{PERL_PEGEX_AUTO_COMPILE} = 'Pegex::JSON::Grammar' }
our $VERSION = '0.31';
use Pegex::Base;
use Pegex::Parser;
use Pegex::JSON::Grammar;
use Pegex::JSON::Data;
sub
load {
my ($self, $json) = @_;
Pegex::Parser->new(
grammar => Pegex::JSON::Grammar->new,
receiver => Pegex::JSON::Data->new,
# debug => 1,
)->parse($json);
}
1;
x::JSON::Grammar;
use Pegex::Base;
extends 'Pegex::Grammar';
use constant file => '../json-pgx/json.pgx';
sub make_tree { # Generated/Inlined by Pegex::Grammar (0.73)
{
'+grammar' => 'json',
'+include' => 'pegex-atoms',
'+toprule' => 'json',
'+version' => '0.0.1',
'_' => {
'.rgx' => qr/\G\s*/
},
'array' => {
'.all' => [
{
'-skip' => 1
qr/\G\s*\]\s*/
}
]
},
'false' => {
'.rgx' => qr/\Gfalse/
},
'json' => {
'.all' => [
{
'.ref' => '_'
},
{
'.ref' =
package Pegex::JSON::Data;
use Pegex::Base;
extends 'Pegex::Tree';
use boolean;
sub got_json { shift @{(pop)} }
sub got_object { +{map @$_, @{(pop)}} }
my %escapes = (
'"' => '"',
'/' => "
ing {
my $string = pop;
$string =~ s/\\(["\/\\bfnrt])/$escapes{$1}/ge;
# This handles JSON encoded Unicode surrogate pairs
$string =~ s/\\u([0-9a-f]{4})\\u([0-9a-f]{4})/pack "U*", hex(
NAME
Pegex::JSON - Pegex Loader for JSON
=for html
<a href="https://travis-ci.org/ingydotnet/pegex-json-pm"><img src="https://travis-ci.org/ingydotnet/pegex-json-pm.png" alt="pegex-json-pm"></a>
<a
et/pegex-json-pm?branch=master"><img src="https://coveralls.io/repos/ingydotnet/pegex-json-pm/badge.png" alt="pegex-json-pm"></a>
=head1 SYNOPSIS
my $data = Pegex::JSON->new->load($json);
=head
1 DESCRIPTION
Pegex::JSON is a JSON parser written in Pegex.
=head1 SEE ALSO
=over
=item * L<Pegex>
=item * L<JSON>
=back
=head1 AUTHOR
Ingy döt Net <ingy@cpan.org>
=head1 COPYRIGHT
Copyrig