I hadn't been able to get the alternative parser to work - probably down
to the lack of () and {} support. So your improvements to the parser will
certainly help.
I've attached a patch to improve the parser still further, adding <> and
[] as pairs of quote characters, and using Text::Balanced to parse any
bracketed quotes. This allows, for example:
qURL[
http://example.com/geo?coord[0]=1&coord[1]=30];
to work. Note the square brackets used within the URL itself! This is
similar to how Perl's built-in quote characters work.
--- /usr/lib/perl5/site_perl/5.10.1/PerlX/QuoteOperator.orig 2011-12-01 04:58:28.029617064 +0000
+++ /usr/lib/perl5/site_perl/5.10.1/PerlX/QuoteOperator.pm 2011-12-01 05:23:24.224367869 +0000
@@ -4,6 +4,7 @@
use 5.008001;
use Devel::Declare ();
+use Text::Balanced ();
use base 'Devel::Declare::Context::Simple';
our $VERSION = '0.03';
@@ -54,9 +55,18 @@
if ( $self->{ $parser } ) {
# find start & end of quote operator
- my $pos = $self->offset; # position just after "http"
- my $delim = _closing_delim( substr( $line, $pos, 1 ) );
- do { $pos++ } until substr( $line, $pos, 1 ) eq $delim;
+ my $pos = $self->offset; # position just after "http"
+ my $opener = substr( $line, $pos, 1 );
+ my $closer = _closing_delim( $opener );
+ if ($closer eq $opener) {
+ do { $pos++ } until substr( $line, $pos, 1 ) eq $closer;
+ }
+ else {
+ my $text = substr($line, $pos);
+ my ($capture, $remaining) = Text::Balanced::extract_bracketed($text, $opener);
+ $pos += length $capture;
+ $pos--;
+ }
# and wrap sub() around quote operator (needed for lists)
substr( $line, $pos + 1, 0 ) = ')';
@@ -80,6 +90,8 @@
my $d = shift;
return ')' if $d eq '(';
return '}' if $d eq '{';
+ return ']' if $d eq '[';
+ return '>' if $d eq '<';
return $d;
}
@@ -92,11 +104,6 @@
PerlX::QuoteOperator - Create new quote-like operators in Perl
-=head1 VERSION
-
-Version 0.02
-
-
=head1 SYNOPSIS
Create a quote-like operator which convert text to uppercase: