]> git.donarmstrong.com Git - perltidy.git/commitdiff
sharpen identification of indirect objects
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 21 Aug 2023 04:52:17 +0000 (21:52 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 21 Aug 2023 04:52:17 +0000 (21:52 -0700)
lib/Perl/Tidy/Tokenizer.pm
t/snippets/expect/essential.essential2
t/snippets/expect/kgb2.def
t/snippets/expect/kgb2.kgb
t/snippets/expect/tick1.def
t/snippets/packing_list.txt
t/snippets11.t
t/snippets14.t
t/snippets3.t

index 00c7e07b1881696ce493d001979b2ff0f1c0a599..bbf61d824f7dfb83baa3a5936867a62ba631354d 100644 (file)
@@ -2719,6 +2719,20 @@ EOM
         return;
     } ## end sub do_VERTICAL_LINE
 
+    # An identifier in possible indirect object location followed by any of
+    # these tokens: -> , ; } (plus others) is not an indirect object. Fix c257.
+    my %Z_test_hash;
+
+    BEGIN {
+        my @q = qw#
+          -> ; } ) ]
+          => =~ = == !~ || >= != *= .. && |= .= -= += <= %=
+          ^= &&= ||= //= <=>
+          #;
+        push @q, ',';
+        @{Z_test_hash}{@q} = (1) x scalar(@q);
+    }
+
     sub do_DOLLAR_SIGN {
 
         my $self = shift;
@@ -2747,11 +2761,12 @@ EOM
         {
 
             # An identifier followed by '->' is not indirect object;
-            # fixes b1175, b1176
-            my ( $next_nonblank_type, $i_next ) =
-              $self->find_next_noncomment_type( $i, $rtokens,
+            # fixes b1175, b1176. Fix c257: Likewise for other tokens like
+            # comma, semicolon, closing brace, ...
+            my ( $next_nonblank_token, $i_next ) =
+              $self->find_next_noncomment_token( $i, $rtokens,
                 $max_token_index );
-            $type = 'Z' if ( $next_nonblank_type ne '->' );
+            $type = 'Z' if ( !$Z_test_hash{$next_nonblank_token} );
         }
         return;
     } ## end sub do_DOLLAR_SIGN
@@ -8935,7 +8950,7 @@ sub find_next_nonblank_token {
     return ( $next_nonblank_token, $i );
 } ## end sub find_next_nonblank_token
 
-sub find_next_noncomment_type {
+sub find_next_noncomment_token {
     my ( $self, $i, $rtokens, $max_token_index ) = @_;
 
     # Given the current character position, look ahead past any comments
@@ -8974,7 +8989,7 @@ sub find_next_noncomment_type {
     }
 
     return ( $next_nonblank_token, $i_next );
-} ## end sub find_next_noncomment_type
+} ## end sub find_next_noncomment_token
 
 sub is_possible_numerator {
 
index 71fa60353644d9caaf13e86dfb92bb1efd084b3d..1a0554532cdf29058cd954ce4d8406ec69bbd784 100644 (file)
@@ -118,7 +118,9 @@ xvals$a
 +
 0.1
 *
-yvals$a;
+yvals
+$a
+;
 # keep paren separate here:
 use
 Foo::Bar (
index 98e8f1fc9d0448050b979df92ef47361ad72e3a1..71db040cf6e9b9b0949f2da08a0ade7a58a31577 100644 (file)
@@ -1,7 +1,7 @@
 # with -kgb, do no break after last my
 sub next_sibling {
     my $self     = shift;
-    my $parent   = $_PARENT{ refaddr $self} or return '';
+    my $parent   = $_PARENT{ refaddr $self } or return '';
     my $key      = refaddr $self;
     my $elements = $parent->{children};
     my $position = List::MoreUtils::firstidx {
index 889c85ac8eafc201fe86c8e2fea50a315575f419..7e4838bf058b5dfe9c85ba6d216024463f7f6077 100644 (file)
@@ -2,7 +2,7 @@
 sub next_sibling {
 
     my $self     = shift;
-    my $parent   = $_PARENT{ refaddr $self} or return '';
+    my $parent   = $_PARENT{ refaddr $self } or return '';
     my $key      = refaddr $self;
     my $elements = $parent->{children};
     my $position = List::MoreUtils::firstidx {
index 85e212887dfa576255452cbe7338be9c8647c88c..4a14d9b58029988b2d778f9b03e821ac769b1c4c 100644 (file)
@@ -4,7 +4,7 @@ print $p'u'a;    # print "mooo"
 
 sub a::that {
     $p't'u = "wwoo\n";
-    return sub { print $p't'u}
+    return sub { print $p't'u }
 }
 $a'that = a'that();
 $a'that->();     # print "wwoo"
index 98bc25a82269752f851f86f94d200a56ee9fd789..66fcffff42e77b8f3a51f7cd88331880aab1dcfc 100644 (file)
 ../snippets28.t        xbt.xbt1
 ../snippets28.t        xbt.xbt2
 ../snippets28.t        xbt.xbt3
+../snippets28.t        lrt.def
+../snippets28.t        lrt.lrt
 ../snippets3.t ce_wn1.ce_wn
 ../snippets3.t ce_wn1.def
 ../snippets3.t colin.colin
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
-../snippets28.t        lrt.def
-../snippets28.t        lrt.lrt
index a9d7dd02732d440fc471fcdb6ca50a3c93c582d8..ec0a8e14ef1de15941a0db3c5cdce58fcbb7b35e 100644 (file)
@@ -362,7 +362,7 @@ print $p'u'a;    # print "mooo"
 
 sub a::that {
     $p't'u = "wwoo\n";
-    return sub { print $p't'u}
+    return sub { print $p't'u }
 }
 $a'that = a'that();
 $a'that->();     # print "wwoo"
index aca0d3653761c02c75f8898e72d99301d1acd1c0..5a85f4af65f31b3e551e054e8a7c3723e0521839 100644 (file)
@@ -711,7 +711,7 @@ exit 1;
 # with -kgb, do no break after last my
 sub next_sibling {
     my $self     = shift;
-    my $parent   = $_PARENT{ refaddr $self} or return '';
+    my $parent   = $_PARENT{ refaddr $self } or return '';
     my $key      = refaddr $self;
     my $elements = $parent->{children};
     my $position = List::MoreUtils::firstidx {
@@ -732,7 +732,7 @@ sub next_sibling {
 sub next_sibling {
 
     my $self     = shift;
-    my $parent   = $_PARENT{ refaddr $self} or return '';
+    my $parent   = $_PARENT{ refaddr $self } or return '';
     my $key      = refaddr $self;
     my $elements = $parent->{children};
     my $position = List::MoreUtils::firstidx {
index f1c77f590e4b8139cf10d3396a50903d8477fef5..067427d2aff8ef7b1021d9a201e325338ac3a3c1 100644 (file)
@@ -561,7 +561,9 @@ xvals$a
 +
 0.1
 *
-yvals$a;
+yvals
+$a
+;
 # keep paren separate here:
 use
 Foo::Bar (