]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix minor issue with space between a sign and number
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 23 Nov 2020 23:39:44 +0000 (15:39 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 23 Nov 2020 23:39:44 +0000 (15:39 -0800)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index afa2b0f9c699987e4a19703096ebb1668ae1f57f..ee8c6cb1e651c1f8e40ec2a17b500aefa2262777 100644 (file)
@@ -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) }
index 0cd7d207b2adc3c6f1234376a3d7c436a1b3d765..114d99648df0ed9523eb09efd80eb3ede069c6a5 100644 (file)
@@ -2,6 +2,29 @@
 
 =over 4
 
+=item B<fix for formatting signed numbers with spaces>
+
+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<fix to prevent conversion of a block comment to hanging side comment>
 
 A rare situation was identified during testing in which a block comment could