From f8bd0889395db5ee8be2b24bdaa07493133de845 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Fri, 6 Nov 2020 09:28:38 -0800 Subject: [PATCH] recognize overloaded RPerl operators to avoid error messages --- lib/Perl/Tidy/Logger.pm | 1 - lib/Perl/Tidy/Tokenizer.pm | 28 +++++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/Perl/Tidy/Logger.pm b/lib/Perl/Tidy/Logger.pm index fa85c378..4f197ba8 100644 --- a/lib/Perl/Tidy/Logger.pm +++ b/lib/Perl/Tidy/Logger.pm @@ -233,7 +233,6 @@ sub make_line_information_string { my $square_bracket_depth = $line_of_tokens->{_square_bracket_depth}; my $guessed_indentation_level = $line_of_tokens->{_guessed_indentation_level}; - ##my $rtoken_array = $line_of_tokens->{_rtoken_array}; my $structural_indentation_level = $line_of_tokens->{_level_0}; diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 163e085f..0d267269 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -46,6 +46,7 @@ use vars qw{ %is_block_function %is_block_list_function %saw_function_definition + %saw_use_module $brace_depth $paren_depth @@ -98,7 +99,7 @@ use vars qw{ %is_sub %is_package %is_comma_question_colon - %other_line_endings + %other_line_endings }; # possible values of operator_expected() @@ -1235,6 +1236,7 @@ sub prepare_for_a_new_file { %is_block_function = (); %is_block_list_function = (); %saw_function_definition = (); + %saw_use_module = (); # variables used to track depths of various containers # and report nesting errors @@ -3694,10 +3696,30 @@ EOM else { scan_bare_identifier(); + + if ( $statement_type eq 'use' + && $last_nonblank_token eq 'use' ) + { + $saw_use_module{$current_package}->{$tok} = 1; + } + if ( $type eq 'w' ) { if ( $expecting == OPERATOR ) { + # Patch to avoid error message for RPerl overloaded + # operator functions: use overload + # '+' => \&sse_add, + # '-' => \&sse_sub, + # '*' => \&sse_mul, + # '/' => \&sse_div; + # FIXME: this should eventually be generalized + if ( $saw_use_module{$current_package}->{'RPerl'} + && $tok =~ /^sse_(mul|div|add|sub)$/ ) + { + + } + # don't complain about possible indirect object # notation. # For example: @@ -3708,7 +3730,7 @@ EOM # This will call A::new but we have a 'new' in # main:: which looks like a constant. # - if ( $last_nonblank_type eq 'C' ) { + elsif ( $last_nonblank_type eq 'C' ) { if ( $tok !~ /::$/ ) { complain(<