"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/Perl/Tidy/VerticalAligner.pm" between
Perl-Tidy-20191203.tar.gz and Perl-Tidy-20200110.tar.gz

About: Perltidy is a Perl script indenter and reformatter (beautifier).

VerticalAligner.pm  (Perl-Tidy-20191203):VerticalAligner.pm  (Perl-Tidy-20200110)
package Perl::Tidy::VerticalAligner; package Perl::Tidy::VerticalAligner;
use strict; use strict;
use warnings; use warnings;
our $VERSION = '20191203'; our $VERSION = '20200110';
use Perl::Tidy::VerticalAligner::Alignment; use Perl::Tidy::VerticalAligner::Alignment;
use Perl::Tidy::VerticalAligner::Line; use Perl::Tidy::VerticalAligner::Line;
# The Perl::Tidy::VerticalAligner package collects output lines and # The Perl::Tidy::VerticalAligner package collects output lines and
# attempts to line up certain common tokens, such as => and #, which are # attempts to line up certain common tokens, such as => and #, which are
# identified by the calling routine. # identified by the calling routine.
# #
# There are two main routines: valign_input and flush. Append acts as a # There are two main routines: valign_input and flush. Append acts as a
# storage buffer, collecting lines into a group which can be vertically # storage buffer, collecting lines into a group which can be vertically
skipping to change at line 1202 skipping to change at line 1202
# if ( 1 || $x ) { print "ok 13\n"; } # if ( 1 || $x ) { print "ok 13\n"; }
# else { print "not ok 13\n"; } # else { print "not ok 13\n"; }
# #
# returns a positive value if the else block should be indented # returns a positive value if the else block should be indented
# #
my ( $old_line, $rfields, $rtokens, $rpatterns ) = @_; my ( $old_line, $rfields, $rtokens, $rpatterns ) = @_;
return unless ($old_line); return unless ($old_line);
my $jmax = @{$rfields} - 1; my $jmax = @{$rfields} - 1;
return unless ( $jmax > 0 ); return unless ( $jmax > 0 );
#my $old_line = $group_lines[-1];
# check for balanced else block following if/elsif/unless # check for balanced else block following if/elsif/unless
my $rfields_old = $old_line->get_rfields(); my $rfields_old = $old_line->get_rfields();
# TBD: add handling for 'case' # TBD: add handling for 'case'
return unless ( $rfields_old->[0] =~ /^(if|elsif|unless)\s*$/ ); return unless ( $rfields_old->[0] =~ /^(if|elsif|unless)\s*$/ );
# look for the opening brace after the else, and extract the depth # look for the opening brace after the else, and extract the depth
my $tok_brace = $rtokens->[0]; my $tok_brace = $rtokens->[0];
my $depth_brace; my $depth_brace;
if ( $tok_brace =~ /^\{(\d+)/ ) { $depth_brace = $1; } if ( $tok_brace =~ /^\{(\d+)/ ) { $depth_brace = $1; }
skipping to change at line 2058 skipping to change at line 2056
# see if if extra indentation is possible. # see if if extra indentation is possible.
my $rOpt_lp = $rOpts->{'line-up-parentheses'}; my $rOpt_lp = $rOpts->{'line-up-parentheses'};
my $keep_group_intact = $rOpt_lp && $extra_indent_ok; my $keep_group_intact = $rOpt_lp && $extra_indent_ok;
my $extra_indent_ok_save = $extra_indent_ok; my $extra_indent_ok_save = $extra_indent_ok;
$extra_indent_ok = 0; $extra_indent_ok = 0;
# we will rebuild alignment line group(s); # we will rebuild alignment line group(s);
my @new_lines = @group_lines; my @new_lines = @group_lines;
initialize_for_new_group(); initialize_for_new_group();
##my $has_terminal_ternary = $new_lines[-1]->{_is_terminal_ternary};
# remove unmatched tokens in all lines # remove unmatched tokens in all lines
delete_unmatched_tokens( \@new_lines ); delete_unmatched_tokens( \@new_lines );
foreach my $new_line (@new_lines) { foreach my $new_line (@new_lines) {
# Start a new group if necessary # Start a new group if necessary
if ( !@group_lines ) { if ( !@group_lines ) {
add_to_group($new_line); add_to_group($new_line);
next; next;
skipping to change at line 2104 skipping to change at line 2100
# ------------------------------------------------------------- # -------------------------------------------------------------
if ( $new_line->get_is_hanging_side_comment() ) { if ( $new_line->get_is_hanging_side_comment() ) {
join_hanging_comment( $new_line, $base_line ); join_hanging_comment( $new_line, $base_line );
} }
# If this line has no matching tokens, then flush out the lines # If this line has no matching tokens, then flush out the lines
# BEFORE this line unless both it and the previous line have side # BEFORE this line unless both it and the previous line have side
# comments. This prevents this line from pushing side coments out # comments. This prevents this line from pushing side coments out
# to the right. # to the right.
##elsif ( $new_line->get_jmax() == 1 ) {
elsif ( $new_line->get_jmax() == 1 && !$keep_group_intact ) { elsif ( $new_line->get_jmax() == 1 && !$keep_group_intact ) {
# There are no matching tokens, so now check side comments: # There are no matching tokens, so now check side comments.
# Programming note: accessing arrays with index -1 is
# risky in Perl, but we have verified there is at least one
# line in the group and that there is at least one field.
my $prev_comment = $group_lines[-1]->get_rfields()->[-1]; my $prev_comment = $group_lines[-1]->get_rfields()->[-1];
my $side_comment = $new_line->get_rfields()->[-1]; my $side_comment = $new_line->get_rfields()->[-1];
my_flush_code() unless ( $side_comment && $prev_comment ); my_flush_code() unless ( $side_comment && $prev_comment );
} }
# ------------------------------------------------------------- # -------------------------------------------------------------
# If there is just one previous line, and it has more fields # If there is just one previous line, and it has more fields
# than the new line, try to join fields together to get a match # than the new line, try to join fields together to get a match
# with the new line. At the present time, only a single # with the new line. At the present time, only a single
skipping to change at line 3205 skipping to change at line 3203
my $diff = my $diff =
$cached_line_leading_space_count - $leading_space_count; $cached_line_leading_space_count - $leading_space_count;
if ( $diff > 0 if ( $diff > 0
&& length($seqno_string) && length($seqno_string)
&& length($last_nonblank_seqno_string) == && length($last_nonblank_seqno_string) ==
length($seqno_string) ) length($seqno_string) )
{ {
my @seqno_last = my @seqno_last =
( split /:/, $last_nonblank_seqno_string ); ( split /:/, $last_nonblank_seqno_string );
my @seqno_now = ( split /:/, $seqno_string ); my @seqno_now = ( split /:/, $seqno_string );
if ( $seqno_now[-1] == $seqno_last[0] if ( @seqno_now
&& @seqno_last
&& $seqno_now[-1] == $seqno_last[0]
&& $seqno_now[0] == $seqno_last[-1] ) && $seqno_now[0] == $seqno_last[-1] )
{ {
# OK to outdent .. # OK to outdent ..
# for absolute safety, be sure we only remove # for absolute safety, be sure we only remove
# whitespace # whitespace
my $ws = substr( $test_line, 0, $diff ); my $ws = substr( $test_line, 0, $diff );
if ( ( length($ws) == $diff ) && $ws =~ /^\s+$/ ) { if ( ( length($ws) == $diff ) && $ws =~ /^\s+$/ ) {
$test_line = substr( $test_line, $diff ); $test_line = substr( $test_line, $diff );
 End of changes. 6 change blocks. 
8 lines changed or deleted 8 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)