From e6a10f3bf1e1754b8d7a4531cade8f5fd26ddd5a Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 18 Oct 2020 08:33:54 -0700 Subject: [PATCH] format all signatures separately from prototypes --- lib/Perl/Tidy/Tokenizer.pm | 12 +++++------- local-docs/BugLog.pod | 22 ++++++++++++++++------ t/snippets/expect/switch1.def | 2 +- t/snippets11.t | 2 +- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index ff30cf49..4c4b0032 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -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 ) diff --git a/local-docs/BugLog.pod b/local-docs/BugLog.pod index 1418a09f..0d56a833 100644 --- a/local-docs/BugLog.pod +++ b/local-docs/BugLog.pod @@ -1,5 +1,21 @@ =head1 Issues fixed after release 20201001 +=item b + +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 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 diff --git a/t/snippets/expect/switch1.def b/t/snippets/expect/switch1.def index 392bbb87..3cb7127b 100644 --- a/t/snippets/expect/switch1.def +++ b/t/snippets/expect/switch1.def @@ -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' } diff --git a/t/snippets11.t b/t/snippets11.t index d348293f..2e869f86 100644 --- a/t/snippets11.t +++ b/t/snippets11.t @@ -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' } -- 2.39.5