Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lexer confused by 1<<bar() #183

Open
jhi opened this issue Nov 23, 2015 · 1 comment
Open

lexer confused by 1<<bar() #183

jhi opened this issue Nov 23, 2015 · 1 comment

Comments

@jhi
Copy link

jhi commented Nov 23, 2015

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
}

@h3xx
Copy link
Contributor

h3xx commented Aug 23, 2023

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants