Skip to content

Commit

Permalink
parse list-embedded curlies as hash constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
s-nez authored and wchristian committed Apr 25, 2019
1 parent eaa601f commit 7fd14b0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/PPI/Lexer.pm
Expand Up @@ -1197,17 +1197,20 @@ sub _curly {
### FIXME This is possibly a bad choice, but will have to do for now.
return 'PPI::Structure::Block' if $Element;

# Special case: Are we the param of a core function
# i.e. map({ $_ => 1 } @foo)
if (
$Parent->isa('PPI::Statement')
and
_INSTANCE($Parent->parent, 'PPI::Structure::List')
) {
# Special case: Are we the param of a core function
# i.e. map({ $_ => 1 } @foo)
my $function = $Parent->parent->parent->schild(-2);
if ( $function and $function->content =~ /^(?:map|grep|sort)$/ ) {
if ( $function and $function->content =~ /^(?:map|grep|sort|eval|do)$/ ) {
return 'PPI::Structure::Block';
}

# Other cases of list-embedded curlies are constructors
return 'PPI::Structure::Constructor';
}

# We need to scan ahead.
Expand Down
2 changes: 1 addition & 1 deletion t/05_lexer.t
Expand Up @@ -5,7 +5,7 @@

use lib 't/lib';
use PPI::Test::pragmas;
use Test::More tests => 218 + ($ENV{AUTHOR_TESTING} ? 1 : 0);
use Test::More tests => 236 + ($ENV{AUTHOR_TESTING} ? 1 : 0);

use File::Spec::Functions ':ALL';
use PPI::Lexer;
Expand Down
1 change: 1 addition & 0 deletions t/data/05_lexer/13_hashref_in_parens.code
@@ -0,0 +1 @@
$hashref = ({ %base_args, arg => $mod_value });
22 changes: 22 additions & 0 deletions t/data/05_lexer/13_hashref_in_parens.dump
@@ -0,0 +1,22 @@
PPI::Document
PPI::Statement
PPI::Token::Symbol '$hashref'
PPI::Token::Whitespace ' '
PPI::Token::Operator '='
PPI::Token::Whitespace ' '
PPI::Structure::List ( ... )
PPI::Statement
PPI::Structure::Constructor { ... }
PPI::Token::Whitespace ' '
PPI::Statement
PPI::Token::Symbol '%base_args'
PPI::Token::Operator ','
PPI::Token::Whitespace ' '
PPI::Token::Word 'arg'
PPI::Token::Whitespace ' '
PPI::Token::Operator '=>'
PPI::Token::Whitespace ' '
PPI::Token::Symbol '$mod_value'
PPI::Token::Whitespace ' '
PPI::Token::Structure ';'
PPI::Token::Whitespace '\n'
2 changes: 1 addition & 1 deletion t/data/08_regression/24_compound.dump
Expand Up @@ -2,7 +2,7 @@ PPI::Document
PPI::Statement
PPI::Token::Word 'eval'
PPI::Structure::List ( ... )
PPI::Statement::Compound
PPI::Statement
PPI::Token::Whitespace ' '
PPI::Structure::Block { ... }
PPI::Statement
Expand Down

0 comments on commit 7fd14b0

Please sign in to comment.