From: Arthur Axel 'fREW' Schmidt Date: Thu, 14 Jul 2011 15:40:27 +0000 (-0500) Subject: better error messages for the SQLite parser X-Git-Tag: v0.11011~63 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FSQL-Translator.git;a=commitdiff_plain;h=95044c79c230e816a4c1c3cd5f9b2b4114d3ef0f better error messages for the SQLite parser --- diff --git a/lib/SQL/Translator/Parser/SQLite.pm b/lib/SQL/Translator/Parser/SQLite.pm index fc39db7..169b516 100644 --- a/lib/SQL/Translator/Parser/SQLite.pm +++ b/lib/SQL/Translator/Parser/SQLite.pm @@ -152,6 +152,16 @@ $GRAMMAR = q! { my ( %tables, $table_order, @table_comments, @views, @triggers ); + + 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 ? '...' : () + ); + } + } # @@ -175,7 +185,7 @@ statement : begin_transaction | drop | comment | create - | + | /^\Z/ | { _err ($thisline, $text) } begin_transaction : /begin/i TRANSACTION(?) SEMICOLON