]> git.donarmstrong.com Git - perltidy.git/commitdiff
Remove incorrect warning at repeated function paren call
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 6 Jun 2021 16:02:08 +0000 (09:02 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 6 Jun 2021 16:02:08 +0000 (09:02 -0700)
lib/Perl/Tidy/Debugger.pm
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/Tokenizer.pm
local-docs/BugLog.pod

index 3736b808e18cd837feeddbee4d04094042dbe022..0f487959800346df7b0b22a0333e34afa4f15cf6 100644 (file)
@@ -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
index 7d51ebbc94f4b1eee92d03a0611a8ae957f6d79f..5be0fb78bb692f54526ebd0e65d080a73a7e486f 100644 (file)
@@ -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 <<snippets/space2.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;
index 9d60cd222fd3e058e641f16557017c1d3b7043da..177e032df29905fa9ec43a4204b47a9b7d4e538e 100644 (file)
@@ -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' ) {
index c4ec023cf70359fbd643f7510233efa63fd8391b..c15750fe7b1854251369326fdc708fd84f5cb2ef 100644 (file)
@@ -2,6 +2,31 @@
 
 =over 4
 
+=item B<Remove incorrect warning at repeated function paren call>
+
+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<Add warning when lexical sub names match some builtins>
 
 This update adds a warning when lexical subs have names which match some builtin