From 6551d65fdc15ca16f36ddc82ba96f039a7f08014 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 6 Jun 2021 09:02:08 -0700 Subject: [PATCH] Remove incorrect warning at repeated function paren call --- lib/Perl/Tidy/Debugger.pm | 1 - lib/Perl/Tidy/Formatter.pm | 16 ++++++++-------- lib/Perl/Tidy/Tokenizer.pm | 11 ++++------- local-docs/BugLog.pod | 25 +++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/lib/Perl/Tidy/Debugger.pm b/lib/Perl/Tidy/Debugger.pm index 3736b808..0f487959 100644 --- a/lib/Perl/Tidy/Debugger.pm +++ b/lib/Perl/Tidy/Debugger.pm @@ -81,7 +81,6 @@ sub write_debug_entry { unless ( $self->{_debug_file_opened} ) { $self->really_open_debug_file() } my $fh = $self->{_fh}; - # FIXME: could convert to use of token_array instead foreach my $j ( 0 .. @{$rtoken_type} - 1 ) { # testing patterns diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 7d51ebbc..5be0fb78 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -711,7 +711,7 @@ sub new { # Basic data structures... $self->[_rlines_] = []; # = ref to array of lines of the file $self->[_rlines_new_] = []; # = ref to array of output lines - # (FOR FUTURE DEVELOPMENT) + # 'rLL' = reference to the liner array of all tokens in the file. # 'LL' stands for 'Linked List'. Using a linked list was a disaster, but # 'LL' stuck because it is easy to type. @@ -2034,9 +2034,6 @@ sub initialize_whitespace_hashes { $binary_ws_rules{'i'}{'Q'} = WS_YES; $binary_ws_rules{'n'}{'('} = WS_YES; # occurs in 'use package n ()' - # FIXME: we could to split 'i' into variables and functions - # and have no space for functions but space for variables. For now, - # I have a special patch in the special rules below $binary_ws_rules{'i'}{'('} = WS_NO; $binary_ws_rules{'w'}{'('} = WS_NO; @@ -2360,7 +2357,7 @@ sub set_whitespace_flags { # &{ $_->[1] }( delete $_[$#_]{ $_->[0] } ); # At present, the above & block is marked as type L/R so this case # won't go through here. - if ( $last_type eq '}' ) { $ws = WS_YES } + if ( $last_type eq '}' && $last_token ne ')' ) { $ws = WS_YES } # NOTE: some older versions of Perl had occasional problems if # spaces are introduced between keywords or functions and opening @@ -2389,17 +2386,20 @@ sub set_whitespace_flags { # arrow. The point is, it is best to mark function call parens # right here before that happens. # Patch: added 'C' to prevent blinker, case b934, i.e. 'pi()' + # NOTE: this would be the place to allow spaces between repeated + # parens, like () () (), as in case c017, but I decided that would + # not be a good idea. elsif (( $last_type =~ /^[wCUG]$/ ) - || ( $last_type =~ /^[wi]$/ && $last_token =~ /^(\&|->)/ ) ) + || ( $last_type =~ /^[wi]$/ && $last_token =~ /^([\&]|->)/ ) ) { - $ws = WS_NO unless ($rOpts_space_function_paren); + $ws = $rOpts_space_function_paren ? WS_YES : WS_NO; $set_container_ws_by_keyword->( $last_token, $seqno ); $ris_function_call_paren->{$seqno} = 1; } # space between something like $i and ( in <> # for $i ( 0 .. 20 ) { - # FIXME: eventually, type 'i' needs to be split into multiple + # FIXME: eventually, type 'i' could be split into multiple # token types so this can be a hardwired rule. elsif ( $last_type eq 'i' && $last_token =~ /^[\$\%\@]/ ) { $ws = WS_YES; diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 9d60cd22..177e032d 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -1998,12 +1998,13 @@ EOM if ( $expecting == OPERATOR - # be sure this is not a method call of the form + # Be sure this is not a method call of the form # &method(...), $method->(..), &{method}(...), # $ref[2](list) is ok & short for $ref[2]->(list) # NOTE: at present, braces in something like &{ xxx } - # are not marked as a block, we might have a method call - && $last_nonblank_token !~ /^([\]\}\&]|\-\>)/ + # are not marked as a block, we might have a method call. + # Added ')' to fix case c017, something like ()()() + && $last_nonblank_token !~ /^([\]\}\)\&]|\-\>)/ ) { @@ -2025,10 +2026,6 @@ EOM if ( $next_nonblank_token ne ')' ) { my $hint; - # FIXME: this gives an error parsing something like - # $subsubs[0]()(0); - # which is a valid syntax (see subsub.t). We may - # need to revise this coding. error_if_expecting_OPERATOR('('); if ( $last_nonblank_type eq 'C' ) { diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index c4ec023c..c15750fe 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,31 @@ =over 4 +=item B + +This update removes an incorrect error messagge at the construct ')('. To illustrate, +the following is a valid program: + + my @words = qw(To view this email as a web page go here); + my @subs; + push @subs, sub { my $i=shift; $i %= @words; print "$words[$i] "; return $subs[0]}; + $subs[0](0)(1)(2)(3)(4)(5)(6)(7)(8)(9)(10)(11); + print "\n"; + +However perltidy was giving an error message at the ')(' combination, which is +unusual in perl scripts. This update fixes this. + +These are function call parens, so logically they should be under control of +the -sfp or --space-function-parens parameter. I wrote a patch to do this, but +decided not to implement it. The reason is that, as noted in the manual, +subtle errors in perl scripts can occur when spaces are placed before parens. +So, to avoid possible problems, the -sfp parameter will be restricted to spaces +between a bareword [assumed to be a function] and a paren. + +This update is in Tokenizer.pm and fixes case c017. + +6 Jun 2021. + =item B This update adds a warning when lexical subs have names which match some builtin -- 2.39.5