From b4b5159338a8583d05a70a0ad9cb88576023513e Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Wed, 20 Jul 2022 15:47:22 -0700 Subject: [PATCH] allow future tokenizer change regarding '->' --- lib/Perl/Tidy/Formatter.pm | 40 ++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 0920de7e..8f160453 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -2620,12 +2620,14 @@ sub set_whitespace_flags { next; } - $rtokh_last_last = $rtokh_last; - - $rtokh_last = $rtokh; $last_token = $token; $last_type = $type; + if ( $type ne '#' ) { + $rtokh_last_last = $rtokh_last; + $rtokh_last = $rtokh; + } + $rtokh = $rLL->[$j]; $token = $rtokh->[_TOKEN_]; $type = $rtokh->[_TYPE_]; @@ -2886,26 +2888,29 @@ sub set_whitespace_flags { # 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. + + # Updated to allow detached '->' from tokenizer (issue c140) elsif ( - ##$last_type =~ /^[wCUG]$/ + + # /^[wCUG]$/ $is_wCUG{$last_type} + || ( - ##$last_type =~ /^[wi]$/ + + # /^[wi]$/ $is_wi{$last_type} && ( + + # with prefix '->' or '&' $last_token =~ /^([\&]|->)/ - # or -> or & split from bareword by newline (b1337) - || ( - $last_token =~ /^\w/ - && ( - $rtokh_last_last->[_TYPE_] eq '->' - || ( $rtokh_last_last->[_TYPE_] eq 't' - && $rtokh_last_last->[_TOKEN_] =~ - /^\&\s*$/ ) - ) - ) + # or preceding token '->' (see b1337; c140) + || $rtokh_last_last->[_TYPE_] eq '->' + + # or preceding sub call operator token '&' + || ( $rtokh_last_last->[_TYPE_] eq 't' + && $rtokh_last_last->[_TOKEN_] =~ /^\&\s*$/ ) ) ) ) @@ -2937,9 +2942,10 @@ sub set_whitespace_flags { $ws = WS_OPTIONAL; } - # keep space between 'sub' and '{' for anonymous sub definition + # keep space between 'sub' and '{' for anonymous sub definition, + # be sure type = 'k' (added for c140) if ( $type eq '{' ) { - if ( $last_token eq 'sub' ) { + if ( $last_token eq 'sub' && $last_type eq 'k' ) { $ws = WS_YES; } -- 2.39.5