Skip to content

Commit

Permalink
make symbol-checking regex more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
wchristian committed Feb 8, 2025
1 parent 6bbfb37 commit 8cc3557
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lib/PPI/Token/Symbol.pm
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,24 @@ sub __TOKENIZER__on_char {
return $t->_finalize_token->__TOKENIZER__on_char( $t );
}

# Trim off anything we oversucked...
$content =~ /^(
# Verify and extract actual full symbol name from sigil to end
my $sep = qr/ (?: :: | '(?!\d) ) /x; # :: and ' are namespace separators
my $pattern = qr/
^(
[\$@%&*]
(?: : (?!:) | # Allow single-colon non-magic variables
(?: \w+ | \' (?!\d) \w+ | \:: \w+ )
(?:
# Allow both :: and ' in namespace separators
(?: \' (?!\d) \w+ | \:: \w+ )
)*
(?: :: )? # Technically a compiler-magic hash, but keep it here
(?:
: (?! : ) # allow single-colon non-magic variables
|
$sep? # optional separator
\w+ # a word
(?: $sep \w+ )* # optionally more separator+word pairs
(?: :: )? # optionally what's technically a
# compiler-magic hash, but keep it here
)
)/x or return undef;
)
/x;
return undef if $content !~ $pattern;

unless ( length $1 eq length $content ) {
$t->{line_cursor} += length($1) - length($content);
$t->{token}->{content} = $1;
Expand Down

0 comments on commit 8cc3557

Please sign in to comment.