From df0c44dfc6d098629c6a78e277a7b49067aaec63 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 28 Nov 2022 07:59:26 -0800 Subject: [PATCH] fix b1433, b1434, b1435 --- dev-bin/run_convergence_tests.pl.data | 39 +++++++++++++++++++++++++++ lib/Perl/Tidy/Formatter.pm | 20 ++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/dev-bin/run_convergence_tests.pl.data b/dev-bin/run_convergence_tests.pl.data index 09d4813b..b062e2ab 100644 --- a/dev-bin/run_convergence_tests.pl.data +++ b/dev-bin/run_convergence_tests.pl.data @@ -11096,6 +11096,45 @@ $last = after ( --space-function-paren --want-trailing-commas='b' +==> b1433.in <== + return ( + ( $val || !exists $opts{$opt} ) ? + do { $opts{$opt} = 1 } : + do { delete $opts{$opt}; 1 } + ); + + return ( + ( $val || !exists $opts{$opt} ) ? do { $opts{$opt} = 1 } + : + do { delete $opts{$opt}; 1 } + ); + +==> b1433.par <== +--break-after-all-operators +--keep-old-breakpoints-after=':' +--variable-maximum-line-length + +==> b1435.in <== +(-r _)?do{do$vshnurc;&err($@)} + : + &err( + "Cannot read $vshnurc") + if-f$vshnurc; + +(-r _)? + do{do$vshnurc;&err($@)}: + &err( + "Cannot read $vshnurc") + if-f$vshnurc; + + +==> b1435.par <== +--noadd-whitespace +--break-after-all-operators +--continuation-indentation=7 +--keep-old-breakpoints-after=':' +--maximum-line-length=34 + ==> b146.in <== # State 1 diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index f729d024..5561fba0 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -8861,6 +8861,19 @@ EOM return ( $severe_error, $rqw_lines ); } ## end sub resync_lines_and_tokens +my %is_soft_break_type; + +BEGIN { + + # Soft breaks are needed to avoid conflicts for token types which might be + # treated with special logic for chains. Fixes b1433, 1434, 1435. + # NOTE: $type is used as the hash key for now; if other container tokens + # are added it might be necessary to use a token/type mixture. + my @q = qw# -> ? : && || + - / * #; + @is_soft_break_type{@q} = (1) x scalar(@q); + +} + sub keep_old_line_breaks { # Called once per file to find and mark any old line breaks which @@ -8936,7 +8949,7 @@ sub keep_old_line_breaks { if ( !$seqno ) { my $type = $rLL->[$KK]->[_TYPE_]; if ( $rkeep_break_hash->{$type} ) { - $rbreak_hash->{$KK} = 1; + $rbreak_hash->{$KK} = $is_soft_break_type{$type} ? 2 : 1; } } @@ -8968,7 +8981,10 @@ sub keep_old_line_breaks { } } } - $rbreak_hash->{$KK} = 1 if ($match); + if ($match) { + my $type = $rLL->[$KK]->[_TYPE_]; + $rbreak_hash->{$KK} = $is_soft_break_type{$type} ? 2 : 1; + } } } }; -- 2.39.5