=cut
use strict;
+use warnings;
-use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ];
-$VERSION = '1.59';
+our $VERSION = '1.59';
+
+our $DEBUG;
$DEBUG = 0 unless defined $DEBUG;
use Data::Dumper;
-use Parse::RecDescent;
-use Exporter;
-use base qw(Exporter);
-
-@EXPORT_OK = qw(parse);
+use SQL::Translator::Utils qw/ddl_parser_instance/;
-$::RD_ERRORS = 1;
-$::RD_WARN = 1;
-$::RD_HINT = 1;
+use base qw(Exporter);
+our @EXPORT_OK = qw(parse);
-$GRAMMAR = q{
+our $GRAMMAR = <<'END_OF_GRAMMAR';
{
my ( %tables, @table_comments, $table_order, %procedures, $proc_order, %views, $view_order );
disable_constraints : if_exists(?) /alter/i /table/i ident /nocheck/i /constraint/i /all/i END_STATEMENT
-# this is for the normal case
+# this is for the normal case
create_constraint : /create/i constraint END_STATEMENT
{
@table_comments = ();
RQUOTE : ']'
-};
+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('SQLServer');
my $result = $parser->startrule($data);
return $translator->error( "Parse failed." ) unless defined $result;