From: Steve Hancock Date: Sat, 23 Jul 2022 16:47:44 +0000 (-0700) Subject: remove unused code X-Git-Tag: 20220613.03~7 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e7028c331b3520deb3fb74b81f8d9dcf5f559529;p=perltidy.git remove unused code --- diff --git a/CHANGES.md b/CHANGES.md index 9cbb82be..5faa68fe 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,24 +12,27 @@ created for the formatted output. This caused the inode to change. For the new default method, -bm='copy', the input is copied to the backup and then the input file is reopened and rewritten. This preserves the - file inode. Before using the --backup-and-modify-in-place - parameter please verify that it works correctly in your environment and - operating system. + file inode. Tests have not produced any problems with this change, but + before using the --backup-and-modify-in-place parameter please verify + that it works correctly in your environment and operating system. - Fix undefined value message when perltidy -D is used (git #104) - Added parameter --delete-repeated-commas (-drc) to delete repeated - commas. This is off by default. For example, given this line: + commas. This is off by default. I added this option after discovering + an unwanted repeated comma in the perltidy source. For example, given: ignoreSpec( $file, "file",, \%spec, \%Rspec ); # perltidy -drc: ignoreSpec( $file, "file", \%spec, \%Rspec ); - - Fixed a minor inconsistency in html colors when -html is used. - Previously, a '->' at the end of a line got a black color by default, - but a '->' within a line got the color of the following identifier. - Now all pointers get the same color, which is black by default. + - Fixed an inconsistency in html colors near pointers when -html is used. + Previously, a '->' at the end of a line got the 'punctuation color', black + by default but a '->' before an identifier got the color of the following + identifier. Now all pointers get the same color, which is black by default. + Also, previously a word following a '->' was given the color of a bareword, + black by default, but now it is given the color of an identifier. ## 2022 06 13 diff --git a/dev-bin/perltidy_random_run.pl b/dev-bin/perltidy_random_run.pl index 27ee802b..59c2b862 100755 --- a/dev-bin/perltidy_random_run.pl +++ b/dev-bin/perltidy_random_run.pl @@ -798,7 +798,7 @@ if ( -e $basename ) { for ( my $j = 1 ; $j < 99 ; $j++ ) { $ext = 'ba' . $j; $bname = "$basename.$ext"; - next if ( -e $bname ); + next if ( -e $bname || -e $bname . ".gz" ); system "mv $basename $bname"; last; } diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index c09eb585..869eed28 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -2522,7 +2522,7 @@ BEGIN { # The following hash is used to skip over needless if tests. # Be sure to update it when adding new checks in its block. - my @q = qw(k w i C m - Q); + my @q = qw(k w C m - Q); push @q, '#'; @is_special_ws_type{@q} = (1) x scalar(@q); @@ -2720,17 +2720,10 @@ sub set_whitespace_flags { #--------------------------------------------------------------- # The hash '%is_special_ws_type' significantly speeds up this routine, # but be sure to update it if a new check is added. - # Currently has types: qw(k w i C m - Q #) + # Currently has types: qw(k w C m - Q #) if ( $is_special_ws_type{$type} ) { - if ( $type eq 'i' ) { - # never a space before -> - if ( substr( $token, 0, 2 ) eq '->' ) { - $ws = WS_NO; - } - } - - elsif ( $type eq 'k' ) { + if ( $type eq 'k' ) { # Keywords 'for', 'foreach' are special cases for -kpit since # the opening paren does not always immediately follow the @@ -2763,11 +2756,6 @@ sub set_whitespace_flags { # retain any space between '-' and bare word elsif ( $type eq 'w' || $type eq 'C' ) { $ws = WS_OPTIONAL if $last_type eq '-'; - - # never a space before -> - if ( substr( $token, 0, 2 ) eq '->' ) { - $ws = WS_NO; - } } # retain any space between '-' and bare word; for example @@ -6637,55 +6625,6 @@ sub respace_tokens_inner_loop { } } - # Split identifiers with leading arrows, inserting blanks - # if necessary. It is easier and safer here than in the - # tokenizer. For example '->new' becomes two tokens, '->' - # and 'new' with a possible blank between. - # - # Note: there is a related patch in sub set_whitespace_flags - elsif (length($token) > 2 - && substr( $token, 0, 2 ) eq '->' - && $token =~ /^\-\>(.*)$/ - && $1 ) - { - - my $token_save = $1; - my $type_save = $type; - - # Change '-> new' to '->new' - $token_save =~ s/^\s+//g; - - # store a blank to left of arrow if necessary - my $Kprev = $self->K_previous_nonblank($KK); - if ( defined($Kprev) - && $rLL->[$Kprev]->[_TYPE_] ne 'b' - && $rOpts_add_whitespace - && $want_left_space{'->'} == WS_YES ) - { - my $rcopy = copy_token_as_type( $rtoken_vars, 'b', SPACE ); - $self->store_token($rcopy); - } - - # then store the arrow - my $rcopy = copy_token_as_type( $rtoken_vars, '->', '->' ); - $self->store_token($rcopy); - - # store a blank after the arrow if requested - # added for issue git #33 - if ( $want_right_space{'->'} == WS_YES ) { - my $rcopy_b = - copy_token_as_type( $rtoken_vars, 'b', SPACE ); - $self->store_token($rcopy_b); - } - - # then reset the current token to be the remainder, - # and reset the whitespace flag according to the arrow - $token = $rtoken_vars->[_TOKEN_] = $token_save; - $type = $rtoken_vars->[_TYPE_] = $type_save; - $self->store_token($rtoken_vars); - next; - } - # Trim certain spaces in identifiers if ( $type eq 'i' ) { diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 91ee888f..eddc1809 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -29,9 +29,6 @@ use constant DEVEL_MODE => 0; use constant EMPTY_STRING => q{}; use constant SPACE => q{ }; -# This can be removed after testing -use constant OLD_POINTER_LOGIC => 0; - use Perl::Tidy::LineBuffer; use Carp; @@ -3319,27 +3316,6 @@ EOM sub do_POINTER { # '->' - - # OLD POINTER LOGIC: - # if -> points to a bare word, we must scan for an identifier, - # otherwise something like ->y would look like the y operator - - # NOTE: this will currently allow things like - # '->@array' '->*VAR' '->%hash' - # to get parsed as identifiers, even though these are not currently - # allowed syntax. To catch syntax errors like this we could first - # check that the next character and skip this call if it is one of - # ' @ % * '. A disadvantage with doing this is that this would - # have to be fixed if the perltidy syntax is ever extended to make - # any of these valid. So for now this check is not done. - - # POINTER_LOGIC update, Part 1: make pointers separate tokens - # and look backwards when scanning the next thing. This makes the - # logic independent of any line breaks and comments between the '->' - # and the next tokens. - if (OLD_POINTER_LOGIC) { - scan_simple_identifier(); - } return; } ## end sub do_POINTER @@ -3926,13 +3902,6 @@ EOM # true if this token ends the current line # false otherwise - # Patch for c043, part 3: A bareword after '->' expects a TERM - # FIXME: It would be cleaner to give method calls a new type 'M' - # and update sub operator_expected to handle this. - if ( $last_nonblank_type eq '->' ) { - $expecting = TERM; - } - my ( $next_nonblank_token, $i_next ) = find_next_nonblank_token( $i, $rtokens, $max_token_index ); @@ -3968,10 +3937,19 @@ EOM # They may also need to check and set various flags + # Scan a bare word following a -> as an identifier; it could + # have a long package name. Fixes c037, c041. + if ( $last_nonblank_token eq '->' ) { + scan_bare_identifier(); + + # a bareward after '->' gets type 'i' + $type = 'i'; + } + # Quote a word followed by => operator # unless the word __END__ or __DATA__ and the only word on # the line. - if ( !$is_END_or_DATA + elsif ( !$is_END_or_DATA && $next_nonblank_token eq '=' && $rtokens->[ $i_next + 1 ] eq '>' ) { @@ -3996,25 +3974,6 @@ EOM $type = 'w'; } - # Scan a bare word following a -> as an identifier; it could - # have a long package name. Fixes c037, c041. - elsif ( $last_nonblank_token eq '->' ) { - scan_bare_identifier(); - - # POINTER_LOGIC update, Part 2: a bareward after '->' gets type 'i' - if (OLD_POINTER_LOGIC) { - - # OLD_POINTER_LOGIC to catch a '->' on previous line: - # Patch for c043, part 4; use type 'w' after a '->'. - # This is just a safety check on sub scan_bare_identifier, - # which should get this case correct. - $type = 'w'; - } - else { - $type = 'i'; - } - } - # handle operator x (now we know it isn't $x=) elsif ( $expecting == OPERATOR