]> git.donarmstrong.com Git - perltidy.git/commitdiff
update for issue git #118
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 13 Apr 2023 03:37:37 +0000 (20:37 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 13 Apr 2023 03:37:37 +0000 (20:37 -0700)
CHANGES.md
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/Tokenizer.pm

index 2dfd7835b8f46b04498556bfce9d2664a9c398e8..d188b7802755e3d5223cd39091928a66e6a209e7 100644 (file)
@@ -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.
index 053efcce711968cac47184f621e7aaada6e9f731..9e87060f0b8cc0dc20f68d25758f5c4ab204a4e4 100644 (file)
@@ -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];
index 1b8a025513ce8b7291ee10fc2992684686135439..2e91624d85d0e8c83d7bbaa94a1351d3637f1a2e 100644 (file)
@@ -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;
                 }