Use precompiled Parse::RecDescent parsers for moar speed
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser / MySQL.pm
index 1a8c44b..854b927 100644 (file)
@@ -129,31 +129,25 @@ More information about the MySQL comment-syntax: L<http://dev.mysql.com/doc/refm
 
 use strict;
 use warnings;
-our ( $DEBUG, $GRAMMAR, @EXPORT_OK );
+
 our $VERSION = '1.59';
+
+our $DEBUG;
 $DEBUG   = 0 unless defined $DEBUG;
 
 use Data::Dumper;
-use Parse::RecDescent;
-use Exporter;
 use Storable qw(dclone);
 use DBI qw(:sql_types);
-use base qw(Exporter);
+use SQL::Translator::Utils qw/parse_mysql_version ddl_parser_instance/;
 
-use SQL::Translator::Utils qw/parse_mysql_version/;
+use base qw(Exporter);
+our @EXPORT_OK = qw(parse);
 
 our %type_mapping = ();
 
-@EXPORT_OK = qw(parse);
-
-# 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 constant DEFAULT_PARSER_VERSION => 30000;
 
-$GRAMMAR = << 'END_OF_GRAMMAR';
+our $GRAMMAR = << 'END_OF_GRAMMAR';
 
 {
     my ( $database_name, %tables, $table_order, @table_comments, %views,
@@ -797,14 +791,16 @@ 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('MySQL');
 
     # Preprocess for MySQL-specific and not-before-version comments
     # from mysqldump