From: Steve Hancock Date: Thu, 13 Apr 2023 03:37:37 +0000 (-0700) Subject: update for issue git #118 X-Git-Tag: 20230309.03~33 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=a251a0ef48742e4f7137e71dfd18c905ea917517;p=perltidy.git update for issue git #118 --- diff --git a/CHANGES.md b/CHANGES.md index 2dfd7835..d188b780 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,11 @@ ## 2023 03 09.02 + - Issue git #118. A warning will be issued if a duplicate format-skipping + starting marker is seen within a format-skipping section. The same + applies to duplicate code-skipping starting markers within code-skipping + sections. + - Issue git #116. A new flag --valign-if-unless, -viu, was added to allow postfix 'unless' terms to align with postfix 'if' terms. The default remains not to do this. diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 053efcce..9e87060f 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -6738,6 +6738,25 @@ sub set_CODE_type { write_logfile_entry( "Line $input_line_no: Exiting format-skipping section\n"); } + elsif ( + $is_block_comment + + # optional fast pre-check + && ( substr( $rLL->[$Kfirst]->[_TOKEN_], 0, 4 ) eq '#<<<' + || $rOpts_format_skipping_begin ) + + && $rOpts_format_skipping + && ( $rLL->[$Kfirst]->[_TOKEN_] . SPACE ) =~ + /$format_skipping_pattern_begin/ + ) + { + # warn of duplicate starting comment lines, git #118 + my $input_line_no = $line_of_tokens->{_line_number}; + warning( +"Already in format-skipping section which started at line $In_format_skipping_section\n", + $input_line_no + ); + } $CODE_type = 'FS'; next; } @@ -6770,8 +6789,8 @@ sub set_CODE_type { /$format_skipping_pattern_begin/ ) { - $In_format_skipping_section = 1; my $input_line_no = $line_of_tokens->{_line_number}; + $In_format_skipping_section = $input_line_no; write_logfile_entry( "Line $input_line_no: Entering format-skipping section\n"); $CODE_type = 'FS'; @@ -7547,7 +7566,7 @@ sub respace_tokens_inner_loop { foreach my $KK ( $Kfirst .. $Klast ) { # TODO: consider eliminating this closure var by passing directly to - # store_token following pattern of store_tokens_to_go. + # store_token following pattern of store_token_to_go. $Ktoken_vars = $KK; my $rtoken_vars = $rLL->[$KK]; diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 1b8a0255..2e91624d 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -1076,6 +1076,14 @@ sub get_line { $self->log_numbered_msg("Exiting code-skipping section\n"); $self->[_in_skipped_] = 0; } + elsif ( $input_line =~ /$code_skipping_pattern_begin/ ) { + + # warn of duplicate starting comment lines, git #118 + my $lno = $self->[_in_skipped_]; + $self->warning( + "Already in code-skipping section which started at line $lno\n" + ); + } return $line_of_tokens; } @@ -1607,7 +1615,7 @@ sub prepare_for_a_new_file { sub initialize_tokenizer_state { - # TV0: initialized once + # GV1: initialized once # TV1: initialized on each call # TV2: initialized on each call # TV3: @@ -1653,9 +1661,8 @@ sub prepare_for_a_new_file { sub save_tokenizer_state { - # Save package variables: - my $rTV0 = [ - + # Global variables: + my $rGV1 = [ $brace_depth, $context, $current_package, @@ -1690,8 +1697,10 @@ sub prepare_for_a_new_file { $square_bracket_depth, $statement_type, $total_depth, + ]; + # Tokenizer closure variables: my $rTV1 = [ $block_type, $container_type, $expecting, $i, $i_tok, $input_line, @@ -1736,15 +1745,14 @@ sub prepare_for_a_new_file { $last_last_nonblank_type_sequence, $last_nonblank_prototype, ]; - return [ $rTV0, $rTV1, $rTV2, $rTV3, $rTV4, $rTV5, $rTV6 ]; + return [ $rGV1, $rTV1, $rTV2, $rTV3, $rTV4, $rTV5, $rTV6 ]; } ## end sub save_tokenizer_state sub restore_tokenizer_state { my ($rstate) = @_; - my ( $rTV0, $rTV1, $rTV2, $rTV3, $rTV4, $rTV5, $rTV6 ) = @{$rstate}; + my ( $rGV1, $rTV1, $rTV2, $rTV3, $rTV4, $rTV5, $rTV6 ) = @{$rstate}; ( - $brace_depth, $context, $current_package, @@ -1779,7 +1787,8 @@ sub prepare_for_a_new_file { $square_bracket_depth, $statement_type, $total_depth, - ) = @{$rTV0}; + + ) = @{$rGV1}; ( $block_type, $container_type, $expecting, @@ -4953,7 +4962,7 @@ EOM if ( $rOpts_code_skipping && $input_line =~ /$code_skipping_pattern_begin/ ) { - $self->[_in_skipped_] = 1; + $self->[_in_skipped_] = $self->[_last_line_number_]; return; }