Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the PPI CPAN distribution.

Report information
The Basics
Id: 55749
Status: open
Priority: 0/
Queue: PPI

People
Owner: Nobody in particular
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: mis-parse of negation -POSIX::DBL_MAX()
Date: Sun, 21 Mar 2010 09:18:18 +1100
To: bug-PPI [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
Download (untitled) / with headers
text/plain 947b
In the debian packaged ppi 1.209 and perl 5.10.1, an input return -POSIX::DBL_MAX() is parsed as PPI::Document PPI::Statement::Break [ 1, 1, 1 ] PPI::Token::Word 'return' [ 1, 8, 8 ] PPI::Token::Word '-POSIX' [ 1, 14, 14 ] PPI::Token::Word '::DBL_MAX' PPI::Structure::List ( ... ) where I expected it to be a negation of the whole "POSIX::DBL_MAX", something like the following, which I believe is how perl parses and runs it (irrespective whether a prototype for that func is available when it compiles). PPI::Document PPI::Statement::Break [ 1, 1, 1 ] PPI::Token::Word 'return' [ 1, 8, 8 ] PPI::Token::Operator '-' [ 1, 10, 10 ] PPI::Token::Word 'POSIX::DBL_MAX' PPI::Structure::List ( ... )
This is confirmed, but it's a duplicate
Subject: Re: [rt.cpan.org #55749] mis-parse of negation -POSIX::DBL_MAX()
Date: Wed, 02 Mar 2011 10:13:47 +1100
To: bug-PPI [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
I lately had the misfortune to wonder exactly when -foo quotes and when not. I suspect if followed by a "(" then it's definitely a negate and function call. But if not then it might depend whether a POSIX::DBL_MAX subr exists or not. Eg. use strict; use POSIX (); my $x = -POSIX::DBL_MAX; print $x; => Ambiguous use of -POSIX::DBL_MAX resolved as -&POSIX::DBL_MAX() -1.79769313486232e+308 versus use strict; my $x = -POSIX::DBL_MAX; print $x; => -POSIX::DBL_MAX Maybe PPI::Token::Word could note that it parses such a thing as a "-word" whereas at runtime it depends whether a "word()" subr exists. I suppose perlcritic could advise against bare "-foo" so as not to risk hitting a subr (asking instead for a fat comma "-foo => 123" say). -- Some people say cricket is like watching grass grow. That's not true, International Rules Grass Growing is much more exciting. Cricket takes 5 days and ends in a draw, but grass growing is 4 days and sure to have a winner.
Subject: Re: [rt.cpan.org #55749] mis-parse of negation -POSIX::DBL_MAX()
Date: Wed, 2 Mar 2011 11:08:48 +1100
To: bug-PPI [...] rt.cpan.org
From: Adam Kennedy <adamkennedybackup [...] gmail.com>
Download (untitled) / with headers
text/plain 1.3k
I'm tempted to just make -FOO::BAR return negation all the time, since I can't recall ever seeing this in the wild. Adam K On 2 March 2011 10:13, Kevin Ryde via RT <bug-PPI@rt.cpan.org> wrote: Show quoted text
>       Queue: PPI >  Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=55749 > > > I lately had the misfortune to wonder exactly when -foo quotes and when > not.  I suspect if followed by a "(" then it's definitely a negate and > function call.  But if not then it might depend whether a POSIX::DBL_MAX > subr exists or not. > > Eg. > >    use strict; >    use POSIX (); >    my $x = -POSIX::DBL_MAX; >    print $x; > >    => >    Ambiguous use of -POSIX::DBL_MAX resolved as -&POSIX::DBL_MAX() >    -1.79769313486232e+308 > > versus > >    use strict; >    my $x = -POSIX::DBL_MAX; >    print $x; > >    => >    -POSIX::DBL_MAX > > Maybe PPI::Token::Word could note that it parses such a thing as a > "-word" whereas at runtime it depends whether a "word()" subr exists. > > I suppose perlcritic could advise against bare "-foo" so as not to risk > hitting a subr (asking instead for a fat comma "-foo => 123" say). > > > > -- > Some people say cricket is like watching grass grow.  That's not true, > International Rules Grass Growing is much more exciting.  Cricket takes > 5 days and ends in a draw, but grass growing is 4 days and sure to have > a winner. > >
Subject: Re: [rt.cpan.org #55749] mis-parse of negation -POSIX::DBL_MAX()
Date: Wed, 02 Mar 2011 11:54:54 +1100
To: bug-PPI [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
Download (untitled) / with headers
text/plain 409b
"Reserved Local Account via RT" <bug-PPI@rt.cpan.org> writes: Show quoted text
> > -FOO::BAR return negation all the time,
Hmm. Might have to dig around in toke.c, but I wonder if there's no difference between colons -FOO::BAR and plain -FOO as far as perl is concerned. In which case it'd be very desirable for PPI to make no difference too -- whichever of the two parses might apply or be adopted in the context etc etc.
Subject: Re: [rt.cpan.org #55749] mis-parse of negation -POSIX::DBL_MAX()
Date: Mon, 30 May 2011 10:41:13 +1000
To: bug-PPI [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
I wrote: Show quoted text
> > toke.c
My understanding now is that foo and foo::bar are treated the same and that -foo or -foo::bar is unary negation and function name when -time function call to perl builtin -foo () function call -foo $obj indirect object method call -foo {$obj} indirect object method call -foo::bar () function call -foo::bar $obj function or method call -foo::bar {$obj} function or method call The program foo.pl below for example, -dashedword is -dashedword -time is -1306715828 -foo() is -123 -foo #comment () is -123 -foo $obj is -999 -foo {$obj} is -999 -foo::bar () is -456 -foo::bar $obj is -456 -foo::bar {$obj} is -456 The {$obj} is a bit obscure but is in perlobj.pod under "Indirect Object Syntax". Allows an expression as the target object apparently. I think the rule would therefore be -foo or -foo::bar is a negation and word if it's a perl builtin func or is followed by (, $ or {. There can be whitespace and comments after the word before the (,$,{.
Download foo.pl
text/x-perl 625b
$x = -dashedword; print "-dashedword is $x\n"; $x = -time; print "-time is $x\n"; print "\n"; $x = -foo(); print "-foo() is $x\n"; $x = -foo # comment (); print "-foo #comment () is $x\n"; my $obj = bless {}, 'Obj'; $x = -foo $obj; print "-foo \$obj is $x\n"; $x = -foo {$obj}; print "-foo {\$obj} is $x\n"; print "\n"; $x = -foo::bar (); print "-foo::bar () is $x\n"; my $obj = bless {}, 'Obj'; $x = -foo::bar $obj; print "-foo::bar \$obj is $x\n"; $x = -foo::bar {$obj}; print "-foo::bar {\$obj} is $x\n"; { package Obj; sub foo { return 999 } } sub foo { return '123'; } sub foo::bar { return '456'; }
Subject: Re: [rt.cpan.org #55749] mis-parse of negation -POSIX::DBL_MAX()
Date: Mon, 30 May 2011 11:06:38 +1000
To: bug-PPI [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
Download (untitled) / with headers
text/plain 247b
Oh, and since the existence of a function foo() can change the parse, below is a bar.pl showing that the cases still parse as calls when there's no function/method existing ... ie. the parse is only from the syntax not what exists at runtime ...
Download bar.pl
text/x-perl 644b
$x = -dashedword; print "-dashedword is $x\n"; $x = -dashed::word; print "-dashed::word is $x\n"; $x = -time; print "-time is $x\n"; print "\n"; $x = eval { -foo() } || $@; print "-foo() is $x\n"; $x = eval { -foo # comment () } || $@; print "-foo #comment () is $x\n"; $obj = bless {}, 'Obj'; $x = eval { -foo $obj } || $@; print "-foo \$obj is $x\n"; $x = eval { -foo {$obj} } || $@; print "-foo {\$obj} is $x\n"; print "\n"; $x = eval { -foo::bar () } || $@; print "-foo::bar () is $x\n"; $x = eval { -foo::bar $obj } || $@; print "-foo::bar \$obj is $x\n"; $x = eval { -foo::bar {$obj} } || $@; print "-foo::bar {\$obj} is $x\n";
This issue is now being tracked on GitHub as https://github.com/adamkennedy/PPI/issues/59


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.