From 059e8852a06c2634627c48a2d0b06f7dc8b35ccc Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 22 Mar 2020 11:04:25 -0700 Subject: [PATCH] rewrote sub is_essential_whitespace to use \w instead of [_A-Za-z] --- lib/Perl/Tidy/Formatter.pm | 38 ++++++++++++++++++++++++-------------- lib/Perl/Tidy/Tokenizer.pm | 1 - 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 1653b705..90cf0fee 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -6719,8 +6719,14 @@ EOM # # Note: This routine should almost never need to be changed. It is # for avoiding syntax problems rather than for formatting. + + # Uses these global hashes: + # $is_sort_grep_map, $is_trigraph, $is_for_foreach + my ( $tokenll, $typell, $tokenl, $typel, $tokenr, $typer ) = @_; + my $tokenr_is_bareword = ( $tokenr =~ /^\w/ && $tokenr !~ /^\d/ ); + my $result = # never combine two bare words or numbers @@ -6738,13 +6744,15 @@ EOM # do not combine a number with a concatenation dot # example: pom.caputo: # $vt100_compatible ? "\e[0;0H" : ('-' x 78 . "\n"); - || ( ( $typel eq 'n' ) && ( $tokenr eq '.' ) ) - || ( ( $typer eq 'n' ) && ( $tokenl eq '.' ) ) + || ( $typel eq 'n' && $tokenr eq '.' ) + || ( $typer eq 'n' && $tokenl eq '.' ) # do not join a minus with a bare word, because you might form # a file test operator. Example from Complex.pm: # if (CORE::abs($z - i) < $eps); "z-i" would be taken as a file test. - || ( ( $tokenl eq '-' ) && ( $tokenr =~ /^[_A-Za-z]$/ ) ) + || ( $tokenl eq '-' + && $tokenr_is_bareword + && length($tokenr) == 1 ) # do not join a bare word with a minus, like between 'Send' and # '-recipients' here <> @@ -6753,7 +6761,7 @@ EOM # -data => $data; # This is the safest thing to do. If we had the token to the right of # the minus we could do a better check. - || ( ( $tokenr eq '-' ) && ( $typel eq 'w' ) ) + || ( $tokenr eq '-' && $typel eq 'w' ) # and something like this could become ambiguous without space # after the '-': @@ -6761,8 +6769,9 @@ EOM # $a = $b - III; # and even this: # $a = - III; - || ( ( $tokenl eq '-' ) - && ( $typer =~ /^[wC]$/ && $tokenr =~ /^[_A-Za-z]/ ) ) + || ( $tokenl eq '-' + && $typer =~ /^[wC]$/ + && $tokenr_is_bareword ) # '= -' should not become =- or you will get a warning # about reversed -= @@ -6770,12 +6779,13 @@ EOM # keep a space between a quote and a bareword to prevent the # bareword from becoming a quote modifier. - || ( ( $typel eq 'Q' ) && ( $tokenr =~ /^[a-zA-Z_]/ ) ) + || ( $typel eq 'Q' && $tokenr_is_bareword ) # keep a space between a token ending in '$' and any word; # this caused trouble: "die @$ if $@" - || ( ( $typel eq 'i' && $tokenl =~ /\$$/ ) - && ( $tokenr =~ /^[a-zA-Z_]/ ) ) + || ( $typel eq 'i' + && $tokenl =~ /\$$/ + && $tokenr_is_bareword ) # perl is very fussy about spaces before << || ( $tokenr =~ /^\<\