From: Steve Hancock Date: Tue, 13 Jul 2021 14:16:33 +0000 (-0700) Subject: Fix problem with side comment after pointer, part 3 X-Git-Tag: 20210717~4 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=cab7ed3d3fabfb4e4b47b2f5cc38f01f251fe148;p=perltidy.git Fix problem with side comment after pointer, part 3 --- diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 2e3daeb1..7dec8997 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -3624,6 +3624,14 @@ EOM if ( $pre_type eq 'w' ) { $expecting = operator_expected( [ $prev_type, $tok, $next_type ] ); + + # Patch for c043, part 3: A bareword after '->' expects a TERM + # FIXME: It would be cleaner to give method calls a new type 'M' + # and update sub operator_expected to handle this. + if ( $last_nonblank_type eq '->' ) { + $expecting = TERM; + } + my ( $next_nonblank_token, $i_next ) = find_next_nonblank_token( $i, $rtokens, $max_token_index ); @@ -3758,6 +3766,11 @@ EOM # have a long package name. Fixes c037, c041. if ( $last_nonblank_token eq '->' ) { scan_bare_identifier(); + + # Patch for c043, part 4; use type 'w' after a '->' + # This is just a safety check on sub scan_bare_identifier, which + # should get this case correct. + $type = 'w'; next; } @@ -6331,13 +6344,14 @@ sub scan_bare_identifier_do { else { $package = $current_package; - if ( $is_keyword{$tok} ) { + # patched for c043, part 1: keyword does not follow '->' + if ( $is_keyword{$tok} && $last_nonblank_type ne '->' ) { $type = 'k'; } } - # if it is a bareword.. - if ( $type eq 'w' ) { + # if it is a bareword.. patched for c043, part 2: not following '->' + if ( $type eq 'w' && $last_nonblank_type ne '->' ) { # check for v-string with leading 'v' type character # (This seems to have precedence over filehandle, type 'Y') diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 8bc5b17d..bfc33fe6 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,34 @@ =over 4 +=item B + +This update fixes some incorrect tokenization produced by a side comment +placed between a pointer and a bareword as in this snippet: + + sub tzoffset {}; + + ... + + my $J + += + ( + $self + ->#sc + tzoffset + / ( + 24 + * + 3600 + ) + ); + +If a sub declaration for the bareword has been seen, the following '/' was +being rejected as an operator. This update fixes this case, which is issue +c043. + +13 Jul 2021. + =item B This is a modification to the previous update for case c039 which prevents a line break before a '/' character which follows a bareword or possible indirect object. This rule