Giter Site home page Giter Site logo

Comments (4)

zmughal avatar zmughal commented on July 19, 2024

Yep, that's because of Try::Tiny's subs conflicting with the PPR built-in rule for feature 'try' so PPR's regex thinks the whole file is invalid Perl.

You have to remove that rule from the grammar to fix it (DCONWAY mentions this in the docs for PPR). This is how I did that with a role:

In my own code where I'm using the [Babble] plugin, it was easier to rename
try to try_tt:

use Import::Into;
use Importer ();
use Try::Tiny ();

sub import {
	my $target = caller;

	# Use postfix so that PPR does not need modification relative to the
	# built-in feature 'try'.
	Importer->import_into('Try::Tiny', $target, (
		map {
			$_ => { -postfix => '_tt' },
		} qw(try catch finally)
	));
}

but I don't necessarily recommend that for others (unless they might be doing a refactor).

from babble.

Leont avatar Leont commented on July 19, 2024

Yep, that's because of Try::Tiny's subs conflicting with the PPR built-in rule for feature 'try' so PPR's regex thinks the whole file is invalid Perl.

I don't think it's because of that; even on my feature-try branch I'm observing this issue.

from babble.

zmughal avatar zmughal commented on July 19, 2024

Yep, that's because of Try::Tiny's subs conflicting with the PPR built-in rule for feature 'try' so PPR's regex thinks the whole file is invalid Perl.

I don't think it's because of that; even on my feature-try branch I'm observing this issue.

You're right. In my test code, I got the transformation as a side-effect of
running the ::DefinedOr plugin twice. :-P I need to figure out why it isn't finding it in a single pass.


for PASSES in $(seq 2); do
  for T in 6.029 fct; do
    git -c advice.detachedHead=false co $T ;
    diff lib/Dist/Zilla.pm <(perl -I $(got-path-for-name-match /perl-parsing-panoply$)/lib -Mutf8::all -MBabble::Grammar -MWith::Roles -MBabble::PluginChain -MPath::Tiny -E '
      my $src = path(shift @ARGV)->slurp_utf8; my $passes = shift @ARGV;
      my $pc = Babble::PluginChain->new( grammar => Babble::Grammar->with::roles( $src =~ /use Try::Tiny/s ? q(PPP::Babble::Grammar::Role::TryTiny) : () )->new );
      $pc->add_plugin($_) for qw(::DefinedOr) x $passes;
      say $pc->transform_document( $src )'  lib/Dist/Zilla.pm $PASSES );
  done;
done

gives the output:

HEAD is now at cba51b6d v6.029
444c444
<     return( $year // (localtime)[5] + 1900 );
---
>     return( (map +(defined($_) ? $_ : (localtime)[5]), $year)[0] + 1900 );
885a886
> 
Previous HEAD position was cba51b6d v6.029
Switched to branch 'fct'
Your branch is up to date with 'Leont/fct'.
444c444
<     return( $year // (localtime)[5] + 1900 );
---
>     return( (map +(defined($_) ? $_ : (localtime)[5]), $year)[0] + 1900 );
887a888
> 
HEAD is now at cba51b6d v6.029
444c444
<     return( $year // (localtime)[5] + 1900 );
---
>     return( (map +(defined($_) ? $_ : (localtime)[5]), $year)[0] + 1900 );
617c617
<                     . ($self->VERSION // '(undef)'),
---
>                     . ((map +(defined($_) ? $_ : '(undef)'), $self->VERSION)[0]),
885a886
> 
Previous HEAD position was cba51b6d v6.029
Switched to branch 'fct'
Your branch is up to date with 'Leont/fct'.
444c444
<     return( $year // (localtime)[5] + 1900 );
---
>     return( (map +(defined($_) ? $_ : (localtime)[5]), $year)[0] + 1900 );
619c619
<                     . ($self->VERSION // '(undef)'),
---
>                     . ((map +(defined($_) ? $_ : '(undef)'), $self->VERSION)[0]),
887a888
> 

from babble.

zmughal avatar zmughal commented on July 19, 2024

Oh, and the first example is wrong because no precedence parsing:

<     return( $year // (localtime)[5] + 1900 );
---
>     return( (map +(defined($_) ? $_ : (localtime)[5]), $year)[0] + 1900 );

is wrong because + is higher precedence than //.

$ perl -MO=Deparse,-p -e ' ( $year // (localtime)[5] + 1900 ) '
($year // (((localtime))[5] + 1900));
-e syntax OK

from babble.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.