]> git.donarmstrong.com Git - perltidy.git/commitdiff
Fix error parsing sub attributes with side comment
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 11 Jul 2021 13:45:50 +0000 (06:45 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 11 Jul 2021 13:45:50 +0000 (06:45 -0700)
lib/Perl/Tidy/Tokenizer.pm
local-docs/BugLog.pod

index d62bb6faa413c3442db1d7768205106e5b9d89ee..2e3daeb150585a3d9523b104e7045416dbb0f14a 100644 (file)
@@ -2293,9 +2293,11 @@ EOM
 
             # a pattern cannot follow certain keywords which take optional
             # arguments, like 'shift' and 'pop'. See also '?'.
-            if ( $last_nonblank_type eq 'k'
+            if (
+                $last_nonblank_type eq 'k'
                 && $is_keyword_rejecting_slash_as_pattern_delimiter{
-                    $last_nonblank_token} )
+                    $last_nonblank_token}
+              )
             {
                 $is_pattern = 0;
             }
@@ -2534,9 +2536,11 @@ EOM
             # Patch for rt #126965
             # a pattern cannot follow certain keywords which take optional
             # arguments, like 'shift' and 'pop'. See also '/'.
-            if ( $last_nonblank_type eq 'k'
+            if (
+                $last_nonblank_type eq 'k'
                 && $is_keyword_rejecting_question_as_pattern_delimiter{
-                    $last_nonblank_token} )
+                    $last_nonblank_token}
+              )
             {
                 $is_pattern = 0;
             }
@@ -3603,8 +3607,11 @@ EOM
                 print STDOUT "TOKENIZE:(@debug_list)\n";
             };
 
-            # turn off attribute list on first non-blank, non-bareword
-            if ( $pre_type ne 'w' ) { $in_attribute_list = 0 }
+            # Turn off attribute list on first non-blank, non-bareword.
+            # Added '#' to fix c038.
+            if ( $pre_type ne 'w' && $pre_type ne '#' ) {
+                $in_attribute_list = 0;
+            }
 
             ###############################################################
             # We have the next token, $tok.
@@ -4713,7 +4720,9 @@ EOM
 # /^(\}|\{|BEGIN|END|CHECK|INIT|AUTOLOAD|DESTROY|UNITCHECK|continue|;|if|elsif|else|unless|while|until|for|foreach)$/
                         elsif (
                             $is_zero_continuation_block_type{
-                                $routput_block_type->[$i] } )
+                                $routput_block_type->[$i]
+                            }
+                          )
                         {
                             $in_statement_continuation = 0;
                         }
@@ -4722,7 +4731,9 @@ EOM
                         #     /^(sort|grep|map|do|eval)$/ )
                         elsif (
                             $is_not_zero_continuation_block_type{
-                                $routput_block_type->[$i] } )
+                                $routput_block_type->[$i]
+                            }
+                          )
                         {
                         }
 
@@ -5082,10 +5093,12 @@ sub operator_expected {
 
             # // may follow perl functions which may be unary operators
             # see test file dor.t (defined or);
-            if (   $tok eq '/'
+            if (
+                   $tok eq '/'
                 && $next_type eq '/'
                 && $is_keyword_rejecting_slash_as_pattern_delimiter{
-                    $last_nonblank_token} )
+                    $last_nonblank_token}
+              )
             {
                 $op_expected = OPERATOR;
             }
index ad52685135503da3b024e954950d1d2292079af0..ca984434636a9ef9d9ed0d1fc933d0e225cc0b71 100644 (file)
@@ -2,6 +2,17 @@
 
 =over 4
 
+=item B<Fix error parsing sub attributes with side comment>
+
+Testing with side comments produced an error in the following snippet:
+
+    sub plugh () :#
+      Ugly('\(") : Bad;
+
+This is fixed in this update, case c038.
+
+11 Jul 2021.
+
 =item B<Fix case b1172, a failure to converge>
 
 Random testing produced case b1172, a failure to converge with unusual parametrs.