]> git.donarmstrong.com Git - perltidy.git/commitdiff
format all signatures separately from prototypes
authorSteve Hancock <perltidy@users.sourceforge.net>
Sun, 18 Oct 2020 15:33:54 +0000 (08:33 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Sun, 18 Oct 2020 15:33:54 +0000 (08:33 -0700)
lib/Perl/Tidy/Tokenizer.pm
local-docs/BugLog.pod
t/snippets/expect/switch1.def
t/snippets11.t

index ff30cf49fc5df742001c041613182a790f0ae150..4c4b0032f3896ed4c414bf8f8bef16fc11c40e7b 100644 (file)
@@ -6688,15 +6688,13 @@ sub scan_identifier_do {
         # does not look like a prototype, we assume it is a SIGNATURE and we
         # will stop and let the the standard tokenizer handle it.  In
         # particular, we stop if we see any nested parens, braces, or commas.
-        # Note, a valid prototype cannot contain any alphabetic character
-        # see https://perldoc.perl.org/perlsub
-        # But it appears that an underscore may be valid now
+        # Also note, a valid prototype cannot contain any alphabetic character
+        #  -- see https://perldoc.perl.org/perlsub
+        # But it appears that an underscore may be valid now, so this is
+        # using [A-Za-z] instead of \w 
         my $saw_opening_paren = $input_line =~ /\G\s*\(/;
         if (
-            ## FIXME: this should be the future version after some
-            ## problems are resolved
-            ## $input_line =~ m/\G(\s*\([^\)\(\}\{\,#A-Za-z]*\))?  # PROTO
-            $input_line =~ m/\G(\s*\([^\)\(\}\{\,#]*\))?  # PROTO
+            $input_line =~ m/\G(\s*\([^\)\(\}\{\,#A-Za-z]*\))?  # PROTO
             (\s*:)?                              # ATTRS leading ':'
             /gcx
             && ( $1 || $2 )
index 1418a09fb1e2d25ea0c11ce7382cfc88ec430542..0d56a83314b59508be0a70a319a23b1b0c80f844 100644 (file)
@@ -1,5 +1,21 @@
 =head1 Issues fixed after release 20201001
 
+=item b<sub signatures no longer parsed with prototypes>
+
+Simple signatures were being parsed with the code for prototypes, which
+prevented them from being formatted with the usual formatting rules.  All
+signatures are now formatted separately from prototypes with the normal
+formatting rules. For example:
+
+ # Old, intput and after formatting:
+ sub t123 ($list=wantarray) { $list ? "list" : "scalar" }
+
+ # New, after formatting
+ sub t123 ( $list = wantarray ) { $list ? "list" : "scalar" }
+
+Notice that some spaces have been introduced within the signature. Previously
+the contents of the parens was left unchanged.
+
 =item b<fix parsing problem with $#>
 
 A problem with parsing variables of the form $# and $#array was found in
@@ -64,12 +80,6 @@ error:
         ) #foo)))
         { $a.$b }
 
-The parenthesized expression in the snippet below was parsed as a prototype
-rather than a signature.  This was fixed.
-
-    sub echo ( $message = 'Hello World!' ) {
-        print "$message\n";
-    }
 
 =item b<improve guess for pattern or division>
 
index 392bbb876fe2611cc216ad679133d0260065dfab..3cb7127b2e9cfaeae2aa7929f9e9951df5346f8c 100644 (file)
@@ -1,4 +1,4 @@
-sub classify_digit($digit) {
+sub classify_digit ($digit) {
     switch ($digit) {
         case 0 { return 'zero' }
         case [ 2, 4, 6, 8 ]{ return 'even' }
index d348293f38d5f68c10afffa33bd7c3c1c7a66423..2e869f867898ebda2ebb65050ba063ad7e5b82aa 100644 (file)
@@ -289,7 +289,7 @@ $a->();
             source => "switch1",
             params => "def",
             expect => <<'#3...........',
-sub classify_digit($digit) {
+sub classify_digit ($digit) {
     switch ($digit) {
         case 0 { return 'zero' }
         case [ 2, 4, 6, 8 ]{ return 'even' }