]> git.donarmstrong.com Git - perltidy.git/commitdiff
fix issue b1422, resolve conflicting comma controls
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 7 Nov 2022 23:12:27 +0000 (15:12 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 7 Nov 2022 23:12:27 +0000 (15:12 -0800)
dev-bin/run_convergence_tests.pl.data
lib/Perl/Tidy/Formatter.pm

index 253ea427ed27145dfc9495c87a2689485ad7b521..b2c276250021553661651f99884892dfb214a1c9 100644 (file)
@@ -10843,6 +10843,46 @@ L2hos
 --paren-vertical-tightness=1
 --weld-nested-containers
 
+==> b1422.in <==
+    $_ = (
+        $INFO && $INFO =~ /^\d+$/
+        ? join(
+            '',
+            $close_all,
+"<STRONG>$t_title</STRONG><P>\nThis document was generated using the\n",
+"<A HREF=\"$TEX2HTMLADDRESS\"><STRONG>LaTeX</STRONG>2<tt>HTML</tt></A>",
+            " translator Version $TEX2HTMLVERSION\n",
+            "<P>Copyright &#169; 1993, 1994, 1995, 1996,\n"
+            , "<A HREF=\"$AUTHORADDRESS\">Nikos Drakos</A>, \n"
+            , "Computer Based Learning Unit, University of Leeds.\n"
+            , "<BR>Copyright &#169; 1997, 1998, 1999,\n"
+            , "<A HREF=\"$AUTHORADDRESS2\">Ross Moore</A>, \n"
+            , "Mathematics Department, Macquarie University, Sydney.\n"
+            , "<P>The command line arguments were: <BR>\n "
+            , "<STRONG>latex2html</STRONG> <TT>$argv</TT>\n"
+            ,
+            (
+                ( $SHOW_INIT_FILE && ( $INIT_FILE ne '' ) )
+                ? "\n<P>with initialization from: <TT>$INIT_FILE</TT>\n$init_file_mark\n"
+                : ''
+            ),
+"<P>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,
index e485156e07ae6cc66eb17ffd15845304597adba3..88cd603a057a1a8bca5a3dde2225cbd96914b663 100644 (file)
@@ -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;