General: Expand JSLexArrayParser to recognize [, ] and # in strings, and add debugging
[videosite.git] / videosite / JSLexArrayParser.pm
index 73a8d7e..9320d03 100644 (file)
@@ -26,7 +26,7 @@ my @tokens = (
     QUADHEX => 'u[0-9a-fA-F]{4}',
     INTEGER => '[0-9]+',
     QUOTEDNORMAL => '[nr]',
-    SIMPLECHAR => '[-\w\._\?\+=\&\!%<>;]+',
+    SIMPLECHAR => '[-\w\._\?\+=\&\!%<>;\#]+',
     BACKSLASH => '\\\\',
     SLASH => '/',
     COMMA => ',',
@@ -38,10 +38,12 @@ my @tokens = (
 
 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);
 }
@@ -58,12 +60,13 @@ sub parse {
             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 => 0x0);
+        yydebug => (exists($self->{'_PARAMS'}->{'debug'})?$self->{'_PARAMS'}->{'debug'}:0x0));
     return ref($result)?$result->[0]:$result;
 }