]> git.donarmstrong.com Git - perltidy.git/commitdiff
add rule to avoid welding at some barewords
authorSteve Hancock <perltidy@users.sourceforge.net>
Sat, 6 Feb 2021 16:32:02 +0000 (08:32 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sat, 6 Feb 2021 16:32:02 +0000 (08:32 -0800)
lib/Perl/Tidy/Formatter.pm
local-docs/BugLog.pod

index e2cd6847768e137ee3b283bd9a8f6d163519c0fa..be081297ed205f58f4e095455304d9572be66ca1 100644 (file)
@@ -6702,6 +6702,15 @@ sub is_excluded_weld {
     return $match;
 }
 
+# types needed for welding RULE 6
+my %type_ok_after_bareword;
+
+BEGIN {
+
+    my @q = qw# => -> { ( [ #;
+    @type_ok_after_bareword{@q} = (1) x scalar(@q);
+}
+
 sub weld_nested_containers {
     my ($self) = @_;
 
@@ -6989,6 +6998,29 @@ sub weld_nested_containers {
             $do_not_weld ||= $self->is_excluded_weld( $Kinner_opening, 0 );
         }
 
+        # DO-NOT-WELD RULE 6: Do not weld to a container which is followed on
+        # the same line by an unknown bareword token.  This can cause
+        # blinkers (cases b626, b611).
+        if ( !$do_not_weld ) {
+            my $Knext_io = $self->K_next_nonblank($Kinner_opening);
+            next unless ( defined($Knext_io) );
+            my $iline_io_next = $rLL->[$Knext_io]->[_LINE_INDEX_];
+            if ( $iline_io_next == $iline_io ) {
+                my $type_io_next = $rLL->[$Knext_io]->[_TYPE_];
+
+                # Note: may need to eventually also include other types here,
+                # such as 'Z' and 'Y':   if ($type_io_next =~ /^[ZYw]$/) {
+                if ( $type_io_next eq 'w' ) {
+                    my $Knext_io2 = $self->K_next_nonblank($Knext_io);
+                    next unless ( defined($Knext_io) );
+                    my $type_io_next2 = $rLL->[$Knext_io2]->[_TYPE_];
+                    if ( !$type_ok_after_bareword{$type_io_next2} ) {
+                        $do_not_weld = 1;
+                    }
+                }
+            }
+        }
+
         if ($do_not_weld) {
 
             # After neglecting a pair, we start measuring from start of point io
index 60ea105dcb340c39fb3132e8ced520478804ef3b..25832316b61f18c7683df59335a390f1cc33eb5b 100644 (file)
@@ -2,6 +2,16 @@
 
 =over 4
 
+=item B<add rule to avoid welding at some barewords>
+
+A rule was added to prevent certain rare blinking states involving welding.
+The rule is that if an opening container is immediately followed by a bareword which is
+unknown, a weld will be avoided. 
+
+The following cases were fixed with this update: b611 b626.
+
+6 Feb 2021.
+
 =item B<further simplify -bbxi=n implementation>
 
 This update adds a new variable which indicates if a container is permanently