From: Steve Hancock Date: Tue, 12 Oct 2021 16:04:39 +0000 (-0700) Subject: add syntax check for variables of the form ${^XXX} X-Git-Tag: 20211029~22 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=be1c74ab61cdaa23cb0a7b14a7bdaaba32809ebb;p=perltidy.git add syntax check for variables of the form ${^XXX} --- 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 {