]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix problem with side comment after pointer, part 3
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 13 Jul 2021 14:16:33 +0000 (07:16 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 13 Jul 2021 14:16:33 +0000 (07:16 -0700)
lib/Perl/Tidy/Tokenizer.pm
local-docs/BugLog.pod

index 2e3daeb150585a3d9523b104e7045416dbb0f14a..7dec89972ec7417af3a758cdf33915cff25630c5 100644 (file)
@@ -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')
index 8bc5b17d16e4112c1e860747157c3c1c6f0c7a28..bfc33fe691df188cef96b59eacb024c921218c4d 100644 (file)
@@ -2,6 +2,34 @@
 
 =over 4
 
+=item B<Fix problem with side comment after pointer, part 3>
+
+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<Avoid line breaks before a slash in certain cases>
 
 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