]> git.donarmstrong.com Git - perltidy.git/commitdiff
fixed parsing error with spaces in $#
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 18 Oct 2020 01:09:04 +0000 (18:09 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 18 Oct 2020 01:09:04 +0000 (18:09 -0700)
bin/perltidy
lib/Perl/Tidy/Tokenizer.pm
local-docs/BugLog.pod

index 2dcff4dab9cc2def4d161aae4c38159d778f6f60..cf0940149c25789e098ebc724c3b0272c67aa9c6 100755 (executable)
@@ -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
index 9375abacfafd71bb5506aae2c108bea56d09d193..ff30cf49fc5df742001c041613182a790f0ae150 100644 (file)
@@ -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
             }
 
index 376baf5e4ef086247713c55bef38a1af7eaa5488..1418a09fb1e2d25ea0c11ce7382cfc88ec430542 100644 (file)
@@ -1,5 +1,20 @@
 =head1 Issues fixed after release 20201001
 
+=item b<fix parsing problem with $#>
+
+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<fix missing line break for hash of subs with signatures>
 
 During testing the following error was found and fixed.