Perl-Critic / PPI

54 stars 44 forks source link

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

Open FractalBoy opened 3 years ago

FractalBoy commented 3 years ago

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: )"