Skip Menu |

This queue is for tickets about the DBIx-MyParsePP CPAN distribution.

Report information
The Basics
Id: 62996
Status: open
Priority: 0/
Queue: DBIx-MyParsePP

People
Owner: MERKYS [...] cpan.org
Requestors: dbonnell2010 [...] me.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.50
Fixed in: (no value)



Subject: Bugs and enhancements
- Fixed bug with stmt_prepare_mode argument - Fixed bug with line number tracking inside comments - LEXER_SERVER_STATUS and SERVER_MORE_RESULTS_EXISTS exported by Lexer to facilitate multi-statement parsing - col() and getCol() methods added to Lexer and Query to facilitate better error reporting Patch file attached.
Subject: DBIx-MyParsePP-0.50-to-0.60.patch
--- DBIx-MyParsePP-0.50/lib/DBIx/MyParsePP/Query.pm 2007-08-18 02:15:01.000000000 +0100 +++ DBIx-MyParsePP-0.60/lib/DBIx/MyParsePP/Query.pm 2010-11-15 13:14:52.371161082 +0000 @@ -84,6 +84,16 @@ return $lexer->getLine(); } +sub col { + $_[0]->getCol(); +} + +sub getCol { + my $query = shift; + my $lexer = $query->getLexer(); + return $lexer->getCol(); +} + sub pos { $_[0]->getPos(); } @@ -204,7 +214,8 @@ just the token types. C<getLine()> returns the line number where the error occured. C<getPos()> returns the character position where the -error occured, counting from the beginning of the string, not the begining of the line. +error occured, counting from the beginning of the string. If instead you want the position of the error relative +to the beginning of the line, use C<getCol()> instead. C<getTokens()> can be used to reconstruct the query as it was up to the failure point. --- DBIx-MyParsePP-0.50/lib/DBIx/MyParsePP/Lexer.pm 2007-08-18 03:29:37.000000000 +0100 +++ DBIx-MyParsePP-0.60/lib/DBIx/MyParsePP/Lexer.pm 2010-11-15 15:09:53.687206166 +0000 @@ -17,7 +17,7 @@ require Exporter; @ISA = qw(Exporter); @EXPORT = qw(MODE_PIPES_AS_CONCAT MODE_ANSI_QUOTES MODE_IGNORE_SPACE MODE_NO_BACKSLASH_ESCAPES - CLIENT_MULTI_STATEMENTS MODE_HIGH_NOT_PRECEDENCE); + CLIENT_MULTI_STATEMENTS MODE_HIGH_NOT_PRECEDENCE LEXER_SERVER_STATUS SERVER_MORE_RESULTS_EXISTS ); use strict; @@ -54,6 +54,7 @@ use constant LEXER_SAFE_TO_CACHE_QUERY => 14; use constant LEXER_SERVER_STATUS => 15; use constant LEXER_CTYPE => 16; +use constant LEXER_YYLINE_START => 17; use constant OPTION_FOUND_COMMENT => 1 << 15; @@ -110,6 +111,7 @@ $lexer->[LEXER_STRING] = $lexer->[LEXER_STRING]."\0"; $lexer->[LEXER_YYLINENO] = 1; + $lexer->[LEXER_YYLINE_START] = 0; $lexer->[LEXER_TOK_START] = 0; $lexer->[LEXER_PTR] = 0; $lexer->[LEXER_NEXT_STATE] = 'MY_LEX_START'; @@ -148,6 +150,14 @@ return $_[0]->[LEXER_YYLINENO]; } +sub col { + return $_[0]->[LEXER_PTR] - $_[0]->[LEXER_YYLINE_START]; +} + +sub getCol { + return $_[0]->[LEXER_PTR] - $_[0]->[LEXER_YYLINE_START]; +} + sub pos { return $_[0]->[LEXER_PTR]; } @@ -210,7 +220,10 @@ ($state eq 'MY_LEX_START') ) { for ($c = $lexer->yyGet(); $state_map->[$c] eq 'MY_LEX_SKIP'; $c = $lexer->yyGet()) { - $lexer->[LEXER_YYLINENO]++ if $c == ord("\n"); + if ($c == ord("\n")) { + $lexer->[LEXER_YYLINENO]++; + $lexer->[LEXER_YYLINE_START] = $lexer->[LEXER_PTR]; + } } $lexer->[LEXER_TOK_START] = $lexer->[LEXER_PTR] - 1; $state = $state_map->[$c]; @@ -557,11 +570,14 @@ while ( ($lexer->[LEXER_PTR] != length($string) - 1) && ( - ($c = $lexer->yyGet() != ord('*')) || + (($c = $lexer->yyGet()) != ord('*')) || ($lexer->yyPeek() != ord('/')) ) ) { - $lexer->[LEXER_YYLINENO]++ if $c == ord("\n"); + if ($c == ord("\n")) { + $lexer->[LEXER_YYLINENO]++; + $lexer->[LEXER_YYLINE_START] = $lexer->[LEXER_PTR]; + } } $lexer->yySkip() if $lexer->[LEXER_PTR] != length($string) - 1; @@ -596,7 +612,9 @@ $lexer->[LEXER_NEXT_STATE] = 'MY_LEX_END'; return ('END_OF_INPUT',''); } - $state = 'MY_LEX_CHAR'; + else { + $state = 'MY_LEX_CHAR'; + } next; } } @@ -999,6 +1017,8 @@ C<pos()> and C<getPos()> return the current character position as counted from the start of the string +C<col()> and C<getCol()> return the current character position as counted from the start of the current line + C<getLine()> and C<line()> return the current line number. C<getTokens()> returns a reference to an array containing all tokens parsed so far. --- DBIx-MyParsePP-0.50/lib/DBIx/MyParsePP.pm 2007-08-18 04:21:43.000000000 +0100 +++ DBIx-MyParsePP-0.60/lib/DBIx/MyParsePP.pm 2010-11-15 13:14:52.381151951 +0000 @@ -6,7 +6,7 @@ use DBIx::MyParsePP::Query; -our $VERSION = '0.50'; +our $VERSION = '0.60'; use constant MYPARSEPP_YAPP => 0; use constant MYPARSEPP_CHARSET => 1; @@ -53,7 +53,7 @@ version => $parser->[MYPARSEPP_VERSION], sql_mode => $parser->[MYPARSEPP_SQL_MODE], client_capabilities => $parser->[MYPARSEPP_CLIENT_CAPABILITIES], - stmt_prepare_mode => $parser->[MYPARSEPP_CLIENT_CAPABILITIES] + stmt_prepare_mode => $parser->[MYPARSEPP_STMT_PREPARE_MODE] ); my $query = DBIx::MyParsePP::Query->new( --- DBIx-MyParsePP-0.50/META.yml 2007-08-18 04:23:48.000000000 +0100 +++ DBIx-MyParsePP-0.60/META.yml 2010-11-15 13:14:52.381151951 +0000 @@ -1,7 +1,7 @@ # http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: DBIx-MyParsePP -version: 0.50 +version: 0.60 version_from: lib/DBIx/MyParsePP.pm installdirs: site requires: --- DBIx-MyParsePP-0.50/Changes 2007-08-18 03:04:55.000000000 +0100 +++ DBIx-MyParsePP-0.60/Changes 2010-11-15 15:12:19.396159611 +0000 @@ -1,5 +1,11 @@ Revision history for Perl extension DBIx::MyParsePP. +0.60 + Fixed bug with stmt_prepare_mode argument processing + Fixed bug with line number tracking inside comments + LEXER_SERVER_STATUS and SERVER_MORE_RESULTS_EXISTS exported by Lexer to facilitate multi-statement parsing + col() and getCol() methods added to Lexer and Query to facilitate better error reporting + 0.50 myconvpp.pl script removed because compiling the parser requires a patched Parse::Yapp getFields() and getTables() methods added
Having line numbers would be really beneficial. I will look into this.