From be1c74ab61cdaa23cb0a7b14a7bdaaba32809ebb Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Tue, 12 Oct 2021 09:04:39 -0700 Subject: [PATCH] add syntax check for variables of the form ${^XXX} --- lib/Perl/Tidy/Tokenizer.pm | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index c65728bd..42557aba 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -2953,9 +2953,6 @@ EOM # check for special variables like ${^WARNING_BITS} if ( $expecting == TERM ) { - # FIXME: this should work but will not catch errors - # because we also have to be sure that previous token is - # a type character ($,@,%). if ( $last_nonblank_token eq '{' && ( $next_tok !~ /^\d/ ) && ( $next_tok =~ /^\w/ ) ) @@ -2967,6 +2964,24 @@ EOM $tok = $tok . $next_tok; $i = $i + 1; $type = 'w'; + + # Optional coding to try to catch syntax errors. This can + # be removed if it ever causes incorrect warning messages. + # The '{^' should be preceded by either by a type or '$#' + # Examples: + # $#{^CAPTURE} ok + # *${^LAST_FH}{NAME} ok + # @{^HOWDY} ok + # $hash{^HOWDY} error + + # Note that a type sigil '$' may be tokenized as 'Z' + # after something like 'print', so allow type 'Z' + if ( $last_last_nonblank_type ne 't' + && $last_last_nonblank_type ne 'Z' + && $last_last_nonblank_token ne '$#' ) + { + warning("Possible syntax error near '{^'\n"); + } } else { -- 2.39.5