From: Steve Hancock Date: Mon, 7 Nov 2022 23:12:27 +0000 (-0800) Subject: fix issue b1422, resolve conflicting comma controls X-Git-Tag: 20221112~5 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=be2c168745a8bce4890f6b4bf464ef6c86de4b32;p=perltidy.git fix issue b1422, resolve conflicting comma controls --- diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index 253ea427..b2c27625 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -10843,6 +10843,46 @@ L2hos --paren-vertical-tightness=1 --weld-nested-containers +==> b1422.in <== + $_ = ( + $INFO && $INFO =~ /^\d+$/ + ? join( + '', + $close_all, +"$t_title

\nThis document was generated using the\n", +"LaTeX2HTML", + " translator Version $TEX2HTMLVERSION\n", + "

Copyright © 1993, 1994, 1995, 1996,\n" + , "Nikos Drakos, \n" + , "Computer Based Learning Unit, University of Leeds.\n" + , "
Copyright © 1997, 1998, 1999,\n" + , "Ross Moore, \n" + , "Mathematics Department, Macquarie University, Sydney.\n" + , "

The command line arguments were:
\n " + , "latex2html $argv\n" + , + ( + ( $SHOW_INIT_FILE && ( $INIT_FILE ne '' ) ) + ? "\n

with initialization from: $INIT_FILE\n$init_file_mark\n" + : '' + ), +"

The translation was initiated by $address_data[0] on $address_data[1]", + $open_all, + $_, + ) + : join( + '', + $close_all, + "$INFO\n", + $open_all, + $_, + ) + ); + + +==> b1422.par <== +--keep-old-breakpoints-after=',' + ==> b1423.in <== if ( L2hos ->Link( $image2, diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index e485156e..88cd603a 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -327,6 +327,7 @@ my ( $line_up_parentheses_control_is_lxpl, %trailing_comma_rules, + $controlled_comma_style, # regex patterns for text identification. # Most are initialized in a sub make_**_pattern during configuration. @@ -1500,6 +1501,7 @@ EOM my @toks = @_; foreach my $tok (@toks) { if ( $tok eq '?' ) { $tok = ':' } # patch to coordinate ?/: + if ( $tok eq ',' ) { $controlled_comma_style = 1 } my $lbs = $left_bond_strength{$tok}; my $rbs = $right_bond_strength{$tok}; if ( defined($lbs) && defined($rbs) && $lbs < $rbs ) { @@ -1513,6 +1515,7 @@ EOM my $break_before = sub { my @toks = @_; foreach my $tok (@toks) { + if ( $tok eq ',' ) { $controlled_comma_style = 1 } my $lbs = $left_bond_strength{$tok}; my $rbs = $right_bond_strength{$tok}; if ( defined($lbs) && defined($rbs) && $rbs < $lbs ) { @@ -1796,6 +1799,9 @@ EOM initialize_keep_old_breakpoints( $rOpts->{'keep-old-breakpoints-after'}, 'kba', \%keep_break_after_type ); + $controlled_comma_style ||= $keep_break_before_type{','}; + $controlled_comma_style ||= $keep_break_after_type{','}; + #------------------------------------------------------------ # Make global vars for frequently used options for efficiency #------------------------------------------------------------ @@ -22581,7 +22587,24 @@ sub copy_old_breakpoints { my ( $self, $i_first_comma, $i_last_comma ) = @_; for my $i ( $i_first_comma .. $i_last_comma ) { if ( $old_breakpoint_to_go[$i] ) { - $self->set_forced_breakpoint($i); + + # If the comma style is under certain controls, and if this is a + # comma breakpoint with the comma is at the beginning of the next + # line, then we must pass that index instead. This will allow sub + # set_forced_breakpoints to check and follow the user settings. This + # produces a uniform style and can prevent instability (b1422). + # + # The flag '$controlled_comma_style' will be set if the user + # entered any of -wbb=',' -wba=',' -kbb=',' -kba=','. It is not + # needed or set for the -boc flag. + my $ibreak = $i; + if ( $types_to_go[$ibreak] ne ',' && $controlled_comma_style ) { + my $index = $inext_to_go[$ibreak]; + if ( $index > $ibreak && $types_to_go[$index] eq ',' ) { + $ibreak = $index; + } + } + $self->set_forced_breakpoint($ibreak); } } return;