On Mon Nov 28 14:20:53 2011, jdeighan wrote:
Show quoted text> Actually, I got both of these warnings:
>
> Subroutine "f" does not end with "return" at line 19, column 1. See
> page 197 of PBP.
> Literal line breaks in a string at line 21, column 27. See pages 60,61
> of PBP.
>
Thanks. Here is where I think the second one came from.
One of PPI's explicit goals it to be round-trip safe. That is, if you
feed it some Perl, you should be able to get the same Perl back out of it.
So when PPI decided to parse "return'ProposedOverdue.png';" as Perl 4
package name "return'ProposedOverdue", it had to do something with the
unclosed quoted string that this decision created. So it just returned
it as is. Perl::Critic looked at this parse, and generated the spurious
"Literal line breaks" error.
Show quoted text> More importantly, though, when I run the script, the function returns
> the correct value. So, clearly, the PPI parser is NOT doing what the
> actual Perl parser does, so in my opinion, PPI is wrong simply because
> Perl is "right" by definition.
This argument has been made before. The counter-example I had in mind
was 'for $x qw{Larry Moe Curly} {...}', with no parentheses around the
list. Perl never complained about this, until 5.14 when it became
deprecated.
The true situation is that Perl is only right until the Perl maintainers
decide it is wrong.
Show quoted text> I will, of course, always put a space
> after the word 'return' (this came up simply because I made a global
> editing change that ended up creating the problematic construct),
Thank you. And thank you for submitting your report. You found something
interesting, and let us know, which is the right thing to do.
Show quoted text> and
> I will submit a bug report for PPI, though I suspect that they will
> take your point of view, not mine ;-) Thanks.
Well, I confess my opinion that fixing this may take an amount of time
disproportionate to the benefit gained. And it may be impossible to fix
it completely.
It is known that you can not statically parse Perl. That is, you can not
be guaranteed to construct a correct parse of a Perl program simply from
looking at the program.
But this is what PPI tries to do. Usually it does it pretty well. But if
duplicating Perl's parse in this case depends on knowing that the first
element of the offending construct is a subroutine name and what its
prototype (if any) is, than I suspect that duplicating Perl's parse in
all cases may be out of PPI's reach.