From 910130d74849b5025aed6ff9f106e0a5b8fdf346 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 14 Jun 2021 05:44:20 -0700 Subject: [PATCH] Handle nested print format blocks --- lib/Perl/Tidy/Tokenizer.pm | 20 ++++++++++++++++---- local-docs/BugLog.pod | 31 ++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 177e032d..aa21f51a 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -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; } diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 5cd28048..5b987404 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -2,6 +2,31 @@ =over 4 +=item B + +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 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 @@ -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 -- 2.39.5