Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update use of PerlTerm for PPR ≥ v0.001000 #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpanfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
requires strictures => 2;
requires Moo => 2;
requires PPR => '0.000021';
requires PPR => '0.001004';
requires Mu => 0;
requires 'Module::Runtime' => 0;
67 changes: 59 additions & 8 deletions lib/Babble/Plugin/PostfixDeref.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,63 @@ package Babble::Plugin::PostfixDeref;

use Moo;

my $term_derefable = q{
# Copied from <PerlTerm> rule in PPR::[email protected]
# The remaining alternatives can all take postfix dereferencers...
# ...
(?:
(?= \$ ) (?&PerlScalarAccess)
|
(?= \@ ) (?&PerlArrayAccess)
|
(?= % ) (?&PerlHashAccess)
|
(?&PerlAnonymousSubroutine)
|
(?>(?&PerlNullaryBuiltinFunction)) (?! (?>(?&PerlOWS)) \( )
|
(?&PerlDoBlock) | (?&PerlEvalBlock)
|
(?&PerlCall)
|
(?&PerlVariableDeclaration)
|
(?&PerlTypeglob)
|
(?>(?&PerlParenthesesList))

# Can optionally do a [...] lookup straight after the parens,
# followd by any number of other look-ups
(?:
(?>(?&PerlOWS)) (?&PerlArrayIndexer)
(?:
(?>(?&PerlOWS))
(?>
(?&PerlArrayIndexer)
| (?&PerlHashIndexer)
| (?&PerlParenthesesList)
)
)*+
)?+
|
(?&PerlAnonymousArray)
|
(?&PerlAnonymousHash)
|
(?&PerlDiamondOperator)
|
(?&PerlContextualMatch)
|
(?&PerlQuotelikeS)
|
(?&PerlQuotelikeTR)
|
(?&PerlQuotelikeQX)
|
(?&PerlLiteral)
)
};

my $scalar_post = q{
(?:
(?>(?&PerlOWS))
Expand Down Expand Up @@ -65,15 +122,9 @@ sub transform_to_plain {
$m->submatches->{term}->replace_text($term);
$m->submatches->{postfix}->replace_text('');
};
$top->each_match_within(PrefixPostfixTerm => [
'(?: (?>(?&PerlPrefixUnaryOperator)) (?&PerlOWS) )*+',
[ term => '(?>(?&PerlTerm))' ],
$top->each_match_within(Term => [
[ term => "(?> $term_derefable )" ],
[ postfix => '(?&PerlTermPostfixDereference)' ],
'(?: (?>(?&PerlOWS)) (?&PerlPostfixUnaryOperator) )?+'
] => $tf);
$top->each_match_within(ScalarAccess => [
[ term => '(?>(?&PerlVariableScalar))' ],
[ postfix => $scalar_post ],
] => $tf);
}

Expand Down
4 changes: 4 additions & 0 deletions t/plugin-postfixderef.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ my @cand = (
'my $x = (map @{$_}, ((map $$_, $foo->bar)[0])->baz);' ],
[ 'my @val = $foo->@{qw(key names)};',
'my @val = (map @{$_}{qw(key names)}, $foo);' ],
[ 'my $val = $foo[0];',
'my $val = $foo[0];' ],
[ 'my $val = $foo[$idx];',
'my $val = $foo[$idx];' ],
);

foreach my $cand (@cand) {
Expand Down