]> git.donarmstrong.com Git - perltidy.git/commitdiff
Handle nested print format blocks
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 14 Jun 2021 12:44:20 +0000 (05:44 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 14 Jun 2021 12:44:20 +0000 (05:44 -0700)
lib/Perl/Tidy/Tokenizer.pm
local-docs/BugLog.pod

index 177e032df29905fa9ec43a4204b47a9b7d4e538e..aa21f51a7d4cf773fcfa0ee2da6966ee48c64a10 100644 (file)
@@ -774,16 +774,28 @@ sub get_line {
         return $line_of_tokens;
     }
 
-    # must print line unchanged if we are in a format section
+    # Print line unchanged if we are in a format section
     elsif ( $tokenizer_self->[_in_format_] ) {
 
         if ( $input_line =~ /^\.[\s#]*$/ ) {
-            write_logfile_entry("Exiting format section\n");
-            $tokenizer_self->[_in_format_] = 0;
-            $line_of_tokens->{_line_type} = 'FORMAT_END';
+
+            # Decrement format depth count at a '.' after a 'format'
+            $tokenizer_self->[_in_format_]--;
+
+            # This is the end when count reaches 0
+            if ( !$tokenizer_self->[_in_format_] ) {
+                write_logfile_entry("Exiting format section\n");
+                $line_of_tokens->{_line_type} = 'FORMAT_END';
+            }
         }
         else {
             $line_of_tokens->{_line_type} = 'FORMAT';
+            if ( $input_line =~ /^\s*format\s+\w+/ ) {
+
+                # Increment format depth count at a 'format' within a 'format'
+                # This is a simple way to handle nested formats (issue c019).
+                $tokenizer_self->[_in_format_]++;
+            }
         }
         return $line_of_tokens;
     }
index 5cd28048da2b6a25470aab114e5e67c73145ce62..5b987404c3c4ac7dacfafb38a9f1026fc0976c94 100644 (file)
@@ -2,6 +2,31 @@
 
 =over 4
 
+=item B<Handle nested print format blocks>
+
+Perltidy was producing an error at nested print format blocks,
+such as
+
+    format NEST =
+    @<<<
+    {
+        my $birds = "birds";
+        local *NEST = *BIRDS{FORMAT};
+        write NEST;
+        format BIRDS =
+    @<<<<<
+    $birds;
+    .
+    "nest"
+      }
+    .
+
+It was ending the first format at the first '.' rather than the second '.' in
+this example.  This update fixes this, issue c019.
+
+13 Jun 2021.
+
+
 =item B<Allow stacked labels without spaces>
 
 When labels are stacked in a single line, such as
@@ -12,12 +37,12 @@ the default is to space them:
 
 A: B: C:
 
-This update allows them to be removed if desired:
+This update allows the spaces to be removed if desired:
 
 # perltidy -naws -dws
 A:B:C:
 
-13 Jun 2021
+13 Jun 2021, c2a63b2
 
 =item B<Fix edge cases of instability involving -wn -lp>
 
@@ -25,7 +50,7 @@ Random testing produced some cases of instability involving -wn -lp and some
 unusual additional parameters.  These were traced to a test for welding,
 and were fixed by refining a certain tolerance.  This fixes cases b1141, b1142.
 
-12 Jun 2021.
+12 Jun 2021, 125494b.
 
 =item B<Remove incorrect warning at repeated function paren call>