From 84f74d01734c14ebd93dba1430db6fd73f0088c5 Mon Sep 17 00:00:00 2001 From: Zakariyya Mughal Date: Thu, 4 Aug 2022 16:21:15 -0400 Subject: [PATCH 1/2] =?UTF-8?q?Update=20use=20of=20PerlTerm=20for=20PPR=20?= =?UTF-8?q?=E2=89=A5=20v0.001000?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the release of PPR v0.001000 there is a backwards incompatible change in the definition of the `PerlTerm` rule to include postfix arrows for dereferencing and methods. This affects the plugin(s): $ git grep -lP '\b(Perl)?(Term|((ScalarAccess|ArrayAccess)(NoSpace)?))' lib/ lib/Babble/Plugin/PostfixDeref.pm --- cpanfile | 2 +- lib/Babble/Plugin/PostfixDeref.pm | 63 +++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/cpanfile b/cpanfile index 33bb7c3..4fab8fb 100644 --- a/cpanfile +++ b/cpanfile @@ -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; diff --git a/lib/Babble/Plugin/PostfixDeref.pm b/lib/Babble/Plugin/PostfixDeref.pm index 65240ee..f50a667 100644 --- a/lib/Babble/Plugin/PostfixDeref.pm +++ b/lib/Babble/Plugin/PostfixDeref.pm @@ -2,6 +2,63 @@ package Babble::Plugin::PostfixDeref; use Moo; +my $term_derefable = q{ + # Copied from rule in PPR::X@0.001002 + # 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)) @@ -65,11 +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))' ], From c1ee5bb899286615f0e3cc02fb6fd9b290b0daf2 Mon Sep 17 00:00:00 2001 From: Zakariyya Mughal Date: Fri, 5 Aug 2022 01:14:12 -0400 Subject: [PATCH 2/2] PostfixDeref: PerlScalarAccess is no longer needed Newer PPR handles the postfix dereference in `PerlTerm` while `PerlScalarAccess` handles indexing without any arrows. This also addresses the issue of . This adds the tests from that PR (djerius++). Co-authored-by: Diab Jerius --- lib/Babble/Plugin/PostfixDeref.pm | 4 ---- t/plugin-postfixderef.t | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Babble/Plugin/PostfixDeref.pm b/lib/Babble/Plugin/PostfixDeref.pm index f50a667..dbe4f8d 100644 --- a/lib/Babble/Plugin/PostfixDeref.pm +++ b/lib/Babble/Plugin/PostfixDeref.pm @@ -126,10 +126,6 @@ sub transform_to_plain { [ term => "(?> $term_derefable )" ], [ postfix => '(?&PerlTermPostfixDereference)' ], ] => $tf); - $top->each_match_within(ScalarAccess => [ - [ term => '(?>(?&PerlVariableScalar))' ], - [ postfix => $scalar_post ], - ] => $tf); } 1; diff --git a/t/plugin-postfixderef.t b/t/plugin-postfixderef.t index a01a43f..d732456 100644 --- a/t/plugin-postfixderef.t +++ b/t/plugin-postfixderef.t @@ -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) {