]> git.donarmstrong.com Git - perltidy.git/commitdiff
trim spaces in token split by line break (c139)
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 21 Apr 2022 03:19:07 +0000 (20:19 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 21 Apr 2022 03:19:07 +0000 (20:19 -0700)
lib/Perl/Tidy/Tokenizer.pm
t/snippets/c139.in [new file with mode: 0644]
t/snippets/expect/c139.def [new file with mode: 0644]
t/snippets/packing_list.txt
t/snippets26.t

index 6a060b62687b8d296e32ef4f7911e6833c01fd46..1925338fd6c8af852f8b77f4db4ba2beebc87ce9 100644 (file)
@@ -7310,6 +7310,7 @@ sub scan_identifier_do {
 
                 $tok_is_blank = 1;
 
+                # note: an id with a leading '&' does not actually come this way
                 if ( $identifier =~ /^[\$\%\*\&\@]/ ) {
 
                     if ( length($identifier) > 1 ) {
@@ -7320,6 +7321,13 @@ sub scan_identifier_do {
                     }
                     else {
 
+                        # fix c139: trim line-ending type 't'
+                        if ( $i == $max_token_index ) {
+                            $i    = $i_save;
+                            $type = 't';
+                            last;
+                        }
+
                         # spaces after $'s are common, and space after @
                         # is harmless, so only complain about space
                         # after other type characters. Space after $ and
@@ -7335,8 +7343,16 @@ sub scan_identifier_do {
                     }
                 }
 
-                # else:
-                # space after '->' is ok
+                elsif ( $identifier eq '->' ) {
+
+                    # space after '->' is ok except at line end ..
+                    # so trim line-ending in type '->' (fixes c139)
+                    if ( $i == $max_token_index ) {
+                        $i    = $i_save;
+                        $type = '->';
+                        last;
+                    }
+                }
             }
             elsif ( $tok eq '^' ) {
 
@@ -7595,6 +7611,13 @@ sub scan_identifier_do {
             }
             elsif ( $tok =~ /^\s*$/ ) {               # allow space
                 $tok_is_blank = 1;
+
+                # fix c139: trim line-ending type 't'
+                if ( length($identifier) == 1 && $i == $max_token_index ) {
+                    $i    = $i_save;
+                    $type = 't';
+                    last;
+                }
             }
             elsif ( $tok eq '::' ) {                  # leading ::
                 $id_scan_state = 'A';                 # accept alpha next
diff --git a/t/snippets/c139.in b/t/snippets/c139.in
new file mode 100644 (file)
index 0000000..bba5d5f
--- /dev/null
@@ -0,0 +1,23 @@
+# The '&' has trailing spaces
+@l = &    
+_  
+( -49, -71 );
+
+# This '$' has trailing spaces
+my $    
+b = 40;
+
+# this arrow has trailing spaces
+$r = $c->         
+sql_set_env_attr( $evh, $SQL_ATTR_ODBC_VERSION, $SQL_OV_ODBC2, 0 );
+
+# spaces and blank line
+@l = &    
+
+_  
+( -49, -71 );
+
+# spaces and blank line
+$r = $c->         
+
+sql_set_env_attr( $evh, $SQL_ATTR_ODBC_VERSION, $SQL_OV_ODBC2, 0 );
diff --git a/t/snippets/expect/c139.def b/t/snippets/expect/c139.def
new file mode 100644 (file)
index 0000000..df2c205
--- /dev/null
@@ -0,0 +1,18 @@
+# The '&' has trailing spaces
+@l = &_( -49, -71 );
+
+# This '$' has trailing spaces
+my $b = 40;
+
+# this arrow has trailing spaces
+$r = $c->sql_set_env_attr( $evh, $SQL_ATTR_ODBC_VERSION, $SQL_OV_ODBC2, 0 );
+
+# spaces and blank line
+@l = &
+
+  _( -49, -71 );
+
+# spaces and blank line
+$r = $c->
+
+  sql_set_env_attr( $evh, $SQL_ATTR_ODBC_VERSION, $SQL_OV_ODBC2, 0 );
index 8fd1b7f5e5f722534de5af2595a8bea49b828f8e..cdd9257afb313644fb14f6711118ada0f9a32624 100644 (file)
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
+../snippets26.t        c139.def
index 88aa7523672505090151f95f9ef3f6aed7a17902..5cf8a6cb677f8893bd04018142bad63fa21e1aed 100644 (file)
@@ -8,6 +8,7 @@
 #5 c133.def
 #6 git93.def
 #7 git93.git93
+#8 c139.def
 
 # To locate test #13 you can search for its name or the string '#13'
 
@@ -70,6 +71,32 @@ return
   $x * sin($a) + $y * cos($a);
 ----------
 
+        'c139' => <<'----------',
+# The '&' has trailing spaces
+@l = &    
+_  
+( -49, -71 );
+
+# This '$' has trailing spaces
+my $    
+b = 40;
+
+# this arrow has trailing spaces
+$r = $c->         
+sql_set_env_attr( $evh, $SQL_ATTR_ODBC_VERSION, $SQL_OV_ODBC2, 0 );
+
+# spaces and blank line
+@l = &    
+
+_  
+( -49, -71 );
+
+# spaces and blank line
+$r = $c->         
+
+sql_set_env_attr( $evh, $SQL_ATTR_ODBC_VERSION, $SQL_OV_ODBC2, 0 );
+----------
+
         'git93' => <<'----------',
 use Cwd qw[cwd];
 use Carp qw(carp);
@@ -353,6 +380,31 @@ use vars qw($curdir);
 no strict qw(vars);
 #7...........
         },
+
+        'c139.def' => {
+            source => "c139",
+            params => "def",
+            expect => <<'#8...........',
+# The '&' has trailing spaces
+@l = &_( -49, -71 );
+
+# This '$' has trailing spaces
+my $b = 40;
+
+# this arrow has trailing spaces
+$r = $c->sql_set_env_attr( $evh, $SQL_ATTR_ODBC_VERSION, $SQL_OV_ODBC2, 0 );
+
+# spaces and blank line
+@l = &
+
+  _( -49, -71 );
+
+# spaces and blank line
+$r = $c->
+
+  sql_set_env_attr( $evh, $SQL_ATTR_ODBC_VERSION, $SQL_OV_ODBC2, 0 );
+#8...........
+        },
     };
 
     my $ntests = 0 + keys %{$rtests};