From: Steve Hancock Date: Fri, 11 Sep 2020 13:23:33 +0000 (-0700) Subject: fixed several fringe parsing bugs found in testing X-Git-Tag: 20200907.01~19 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=85e01b7965b44899bca94f7e6ef547c3a558741f;p=perltidy.git fixed several fringe parsing bugs found in testing --- diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index f6dcac0b..939e4a44 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -4411,30 +4411,41 @@ sub operator_expected { $op_expected = UNKNOWN; } + # The 'weird parsing rules' of next section do not work for '<' and '?' + # It is best to mark them as unknown. Test case: + # print $fh ; + elsif ( $tok =~ /^[\<\?]$/ ) { + $op_expected = UNKNOWN; + } + # For possible file handle like "$a", Perl uses weird parsing rules. # For example: # print $a/2,"/hi"; - division # print $a / 2,"/hi"; - division # print $a/ 2,"/hi"; - division # print $a /2,"/hi"; - pattern (and error)! - elsif ( ( $prev_type eq 'b' ) && ( $next_type ne 'b' ) ) { + # Some examples where this logic works okay, for '&','*','+': + # print $fh &xsi_protos(@mods); + # my $x = new $CompressClass *FH; + # print $OUT +( $count % 15 ? ", " : "\n\t" ); + elsif ($prev_type eq 'b' + && $next_type ne 'b' ) + { $op_expected = TERM; } - # Note when an operation is being done where a - # filehandle might be expected, since a change in whitespace - # could change the interpretation of the statement. - else { - if ( $tok =~ /^([x\/\+\-\*\%\&\.\?\<]|\>\>)$/ ) { + # Note that '?' and '<' have been moved above + # ( $tok =~ /^([x\/\+\-\*\%\&\.\?\<]|\>\>)$/ ) { + elsif ( $tok =~ /^([x\/\+\-\*\%\&\.]|\>\>)$/ ) { - # Do not complain in 'use' statements, which have special syntax. - # For example, from RT#130344: - # use lib $FindBin::Bin . '/lib'; - if ( $statement_type ne 'use' ) { - complain("operator in print statement not recommended\n"); - } - $op_expected = OPERATOR; + + # Do not complain in 'use' statements, which have special syntax. + # For example, from RT#130344: + # use lib $FindBin::Bin . '/lib'; + if ( $statement_type ne 'use' ) { + complain("operator in print statement not recommended\n"); } + $op_expected = OPERATOR; } } @@ -6374,6 +6385,10 @@ sub scan_identifier_do { if ( $id_scan_state =~ /^[A\:\(\)]/ ) { $id_scan_state = ''; } + + # The deprecated variable $# does not combine with anything on the next line + if ( $identifier eq '$#' ) { $id_scan_state = '' } + if ( $i < 0 ) { $i = 0 } unless ($type) {