From: Steve Hancock Date: Thu, 19 Aug 2021 01:13:53 +0000 (-0700) Subject: Correct parsing error, case c061 X-Git-Tag: 20210717.02~38 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=3bb2b2cabdb00a6ad454c7d6d5aacd7ccddd535e;p=perltidy.git Correct parsing error, case c061 --- diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index e53381e9..c5f955ee 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -3507,7 +3507,25 @@ EOM scan_identifier(); } - last if ($id_scan_state); + if ($id_scan_state) { + + # Still scanning ... + # Check for side comment between sub and prototype (c061) + + # done if nothing left to scan on this line + last if ( $i > $max_token_index ); + + my ( $next_nonblank_token, $i_next ) = + find_next_nonblank_token_on_this_line( $i, $rtokens, + $max_token_index ); + + # done if it was just some trailing space + last if ( $i_next > $max_token_index ); + + # something remains on the line ... must be a side comment + next; + } + next if ( ( $i > 0 ) || $type ); # didn't find any token; start over diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 85aa5a11..e8a517ca 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,37 @@ =over 4 +=item B + +Testing with random input produced an error condition involving a +side comment placed between a sub name and prototype, as in the +following snippet: + + sub + witch # sc + () # prototype may be on new line ... + { print "which?\n" } + witch(); + +The current version of perltidy makes an error: + + # OLD: perltidy + sub witch # sc () # prototype may be on new line ... + { print "which?\n" } + witch(); + +This update corrects the problem: + + # NEW: perltidy + sub witch # sc + () # prototype may be on new line ... + { print "which?\n" } + witch(); + +This fixes case c061; + +18 Aug 2021. + =item B The default formatting produced an undesirable line break at the last '&&' term