From a079cdb7b650228679f291623b4041ac633eb670 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sat, 17 Oct 2020 18:09:04 -0700 Subject: [PATCH] fixed parsing error with spaces in $# --- bin/perltidy | 8 ++++---- lib/Perl/Tidy/Tokenizer.pm | 15 ++++++++++++++- local-docs/BugLog.pod | 15 +++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/bin/perltidy b/bin/perltidy index 2dcff4da..cf094014 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -2353,10 +2353,10 @@ When this flag is set perltidy makes a preliminary pass through the file and identifies all nested pairs of containers. To qualify as a nested pair, the closing container symbols must be immediately adjacent and the opening symbols must either (1) be adjacent as in the above example, or (2) have an anonymous -sub declaration following the outer opening container symbol, or (3) have an -outer opening paren separated from the inner opening symbol by any single -non-container symbol or something that looks like a function evaluation, -as illustrated in the next examples. +sub declaration following an outer opening container symbol which is not a +code block brace, or (3) have an outer opening paren separated from the inner +opening symbol by any single non-container symbol or something that looks like +a function evaluation, as illustrated in the next examples. Any container symbol may serve as both the inner container of one pair and as the outer container of an adjacent pair. Consequently, any number of adjacent diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 9375abac..ff30cf49 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -6127,6 +6127,7 @@ sub scan_identifier_do { my $i_save = $i; while ( $i < $max_token_index ) { + my $last_tok_is_blank = $tok_is_blank; if ($tok_is_blank) { $tok_is_blank = undef } else { $i_save = $i } @@ -6191,7 +6192,19 @@ sub scan_identifier_do { # a # inside a prototype or signature can only start a comment && !$in_prototype_or_signature ) - { # $#array + { + # A '#' starts a comment if it follows a space. For example, + # the following is equivalent to $ans=40. + # my $ # + # ans = 40; + if ($last_tok_is_blank) { + $id_scan_state = ''; + $i = $i_save; + $type = 'i'; + last; + } + + # May be '$#' or '$#array' $identifier .= $tok; # keep same state, a $ could follow } diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 376baf5e..1418a09f 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -1,5 +1,20 @@ =head1 Issues fixed after release 20201001 +=item b + +A problem with parsing variables of the form $# and $#array was found in +testing and fixed. For most variables the leading sigil may be separated from +the remaining part of the identifier by whitespace. An exception is for a +variable beginning with '$#'. If there is any space between the '$' and '#' +then the '#' starts a comment. So the following snippet is has valid syntax +and is equivalent to $ans=40; + + my $ # + # + ans = 40; + +This was being misparsed and was fixed 17 Oct 2020. + =item b During testing the following error was found and fixed. -- 2.39.5