X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FParser%2FSQLite.pm;h=593b4bacb38fa3f284b445b08211233dcd7b70ad;hb=88ad825597d4eee0bf3c93aa81738f82cc583fae;hp=aaa662561774dcdd2658135975ce5c76b8ffc206;hpb=df399712c8e458cbd2bf0389cb17666ce499dedd;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Parser/SQLite.pm b/lib/SQL/Translator/Parser/SQLite.pm index aaa6625..593b4ba 100644 --- a/lib/SQL/Translator/Parser/SQLite.pm +++ b/lib/SQL/Translator/Parser/SQLite.pm @@ -131,8 +131,9 @@ like-op::= =cut use strict; -use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ]; -$VERSION = '1.59'; +use warnings; +our ( $DEBUG, $GRAMMAR, @EXPORT_OK ); +our $VERSION = '1.59'; $DEBUG = 0 unless defined $DEBUG; use Data::Dumper; @@ -151,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 ? '...' : () + ); + } + } # @@ -174,7 +185,7 @@ statement : begin_transaction | drop | comment | create - | + | /^\Z/ | { _err ($thisline, $text) } begin_transaction : /begin/i TRANSACTION(?) SEMICOLON @@ -427,8 +438,8 @@ table_constraint : PRIMARY_KEY parens_field_list conflict_clause(?) } } -ref_def : /(\w+)\s*\((\w+)\)/ - { $return = { reference_table => $1, reference_fields => $2 } } +ref_def : table_name parens_field_list + { $return = { reference_table => $item[1]{name}, reference_fields => $item[2] } } table_name : qualified_name