From 20cc9a0eb78b9780befb09a6ec98981e33c0f156 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Fri, 9 Jul 2021 07:37:22 -0700 Subject: [PATCH] Fix problem caused by side comment after ++ --- lib/Perl/Tidy/Tokenizer.pm | 26 +++++++++++++++++++++++--- local-docs/BugLog.pod | 17 +++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index dae48ae2..d19f7a74 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -2928,8 +2928,17 @@ EOM '++' => sub { if ( $expecting == TERM ) { $type = 'pp' } elsif ( $expecting == UNKNOWN ) { + my ( $next_nonblank_token, $i_next ) = find_next_nonblank_token( $i, $rtokens, $max_token_index ); + + # Fix for c042: look past a side comment + if ( $next_nonblank_token eq '#' ) { + ( $next_nonblank_token, $i_next ) = + find_next_nonblank_token( $max_token_index, + $rtokens, $max_token_index ); + } + if ( $next_nonblank_token eq '$' ) { $type = 'pp' } } }, @@ -2951,6 +2960,14 @@ EOM elsif ( $expecting == UNKNOWN ) { my ( $next_nonblank_token, $i_next ) = find_next_nonblank_token( $i, $rtokens, $max_token_index ); + + # Fix for c042: look past a side comment + if ( $next_nonblank_token eq '#' ) { + ( $next_nonblank_token, $i_next ) = + find_next_nonblank_token( $max_token_index, + $rtokens, $max_token_index ); + } + if ( $next_nonblank_token eq '$' ) { $type = 'mm' } } }, @@ -5929,7 +5946,7 @@ sub peek_ahead_for_nonblank_token { } last; } - return $rtokens; + return; } #########i############################################################# @@ -7643,11 +7660,14 @@ sub scan_identifier_do { sub find_next_nonblank_token { my ( $i, $rtokens, $max_token_index ) = @_; + # Returns the next nonblank token after the token at index $i + # To skip past a side comment, and any subsequent block comments + # and blank lines, call with i=$max_token_index + if ( $i >= $max_token_index ) { if ( !peeked_ahead() ) { peeked_ahead(1); - $rtokens = - peek_ahead_for_nonblank_token( $rtokens, $max_token_index ); + peek_ahead_for_nonblank_token( $rtokens, $max_token_index ); } } diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index b0b13ca5..54e9858f 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,23 @@ =over 4 +=item B + +Testing with side comments produced an incorrect error message for this +snippet: + + xxx + ++# + $test, + Internals::SvREADONLY( %$copy) , + "cloned hash restricted?" ; + +The problem was caused by the side comment between the '++' and '$test'. +The same problem occurs for '--' instead of '++'. This is fixed with this +update, case c042. + +8 Jul 2021. + =item B This is related to the previous issue, c037. The following snippet was misparsed -- 2.39.5