From: Peter Rabbitson Date: Fri, 25 Feb 2011 03:15:32 +0000 (+0100) Subject: Better diagnostics X-Git-Tag: v0.11008~15 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=28224573adab3cc22c91910dbf36c835943d0d8a;p=dbsrgits%2FSQL-Translator.git Better diagnostics --- diff --git a/lib/SQL/Translator/Parser/SQLServer.pm b/lib/SQL/Translator/Parser/SQLServer.pm index 38cf64b..c178302 100644 --- a/lib/SQL/Translator/Parser/SQLServer.pm +++ b/lib/SQL/Translator/Parser/SQLServer.pm @@ -55,6 +55,16 @@ $GRAMMAR = q{ { my ( %tables, @table_comments, $table_order, %procedures, $proc_order, %views, $view_order ); + + sub _err { + my $max_lines = 5; + my @up_to_N_lines = split (/\n/, $_[1], $max_lines + 1); + die sprintf ("Unable to parse line %d:\n%s\n", + $_[0], + join "\n", (map { "'$_'" } @up_to_N_lines[0..$max_lines - 1 ]), @up_to_N_lines > $max_lines ? '...' : () + ); + } + } startrule : statement(s) eofile @@ -81,7 +91,7 @@ statement : create_table | print | grant | exec - | + | /^\Z/ | { _err ($thisline, $text) } use : /use/i WORD GO { @table_comments = () } diff --git a/t/60roundtrip.t b/t/60roundtrip.t index 857226e..f2d491a 100644 --- a/t/60roundtrip.t +++ b/t/60roundtrip.t @@ -165,6 +165,12 @@ sub check_roundtrip { isa_ok ($mid_schema, 'SQL::Translator::Schema', "First $args->{name} parser pass produced a schema:") or do { diag (_gen_diag ( $parser_t->error, $base_out ) ); + my $i; + note join ("\n" . ( '=' x 76) . "\n", + 'Unparseable DDL:', + (join ("\n", map { ++$i . ":\t$_" } split /\n/, $base_out) ), + '' + ); return; };