-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The comment in  INTERPOLATE is about "subcaptures"... but if you do not
capture the interpolated regex itself, you break that chain.

Am 17.04.2015 um 04:34 schrieb Nathan Gray:
> On Wed, Apr 15, 2015 at 09:45:39PM -0400, Nathan Gray wrote:
>> I had given up on using regexes embedded within regexes, because
>> I could not get capturing to work.
>
> I did a backtrace on one of the test cases that fails, which led
> me to
>
>   src/core/Cursor.pm
>
> in
>
>   method INTERPOLATE(\var, $i = 0, $s = 0, $a = 0)
>
> with this comment:
>
>   # Call it if it is a routine. This will capture if requested.
>   return (var)(self) if nqp::istype(var,Callable);
>
> This seems to indicate that captures in the embedded regexes
> should capture.
>
> When the capture does not happen, is this a bug?
>
> The test cases I came up with, that illustrate capturing from
> embedded regexes (some which work, some which do not), are
> included below.
>
> -kolibrie
>
> use v6;
> use Test;
>
> my $year = '2015';
> my $month = '04';
> my $day = '11';
> my $date_string = "$year-$month-$day";
>
> my $year_regex = rx/$<year>=[\d**4]/;
> my $month_regex = rx/$<month>=[\d\d?]/;
> my $day_regex = rx/$<day>=[\d\d?]/;
> my $separator = rx/'-'/;
>
> # Single named capture.
> {
>     ok($date_string ~~ $year_regex, 'date string matches year regex');
>     is(~$/, $year, 'matched is year string');
>     is(~$/<year>, $year, 'year is captured');
> }
>
> # Single named capture in slashes.
> {
>     ok($date_string ~~ /$year_regex/, 'date string matches year regex
when in slashes');
>     is(~$/, $year, 'matched is year string when in slashes');
>     is(~$/<year>, $year, 'year is captured when in slashes');  # Fails
> }
>
> # Single named capture embedded in named capture.
> {
>     ok($date_string ~~ /$<pattern>=$year_regex/, 'date string matches
year regex when embedded');
>     is(~$/, $year, 'matched is year string when embedded');
>     is(~$/<pattern>, $year, 'pattern is captured when embedded');
>     is(~$/<pattern><year>, $year, 'year is captured when embedded');
> }
>
> # Single named capture embedded in named capture with brackets.
> {
>     ok($date_string ~~ /$<pattern>=[$year_regex]/, 'date string
matches year regex when embedded with brackets');
>     is(~$/, $year, 'matched is year string when embedded with brackets');
>     is(~$/<pattern>, $year, 'pattern is captured when embedded with
brackets');
>     is(~$/<pattern><year>, $year, 'year is captured when embedded with
brackets');  # Fails
> }
>
> # Multiple named captures.
> {
>     ok($date_string ~~ /$year_regex $separator $month_regex $separator
$day_regex/, 'date string matches multiple regexes in slashes');
>     is(~$/, $date_string, 'matched is date string in multi regex with
slashes');
>     is(~$/<year>, $year, 'year is captured in multi regex with
slashes');  # Fails
>     is(~$/<month>, $month, 'month is captured in multi regex with
slashes');  # Fails
>     is(~$/<day>, $day, 'day is captured in multi regex with
slashes');  # Fails
> }
>
> # Multiple named captures embedded in named capture.
> {
>     ok($date_string ~~ /$<pattern>=$year_regex $separator $month_regex
$separator $day_regex/, 'date string matches multiple regexes when
embedded');
>     is(~$/, $date_string, 'matched is date string in multi regex when
embedded');
>     is(~$/<pattern>, $year, 'pattern is captured in multi regex when
embedded');
>     is(~$/<pattern><year>, $year, 'year is captured in multi regex
when embedded');
>     is(~$/<month>, $month, 'month is captured in multi regex when
embedded');  # Fails
>     is(~$/<day>, $day, 'day is captured in multi regex when
embedded');  # Fails
> }
>
> # Multiple named captures embedded in named capture with brackets.
> {
>     ok($date_string ~~ /$<pattern>=[$year_regex $separator
$month_regex $separator $day_regex]/, 'date string matches multiple
regexes when embedded with brackets');
>     is(~$/, $date_string, 'matched is date string in multi regex when
embedded with brackets');
>     is(~$/<pattern>, $date_string, 'pattern is captured in multi regex
when embedded with brackets');
>     is(~$/<pattern><year>, $year, 'year is captured in multi regex
when embedded with brackets');  # Fails
>     is(~$/<pattern><month>, $month, 'month is captured in multi regex
when embedded with brackets');  # Fails
>     is(~$/<pattern><day>, $day, 'day is captured in multi regex when
embedded with brackets');  # Fails
> }
>
>
>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQEcBAEBAgAGBQJVMLqGAAoJEKo+Od/eKQxFiN0IALO/O2XYMEwDabVIxQ41qBk2
npTfOPFCu/QTewHt0/rFh8ujZnx6APt5J+MDXHobB1v0E3ckMdZymsBgPSVFRYfh
XYgkWX0pelyH6Ys0M7oGEHuqZWPLavLXL5EC5gSNagKkwKdytKVlzMH+UPOEZma2
GX3GDpoCeJNuzwrACbrcwxRHYdGkaTgr19d0IyyPsGrtKKUj83yTKlb3GRPgDWUL
7g9uaIAdN87G8qvGGAdabV96gt8M0s8wRlLmKBL06q0uIs0YQvxbBLLhGrmHmX0r
4/Pc1lnS28tUdb6dfURXI3eSyFe7AmUiMnxUInojgsiJ3mQH/hmDrgOMIJTSCDE=
=K+kk
-----END PGP SIGNATURE-----

Reply via email to