return ( $is_pattern, $msg );
}
+my %is_known_constant;
+my %is_known_function;
+
+BEGIN {
+
+ # Constants like 'pi' in Trig.pm are common
+ my @q = qw(pi pi2 pi4 pip2 pip4);
+ @{is_known_constant}{@q} = (1) x scalar(@q);
+
+ # parenless calls of 'ok' are common
+ @q = qw( ok );
+ @{is_known_function}{@q} = (1) x scalar(@q);
+}
+
sub guess_if_pattern_or_division {
# this routine is called when we have encountered a / following an
# Both pattern and divide can work here...
- # A very common bare word in math expressions is 'pi'
- if ( $last_nonblank_token eq 'pi' ) {
- $msg .= "division (pattern works too but saw 'pi')\n";
+ # Increase weight of divide if a pure number follows
+ $divide_expected += $next_token =~ /^\d+$/;
+
+ # Check for known constants in the numerator, like 'pi'
+ if ( $is_known_constant{$last_nonblank_token} ) {
+ $msg .=
+"division (pattern works too but saw known constant '$last_nonblank_token')\n";
$is_pattern = 0;
}
# A very common bare word in pattern expressions is 'ok'
- elsif ( $last_nonblank_token eq 'ok' ) {
- $msg .= "pattern (division works too but saw 'ok')\n";
+ elsif ( $is_known_function{$last_nonblank_token} ) {
+ $msg .=
+"pattern (division works too but saw '$last_nonblank_token')\n";
$is_pattern = 1;
}
-=head1 Issues fixed after release 20201207
+=head1 Issues fixed after release 20210111
=over 4
+=item B<Fixed incorrect guess of division vs pattern>
+
+A syntax error was produced in random testing when perltidy was fed
+the following line:
+
+ sub _DR () { pi2 /360 } sub _RD () { 360 /pi2 }
+
+The bareword 'pi2' was not recognized and the text between the two slashes
+was a taken as a possible pattern argument in a parenless call to pi2. Two
+fixes were made to fix this. Perltidy looks for 'pi' but not 'pi2', so the
+first fix was to expand its table to include all variations of 'pi' in Trig.pm.
+Second, the fact that the first slash was followed by a number should have
+tipped the guess to favor division, so this was fixed.
+As it was, a backup spacing rule was used, which favored a pattern.
+
+The formatted result is now
+
+ sub _DR () { pi2 / 360 }
+ sub _RD () { 360 / pi2 }
+
+This update was made 13 Jan 2021.
+
+
=item B<Correct formula for estimating line length with -wn option>
A formula used to estimating maximum line length when the -wn option is set was
to the problem is the very large ci value. This is fixed in a patch made 12 Jan
2021.
+=back
+
+=head1 Issues fixed after release 20201207
+
+=over 4
=item B<Improve indentation of multiline qw quotes when -xci flag is set>