]> git.donarmstrong.com Git - perltidy.git/commitdiff
minor code cleanups
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 22 Jul 2021 22:47:19 +0000 (15:47 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 22 Jul 2021 22:47:19 +0000 (15:47 -0700)
lib/Perl/Tidy/Formatter.pm
lib/Perl/Tidy/HtmlWriter.pm
lib/Perl/Tidy/Tokenizer.pm

index 1baf45ed7fe792c0d12c232b7e7727e99408d77e..9132083dc1980b6f495f2bbcb1d6343f1a7ef977 100644 (file)
@@ -4509,7 +4509,7 @@ sub make_closing_side_comment_prefix {
 
            # Sequence numbers are generated for opening tokens, so every opening
            # token should be sequenced.  Closing tokens will be unsequenced
-           # if they do not have a matching opening toke.
+           # if they do not have a matching opening token.
                 if (   $is_opening_sequence_token{$token}
                     && $type ne 'q'
                     && $type ne 'Q' )
@@ -9661,6 +9661,8 @@ sub process_all_lines {
         #   HERE_END       - last line of here-doc (target word)
         #   FORMAT         - format section
         #   FORMAT_END     - last line of format section, '.'
+        #   SKIP           - code skipping section
+        #   SKIP_END       - last line of code skipping section, '#>>V'
         #   DATA_START     - __DATA__ line
         #   DATA           - unidentified text following __DATA__
         #   END_START      - __END__ line
@@ -9766,10 +9768,8 @@ sub process_all_lines {
             }
 
             # Patch to avoid losing blank lines after a code-skipping block;
-            # fixes case c047.  Note that the code for code-skipping is
-            # currently 'FORMAT'.  If it changes, the next line would need to
-            # be changed.
-            elsif ( $line_type eq 'FORMAT' ) {
+            # fixes case c047.
+            elsif ( $line_type eq 'SKIP_END' ) {
                 $file_writer_object->reset_consecutive_blank_lines();
             }
 
@@ -10078,7 +10078,7 @@ EOM
 
         # Find the parent container of the first token on the next line
         my $parent_seqno = $self->parent_seqno_by_K($Knext_nonblank);
-        goto RETURN unless defined($parent_seqno);
+        goto RETURN unless ( defined($parent_seqno) );
 
         # Must not be a weld (can be unstable)
         goto RETURN
@@ -12013,10 +12013,20 @@ sub compare_indentation_levels {
     sub set_forced_breakpoint {
         my ( $self, $i ) = @_;
 
+        # Set a breakpoint AFTER the token at index $i in the _to_go arrays.
+
+        # Exceptions:
+        # - If the token at index $i is a blank, backup to $i-1 to
+        #   get to the previous nonblank token.
+        # - For certain tokens, the break may be placed BEFORE the token
+        #   at index $i, depending on user break preference settings.
+        # - If a break is made after an opening token, then a break will
+        #   also be made before the corresponding closing token.
+
         return unless defined $i && $i >= 0;
 
-        # Back up at a blank in case we need an = break.
-        # This is a backup fix for cases like b932.
+        # Back up at a blank so we have a token to examine.
+        # This was added to fix for cases like b932 involving an '=' break.
         if ( $i > 0 && $types_to_go[$i] eq 'b' ) { $i-- }
 
         # no breaks between welded tokens
index d9e120b19af04927b93ae2e23417fce1cc9754b6..c5239c2e8e1c942b1da1bd12cb2d15a4fd395cd0 100644 (file)
@@ -1429,6 +1429,8 @@ sub write_line {
         elsif ( $line_type eq 'HERE_END' )   { $line_character = 'h' }
         elsif ( $line_type eq 'FORMAT' )     { $line_character = 'H' }
         elsif ( $line_type eq 'FORMAT_END' ) { $line_character = 'h' }
+        elsif ( $line_type eq 'SKIP' )       { $line_character = 'H' }
+        elsif ( $line_type eq 'SKIP_END' )   { $line_character = 'h' }
         elsif ( $line_type eq 'SYSTEM' )     { $line_character = 'c' }
         elsif ( $line_type eq 'END_START' ) {
             $line_character = 'k';
index 42915e5c1ab9801ffe1f139fbd00d4dba2213100..a50584835217302e01bb10bfbae5d8157a66d5ae 100644 (file)
@@ -748,6 +748,8 @@ sub get_line {
     #   HERE_END       - last line of here-doc (target word)
     #   FORMAT         - format section
     #   FORMAT_END     - last line of format section, '.'
+    #   SKIP           - code skipping section
+    #   SKIP_END       - last line of code skipping section, '#>>V'
     #   DATA_START     - __DATA__ line
     #   DATA           - unidentified text following __DATA__
     #   END_START      - __END__ line
@@ -885,9 +887,9 @@ sub get_line {
     # print line unchanged if in skipped section
     elsif ( $tokenizer_self->[_in_skipped_] ) {
 
-        # NOTE: marked as the existing type 'FORMAT' to keep html working
-        $line_of_tokens->{_line_type} = 'FORMAT';
+        $line_of_tokens->{_line_type} = 'SKIP';
         if ( $input_line =~ /$code_skipping_pattern_end/ ) {
+            $line_of_tokens->{_line_type} = 'SKIP_END';
             $write_logfile_entry->("Exiting code-skipping section\n");
             $tokenizer_self->[_in_skipped_] = 0;
         }
@@ -1078,8 +1080,7 @@ sub get_line {
     # handle start of skipped section
     if ( $tokenizer_self->[_in_skipped_] ) {
 
-        # NOTE: marked as the existing type 'FORMAT' to keep html working
-        $line_of_tokens->{_line_type} = 'FORMAT';
+        $line_of_tokens->{_line_type} = 'SKIP';
         $write_logfile_entry->("Entering code-skipping section\n");
         return $line_of_tokens;
     }
@@ -8786,6 +8787,8 @@ The following additional token types are defined:
     HERE_END       - last line of here-doc (target word)
     FORMAT         - format section
     FORMAT_END     - last line of format section, '.'
+    SKIP           - code skipping section
+    SKIP_END       - last line of code skipping section, '#>>V'
     DATA_START     - __DATA__ line
     DATA           - unidentified text following __DATA__
     END_START      - __END__ line