X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FParser%2FAccess.pm;h=bd51ec958a0f9639746d442e4c942f9d33c20f32;hb=90097ddd3b029720062c30118f05fdf3cc241cd3;hp=d1ff7d7729a6ea39371448f8adcc05fdd5872297;hpb=df399712c8e458cbd2bf0389cb17666ce499dedd;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Parser/Access.pm b/lib/SQL/Translator/Parser/Access.pm index d1ff7d7..bd51ec9 100644 --- a/lib/SQL/Translator/Parser/Access.pm +++ b/lib/SQL/Translator/Parser/Access.pm @@ -20,23 +20,20 @@ something similar to the output of mdbtools (http://mdbtools.sourceforge.net/). =cut use strict; -use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ]; -$VERSION = '1.59'; -$DEBUG = 0 unless defined $DEBUG; +use warnings; -use Data::Dumper; -use Parse::RecDescent; -use Exporter; -use base qw(Exporter); +our $VERSION = '1.59'; -@EXPORT_OK = qw(parse); +our $DEBUG; +$DEBUG = 0 unless defined $DEBUG; -# Enable warnings within the Parse::RecDescent module. -$::RD_ERRORS = 1; # Make sure the parser dies when it encounters an error -$::RD_WARN = 1; # Enable warnings. This will warn on unused rules &c. -$::RD_HINT = 1; # Give out hints to help fix problems. +use Data::Dumper; +use SQL::Translator::Utils qw/ddl_parser_instance/; -$GRAMMAR = q! +use base qw(Exporter); +our @EXPORT_OK = qw(parse); + +our $GRAMMAR = <<'END_OF_GRAMMAR'; { my ( %tables, $table_order, @table_comments ); @@ -262,7 +259,7 @@ not_null : /not/i /null/i { $return = 0 } unsigned : /unsigned/i { $return = 0 } -default_val : /default/i /'(?:.*?\\')*.*?'|(?:')?[\w\d:.-]*(?:')?/ +default_val : /default/i /'(?:.*?\')*.*?'|(?:')?[\w\d:.-]*(?:')?/ { $item[2] =~ s/^\s*'|'\s*$//g; $return = $item[2]; @@ -378,19 +375,20 @@ VALUE : /[-+]?\.?\d+(?:[eE]\d+)?/ | /NULL/ { 'NULL' } -!; +END_OF_GRAMMAR sub parse { my ( $translator, $data ) = @_; - my $parser = Parse::RecDescent->new($GRAMMAR); + + # Enable warnings within the Parse::RecDescent module. + local $::RD_ERRORS = 1 unless defined $::RD_ERRORS; # Make sure the parser dies when it encounters an error + local $::RD_WARN = 1 unless defined $::RD_WARN; # Enable warnings. This will warn on unused rules &c. + local $::RD_HINT = 1 unless defined $::RD_HINT; # Give out hints to help fix problems. local $::RD_TRACE = $translator->trace ? 1 : undef; local $DEBUG = $translator->debug; - unless (defined $parser) { - return $translator->error("Error instantiating Parse::RecDescent ". - "instance: Bad grammer"); - } + my $parser = ddl_parser_instance('Access'); my $result = $parser->startrule($data); return $translator->error( "Parse failed." ) unless defined $result;