From: Steve Hancock Date: Tue, 2 Jan 2024 15:39:19 +0000 (-0800) Subject: improve error checking X-Git-Tag: 20230912.12~22 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=fb6820be05d254012253f188737c3ee2f989aec2;p=perltidy.git improve error checking --- diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index a0e60d1a..754d6d03 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -9825,13 +9825,31 @@ EOM sub initialize_call_paren_style { # parse --want-call-parens=s and --nowant-call-parens=s + # and store results in this global hash: %call_paren_style = (); - my $val = 0; + my $iter = -1; foreach my $opt_name ( 'nowant-call-parens', 'want-call-parens' ) { - if ( my @q = split_words( $rOpts->{$opt_name} ) ) { - @call_paren_style{@q} = ($val) x scalar(@q); + $iter++; + my $opt = $rOpts->{$opt_name}; + next unless defined($opt); + + # allow comma separators + $opt =~ s/,/ /g; + if ( my @q = split_words($opt) ) { + foreach my $word (@q) { + + # words must be simple identifiers, or '&' + if ( $word !~ /^(?:\&|\w+)$/ || $word =~ /^\d/ ) { + Perl::Tidy::Die( + "Unexpected word in --$opt_name: '$word'\n"); + } + if ( $iter && defined( $call_paren_style{$word} ) ) { + Perl::Tidy::Warn( + "'$word' occurs in both -nwcp and -wcp, using -wcp\n"); + } + } + @call_paren_style{@q} = ($iter) x scalar(@q); } - $val++; } return; } ## end sub initialize_call_paren_style