From 88332067e15f9e9838b3d7520aadbec14ea05a27 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Fri, 20 May 2022 05:51:27 -0700 Subject: [PATCH] fix tokenization issue c147 --- dev-bin/run_tokenizer_tests.pl.data | 6 +++++- lib/Perl/Tidy/Formatter.pm | 5 +++++ lib/Perl/Tidy/Tokenizer.pm | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/dev-bin/run_tokenizer_tests.pl.data b/dev-bin/run_tokenizer_tests.pl.data index 476f0503..408ea2c4 100644 --- a/dev-bin/run_tokenizer_tests.pl.data +++ b/dev-bin/run_tokenizer_tests.pl.data @@ -154,6 +154,11 @@ my$seed=$$^$^T; s s(..)(.)sss ; +==> c147.in <== +my $str = $$# the process ID + . " xxx\n"; +print "str='$str'\n"; + ==> git82.in <== say $ @@ -165,4 +170,3 @@ say { $fh } < 0 to avoid future parsing problems (issue c147) + for ( $rOpts->{'minimum-space-to-comment'} ) { + if ( !$_ || $_ <= 0 ) { $_ = 1 } + } + # implement outdenting preferences for keywords %outdent_keyword = (); my @okw = split_words( $rOpts->{'outdent-keyword-list'} ); diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index fb9e42f4..d08820e1 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -7507,6 +7507,8 @@ sub scan_identifier_do { } elsif ( $tok eq '#' ) { + my $is_punct_var = $identifier eq '$$'; + # side comment or identifier? if ( @@ -7524,6 +7526,9 @@ sub scan_identifier_do { # May also be '$#array' or POSTDEFREF ->$# && ( $identifier =~ /^[\%\@\$\*]$/ || $identifier =~ /\$$/ ) + # but a '#' after '$$' is a side comment; see c147 + && !$is_punct_var + ) { $identifier .= $tok; # keep same state, a $ could follow @@ -7532,6 +7537,7 @@ sub scan_identifier_do { # otherwise it is a side comment if ( $identifier eq '->' ) { } + elsif ($is_punct_var) { $type = 'i' } elsif ( $id_scan_state eq '$' ) { $type = 't' } else { $type = 'i' } $i = $i_save; -- 2.39.5