Skip to content

Commit

Permalink
allow variables with spaces after the sigil
Browse files Browse the repository at this point in the history
  • Loading branch information
wchristian committed Feb 15, 2025
1 parent 725a4a1 commit 3cacd05
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Revision history for Perl extension PPI

{{$NEXT}}
- Allow zero byte documents to have a location
- Allow variable names to have whitespace after the sigil (GH#158)

1.281 2024-12-27 14:44:47Z
Summary:
Expand Down
3 changes: 2 additions & 1 deletion lib/PPI/Token/Symbol.pm
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ sub __TOKENIZER__on_char {

# Suck in till the end of the symbol
pos $t->{line} = $t->{line_cursor};
if ( $t->{line} =~ m/\G([\w:\']+)/gc ) {
if ( $t->{line} =~ m/\G(\s*[\w:\']+)/gc ) {
$t->{token}->{content} .= $1;
$t->{line_cursor} += length $1;
}
Expand Down Expand Up @@ -201,6 +201,7 @@ sub __TOKENIZER__on_char {
my $pattern = qr/
^(
[\$@%&*]
\s*
(?:
: (?! : ) # allow single-colon non-magic variables
|
Expand Down
8 changes: 8 additions & 0 deletions lib/PPI/Token/Unknown.pm
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ sub __TOKENIZER__on_char {
return 1;
}

if ( $char eq ' ' ) {
pos $t->{line} = $t->{line_cursor} + 1;
if ( $t->{line} =~ m/\G\s*[a-z_]/gci ) {
$t->{class} = $t->{token}->set_class('Symbol');
return 1;
}
}

# Is it a nameless arg in a signature?
if ( $char eq ')' or $char eq '=' or $char eq ',' ) {
my ($has_sig) = $t->_current_token_has_signatures_active;
Expand Down
4 changes: 0 additions & 4 deletions t/foreach_whitespace.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use PPI::Dumper;
sub test_document;

BASE_SPACE_SYMBOL: {
local $TODO = "crashes";
test_document #
'$ s', #
[
Expand All @@ -24,7 +23,6 @@ BASE_SPACE_SYMBOL: {
}

FOR_LOOP: {
local $TODO = "crashes";
test_document
'for my $ s ( qw( a b ) ) { say $s }',
[
Expand All @@ -48,7 +46,6 @@ FOR_LOOP: {
}

SIGIL_WITH_TRASH: {
local $TODO = "crashes";
test_document
'$ \"8;b',
[
Expand All @@ -61,7 +58,6 @@ SIGIL_WITH_TRASH: {
}

SIGIL_WITH_TABS_AND_TRAIL: {
local $TODO = "crashes";
test_document #
'$ b ', #
[ #
Expand Down

0 comments on commit 3cacd05

Please sign in to comment.