]> git.donarmstrong.com Git - perltidy.git/commitdiff
added warning for issue git18
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 14 Jan 2020 15:45:39 +0000 (07:45 -0800)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 14 Jan 2020 15:45:39 +0000 (07:45 -0800)
lib/Perl/Tidy/Tokenizer.pm
t/snippets/expect/git18.def [new file with mode: 0644]
t/snippets/git18.in [new file with mode: 0644]
t/snippets/packing_list.txt
t/snippets16.t

index e1d644a96bb06a3e89949e14a4edf45ff62e1270..a52a93a1b49a20d6fc8c235d6dabc3ad2c3067e0 100644 (file)
@@ -3067,7 +3067,36 @@ EOM
                             $type = 'v';
                             report_v_string($tok);
                         }
-                        else { $type = 'w' }
+                        else {
+
+                           # Bareword followed by a fat comma ... see 'git18.in'
+                           # If tok is something like 'x17' then it could
+                           # actually be operator x followed by number 17.
+                           # For example, here:
+                           #     123x17 => [ 792, 1224 ],
+                           # (a key of 123 repeated 17 times, perhaps not
+                           # what was intended). We will mark x17 as type
+                           # 'n' and it will be split. If the previous token
+                           # was also a bareword then it is not very clear is
+                           # going on.  In this case we will not be sure that
+                           # an operator is expected, so we just mark it as a
+                           # bareword.  Perl is a little murky in what it does
+                           # with stuff like this, and its behavior can change
+                           # over time.  Something like
+                           #    a x18 => [792, 1224], will compile as
+                           # a key with 18 a's.  But something like
+                           #    push @array, a x18;
+                           # is a syntax error.
+                            if ( $expecting == OPERATOR && $tok =~ /^x\d+$/ ) {
+                                $type = 'n';
+                            }
+                            else {
+
+                                # git #18
+                                $type = 'w';
+                                error_if_expecting_OPERATOR();
+                            }
+                        }
 
                         next;
                     }
diff --git a/t/snippets/expect/git18.def b/t/snippets/expect/git18.def
new file mode 100644 (file)
index 0000000..d67c57e
--- /dev/null
@@ -0,0 +1,13 @@
+# parsing stuff like 'x17' before fat comma
+my %bb = (
+    123 x 18 => '123x18',
+    123 x 19 => '123 x19',
+    123 x 20 => '123x 20',
+    2 x 7    => '2 x 7',
+    x40      => 'x40',
+    'd' x 17 => "'d' x17",
+    c x17    => 'c x17',
+);
+foreach my $key ( keys %bb ) {
+    print "key='$key' => $bb{$key}\n";
+}
diff --git a/t/snippets/git18.in b/t/snippets/git18.in
new file mode 100644 (file)
index 0000000..c33202d
--- /dev/null
@@ -0,0 +1,13 @@
+# parsing stuff like 'x17' before fat comma
+my %bb = (
+    123x18 => '123x18',
+    123 x19 => '123 x19', 
+    123x 20 => '123x 20',
+    2 x 7    => '2 x 7', 
+    x40      => 'x40',
+    'd' x17    => "'d' x17",
+    c x17    => 'c x17', 
+);
+foreach my $key ( keys %bb ) {
+    print "key='$key' => $bb{$key}\n";
+}
index a2716b10979a429bb99c7369634845916afb7c0d..a9736c668ea7b21867e3f6e8e9d1f1d42268be1b 100644 (file)
 ../snippets16.t        ndsm1.def
 ../snippets16.t        ndsm1.ndsm
 ../snippets16.t        rt131288.def
+../snippets16.t        rt130394.rt130394
 ../snippets2.t angle.def
 ../snippets2.t arrows1.def
 ../snippets2.t arrows2.def
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
-../snippets16.t        rt130394.rt130394
+../snippets16.t        git18.def
index 50c331728b20c6cd1258f6c966970e0c238595b5..a4cb2be2ba5d1bf7292d11627d2a371635573e1b 100644 (file)
@@ -18,6 +18,7 @@
 #15 ndsm1.ndsm
 #16 rt131288.def
 #17 rt130394.rt130394
+#18 git18.def
 
 # To locate test #13 you can search for its name or the string '#13'
 
@@ -93,6 +94,22 @@ sub head {
 # git#16, two equality lines with fat commas on the right
 my $Package = $Self->RepositoryGet( %Param, Result => 'SCALAR' );
 my %Structure = $Self->PackageParse( String => $Package );
+----------
+
+        'git18' => <<'----------',
+# parsing stuff like 'x17' before fat comma
+my %bb = (
+    123x18 => '123x18',
+    123 x19 => '123 x19', 
+    123x 20 => '123x 20',
+    2 x 7    => '2 x 7', 
+    x40      => 'x40',
+    'd' x17    => "'d' x17",
+    c x17    => 'c x17', 
+);
+foreach my $key ( keys %bb ) {
+    print "key='$key' => $bb{$key}\n";
+}
 ----------
 
         'multiple_equals' => <<'----------',
@@ -368,6 +385,26 @@ $style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage',
 $factorial = sub { reduce { $a * $b } 1 .. 11 };
 #17...........
         },
+
+        'git18.def' => {
+            source => "git18",
+            params => "def",
+            expect => <<'#18...........',
+# parsing stuff like 'x17' before fat comma
+my %bb = (
+    123 x 18 => '123x18',
+    123 x 19 => '123 x19',
+    123 x 20 => '123x 20',
+    2 x 7    => '2 x 7',
+    x40      => 'x40',
+    'd' x 17 => "'d' x17",
+    c x17    => 'c x17',
+);
+foreach my $key ( keys %bb ) {
+    print "key='$key' => $bb{$key}\n";
+}
+#18...........
+        },
     };
 
     my $ntests = 0 + keys %{$rtests};