PPI
PPI copied to clipboard
lexer confused by 1<<bar()
Using this simple round-tripper:
use PPI; print PPI::Document->new($ARGV[0]), "\n";
the following trivial code fails:
sub foo { 1<<bar(); }
I am guessing it thinks the << is a heredoc, when it should be a bit shift.
The original line was
$num |= (1<<index($D_flags, $_)) for split //, $on;
which comes from this in the standard Devel/Peek.pm:
sub debug_flags (;$) { my $out = ""; for my $i (0 .. length($D_flags)-1) { $out .= substr $D_flags, $i, 1 if $^D & (1<<$i); } my $arg = shift; my $num = $arg; if (defined $arg and $arg =~ /\D/) { die "unknown flags in debug_flags()" if $arg =~ /[^-$D_flags]/; my ($on,$off) = split /-/, "$arg-"; $num = $^D; $num |= (1<<index($D_flags, $)) for split //, $on; $num &= ~(1<<index($D_flags, $)) for split //, $off; } $^D = $num if defined $arg; $out }
I've been investigating a related issue, whereby stringifying the PPI::Document
object (same as calling ->content()
on it) strips out the content of heredocs, giving back an un-parseable document.
See #288 for a full description of the bug I found.
A workaround I've found in the mean time is to call ->serialize()
instead of using the automatic stringification.
To fix your code, replace:
print PPI::Document->new($ARGV[0]), "\n";
with:
print PPI::Document->new($ARGV[0])->serialize;