From b2920a2e9acbf9d169fa804ac0ee1f295bd13666 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Tue, 14 Jan 2020 07:45:39 -0800 Subject: [PATCH] added warning for issue git18 --- lib/Perl/Tidy/Tokenizer.pm | 31 ++++++++++++++++++++++++++++++- t/snippets/expect/git18.def | 13 +++++++++++++ t/snippets/git18.in | 13 +++++++++++++ t/snippets/packing_list.txt | 3 ++- t/snippets16.t | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 t/snippets/expect/git18.def create mode 100644 t/snippets/git18.in diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index e1d644a9..a52a93a1 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -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 index 00000000..d67c57e6 --- /dev/null +++ b/t/snippets/expect/git18.def @@ -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 index 00000000..c33202d7 --- /dev/null +++ b/t/snippets/git18.in @@ -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"; +} diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index a2716b10..a9736c66 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -152,6 +152,7 @@ ../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 @@ -312,4 +313,4 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets16.t rt130394.rt130394 +../snippets16.t git18.def diff --git a/t/snippets16.t b/t/snippets16.t index 50c33172..a4cb2be2 100644 --- a/t/snippets16.t +++ b/t/snippets16.t @@ -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}; -- 2.39.5