PPI icon indicating copy to clipboard operation
PPI copied to clipboard

provide delimiters for PPI::Token::QuoteLike::{Words,Regexp,Command}, PPI::Token::Quote::{Literal,Interpolate}

Open FractalBoy opened this issue 4 years ago • 0 comments

When parsing qw, qr, qx, q, and qq strings, it would be nice to be able to get which delimiters are being used. It looks like these are already being stored in {sections}[0]{type}, but not publically available. Ideally, it would always return a two-element array.

For example:

my $doc = PPI::Document->new(\q{my @a = qw(a b c);});
my ($start, $end) = $doc->schild(0)->schild(3)->delimiters();
print "start: $start end: $end\n";
# prints "start: ( end: )"

Here is code that currently works, but seems like it wouldn't be safe to rely on:

my $doc = PPI::Document->new(\q{my @a = qw(a b c);});
my ($start, $end) = split //, $doc->schild(0)->schild(3)->{sections}[0]{type};
print "start: $start end: $end\n";
# prints "start: ( end: )"

FractalBoy avatar Feb 24 '21 03:02 FractalBoy