]> git.donarmstrong.com Git - perltidy.git/commitdiff
add 'state' as keyword
authorSteve Hancock <perltidy@users.sourceforge.net>
Mon, 19 Oct 2020 01:38:07 +0000 (18:38 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Mon, 19 Oct 2020 01:38:07 +0000 (18:38 -0700)
lib/Perl/Tidy/Tokenizer.pm
local-docs/BugLog.pod

index 46c79f26085c4b3733fc9a99c25597fa4e93b3d4..cd8bf3bacd7dc40a4dc22277af0b2fec0114b189 100644 (file)
@@ -1,6 +1,6 @@
 ######################################################################
 #
-# the Perl::Tidy::Tokenizer package is essentially a filter which
+# The Perl::Tidy::Tokenizer package is essentially a filter which
 # reads lines of perl source code from a source object and provides
 # corresponding tokenized lines through its get_line() method.  Lines
 # flow from the source_object to the caller like this:
@@ -1625,9 +1625,9 @@ sub prepare_for_a_new_file {
     @_ = qw(for foreach);
     @is_for_foreach{@_} = (1) x scalar(@_);
 
-    my %is_my_our;
-    @_ = qw(my our);
-    @is_my_our{@_} = (1) x scalar(@_);
+    my %is_my_our_state;
+    @_ = qw(my our state);
+    @is_my_our_state{@_} = (1) x scalar(@_);
 
     # These keywords may introduce blocks after parenthesized expressions,
     # in the form:
@@ -2251,14 +2251,24 @@ sub prepare_for_a_new_file {
 
             # ATTRS: check for a ':' which introduces an attribute list
             # either after a 'sub' keyword or within a paren list
-            elsif ($statement_type =~ /^sub\b/ ) {
+            elsif ( $statement_type =~ /^sub\b/ ) {
+                $type              = 'A';
+                $in_attribute_list = 1;
+            }
+
+            # Withing a signature, unless we are in a ternary.  For example,
+            # from 't/filter_example.t':
+            #    method foo4 ( $class: $bar ) { $class->bar($bar) }
+            elsif ( $paren_type[$paren_depth] =~ /^sub\b/
+                && !is_balanced_closing_container(QUESTION_COLON) )
+            {
                 $type              = 'A';
                 $in_attribute_list = 1;
             }
 
             # check for scalar attribute, such as
             # my $foo : shared = 1;
-            elsif ($is_my_our{$statement_type}
+            elsif ($is_my_our_state{$statement_type}
                 && $current_depth[QUESTION_COLON] == 0 )
             {
                 $type              = 'A';
@@ -2281,16 +2291,6 @@ sub prepare_for_a_new_file {
                 $type = 'J';
             }
 
-            # Withing a signature.  For example,
-            # from 't/filter_example.t':
-            #    method foo4 ( $class: $bar ) { $class->bar($bar) }
-            elsif ( !is_balanced_closing_container(QUESTION_COLON)
-                && $paren_type[$paren_depth] =~ /^sub\b/ )
-            {
-                $type              = 'A';
-                $in_attribute_list = 1;
-            }
-
             # otherwise, it should be part of a ?/: operator
             else {
                 ( $type_sequence, $indent_flag ) =
@@ -3492,7 +3492,7 @@ EOM
                     }
 
                     # remember my and our to check for trailing ": shared"
-                    elsif ( $is_my_our{$tok} ) {
+                    elsif ( $is_my_our_state{$tok} ) {
                         $statement_type = $tok;
                     }
 
@@ -5455,16 +5455,16 @@ sub guess_if_pattern_or_division {
 
         if ($in_quote) {
 
-           # we didn't find an ending / on this line, so we bias towards
-           # division
+            # we didn't find an ending / on this line, so we bias towards
+            # division
             if ( $divide_expected >= 0 ) {
                 $is_pattern = 0;
                 $msg .= "division (no ending / on this line)\n";
             }
             else {
 
-               # assuming a multi-line pattern ... this is risky, but division
-               # does not seem possible.  If this fails, it would either be due
+                # assuming a multi-line pattern ... this is risky, but division
+                # does not seem possible.  If this fails, it would either be due
                 # to a syntax error in the code, or the division_expected logic
                 # needs to be fixed.
                 $msg        = "multi-line pattern (division not possible)\n";
@@ -6700,7 +6700,9 @@ sub scan_identifier_do {
         # particular, we stop if we see any nested parens, braces, or commas.
         # Also note, a valid prototype cannot contain any alphabetic character
         #  -- see https://perldoc.perl.org/perlsub
-        # old PROTO:
+        # But it appears that an underscore is valid in a prototype, so the
+        # regex below uses [A-Za-z] rather than \w
+        # This is the old regex which has been replaced:
         # $input_line =~ m/\G(\s*\([^\)\(\}\{\,#]*\))?  # PROTO
         my $saw_opening_paren = $input_line =~ /\G\s*\(/;
         if (
@@ -8127,6 +8129,7 @@ BEGIN {
       sqrt
       srand
       stat
+      state
       study
       substr
       symlink
@@ -8349,6 +8352,7 @@ BEGIN {
       splice
       split
       sprintf
+      state
       substr
       syscall
       sysopen
index 7ce22c09ccf1ac026b1ec407869e61ff84099d16..472d94349510ab08ad95c769fc278bf23496184a 100644 (file)
@@ -1,5 +1,15 @@
 =head1 Issues fixed after release 20201001
 
+=item b<added 'state' as keyword>
+
+A statement such as the following was generating an error message at the colon:
+
+   state $a : shared;
+
+The problem was that 'state' was not in the list of keywords. This has been fixed
+and the line now parses without error.  The 'state.t' test file for perl 5.31
+now formats without error.
+
 =item b<sub signatures no longer parsed with prototypes>
 
 Simple signatures (those without commas) were being parsed with code originally