From: Steve Hancock Date: Mon, 23 Nov 2020 23:39:44 +0000 (-0800) Subject: fix minor issue with space between a sign and number X-Git-Tag: 20201202~18 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=f477c8b1ee020ec09d5d627dfba4a263a55808fa;p=perltidy.git fix minor issue with space between a sign and number --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index afa2b0f9..ee8c6cb1 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -1836,6 +1836,18 @@ sub set_whitespace_flags { && $last_token eq '{' && $rLL->[ $j + 1 ]->[_TYPE_] eq 'w' ); + # Patch to count a sign separated from a number as a single token, as + # in the following line. Otherwise, it takes two steps to converge: + # deg2rad(- 0.5) + if ( ( $type eq 'm' || $type eq 'p' ) + && $j < $jmax + 1 + && $rLL->[ $j + 1 ]->[_TYPE_] eq 'b' + && $rLL->[ $j + 2 ]->[_TYPE_] eq 'n' + && $rLL->[ $j + 2 ]->[_TOKEN_] =~ /^\d/ ) + { + $j_here = $j + 2; + } + # $j_next is where a closing token should be if # the container has a single token if ( $j_here + 1 > $jmax ) { return (WS_NO) } diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 0cd7d207..114d9964 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,29 @@ =over 4 +=item B + +In developing an improved convergence test, an issue slowing convergence +was found related to signed numbers as in the following line, + + @london = (deg2rad(- 0.5), deg2rad(90 - 51.3)); + +The leading '-' here is separated from the following number '0.5'. This is handled +by tokenizing the minus as type 'm' and the number as type 'n'. The whitespace +between them is removed in formatting, and so the space is gone in the output. +But a little problem is that the default rule for placing spaces within the +parens is based on the token count, after the first formatting the result is + + @london = ( deg2rad( -0.5 ), deg2rad( 90 - 51.3 ) ); + +The next time it is formatted, the '-0.5' counts as one token, resulting in + + @london = ( deg2rad(-0.5), deg2rad( 90 - 51.3 ) ); + +Notice that the space within the parens around the '-0.5' is gone. An update +was made to fix this, so that the final state is reached in one step. This fix +was made 23 Nov 2020. + =item B A rare situation was identified during testing in which a block comment could