# # A helper class for parsing textual JSON structures into perl # structures # # The parser is in JSONNospace.yp, to regenerate you'll need the Parse::YAPP # package. Use 'yapp -m videosite::JSONNospace -s JSONNospace.yp' to regenerate # package videosite::JSLexArrayParser; use videosite::JSArrayParser; @ISA = qw(videosite::JSArrayParser); use Parse::Lex; use videosite::JSONNospace; use Data::Dumper; use strict; my @tokens = ( COLON => ':', QUOTE => '\"', SINGLEQUOTE => '\\\'', TRUE => 'true', FALSE => 'false', NULL => 'null', QUADHEX => 'u[0-9a-fA-F]{4}', INTEGER => '[0-9]+', QUOTEDNORMAL => '[nr]', SIMPLECHAR => '[-\w\._\?\+=\&\!%<>;\#]+', BACKSLASH => '\\\\', SLASH => '/', COMMA => ',', CURLYOPEN => '{', CURLYCLOSE => '}', SQUAREOPEN => '\[', SQUARECLOSE => '\]', ); sub new { my $class = shift; my %params = @_; my $self = $class->SUPER::new(); $self->{'_PARSER'} = videosite::JSONNospace->new(); $self->{'_LEXER'} = Parse::Lex->new(@tokens); $self->{'_PARAMS'} = \%params; return bless($self, $class); } sub parse { my $self = shift; my $s = shift; my $result; my $l = $self->{'_LEXER'}; $l->from($s); $result = $self->{'_PARSER'}->YYParse( yylex => sub { my $tok = $l->next(); return ('', undef) unless $tok; return ('', undef) if $l->eoi(); print STDERR $tok->text(), "\n" if (exists($self->{'_PARAMS'}->{'debug'}) and ($self->{'_PARAMS'}->{'debug'} > 0)); return ($tok->name(), $tok->text()); }, yyerror => sub { $_[0]->YYAbort(); }, yydebug => (exists($self->{'_PARAMS'}->{'debug'})?$self->{'_PARAMS'}->{'debug'}:0x0)); return ref($result)?$result->[0]:$result; } 1;