Hi Yary,

I ran your Raku code in a script (on MacOS) and in the REPL (MacOS with
Linenoise). All results below with Rakudo_2020.10:

#Script:

my $word = /(\w+)/;
my $AwithB = /$word' with '$word/;
$_= 'Interpolating regexes with arbitrary captures is fun!';
say "Nested rx";
dd m/$AwithB.*'is '$word/;

say "shallow rx";
dd m/$word' with '$word.*'is '$word/;

say "no interpolation";
dd m/(\w+)' with '(\w+).*'is '(\w+)/;

#Script Result:

admin@mbook:~$ raku yary_named.p6
Nested rx
Match $/ = Match.new(:orig("Interpolating regexes with arbitrary captures
is fun!"), :from(14), :pos(52))
shallow rx
Match $/ = Match.new(:orig("Interpolating regexes with arbitrary captures
is fun!"), :from(14), :pos(52))
no interpolation
Match $/ = Match.new(:orig("Interpolating regexes with arbitrary captures
is fun!"), :from(14), :pos(52), :list((Match.new(:orig("Interpolating
regexes with arbitrary captures is fun!"), :from(14), :pos(21)),
Match.new(:orig("Interpolating regexes with arbitrary captures is fun!"),
:from(27), :pos(36)), Match.new(:orig("Interpolating regexes with arbitrary
captures is fun!"), :from(49), :pos(52)))))

REPL:

admin@mbook:~$ raku
Welcome to ๐‘๐š๐ค๐ฎ๐๐จโ„ข v2020.10.
Implementing the ๐‘๐š๐ค๐ฎโ„ข programming language v6.d.
Built on MoarVM version 2020.10.

To exit type 'exit' or '^D'
> my $word = /(\w+)/;
/(\w+)/
> my $AwithB = /$word' with '$word/;
Regex object coerced to string (please use .gist or .raku to do that)
  in any metachar at /Users/admin/rakudo/rakudo-
2020.10/install/share/nqp/lib/NQPP6QRegex.moarvm line 1
  in any termseq at /Users/admin/rakudo/rakudo-
2020.10/install/share/nqp/lib/NQPP6QRegex.moarvm line 1
  in any quote:sym</ /> at /Users/admin/rakudo/rakudo-
2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm line 1
  in any quote at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any value:sym<quote> at /Users/admin/rakudo/rakudo-
2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm line 1
  in any value at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any term:sym<value> at /Users/admin/rakudo/rakudo-
2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm line 1
  in any term at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1

Regex object coerced to string (please use .gist or .raku to do that)
  in any metachar at /Users/admin/rakudo/rakudo-
2020.10/install/share/nqp/lib/NQPP6QRegex.moarvm line 1
  in any termseq at /Users/admin/rakudo/rakudo-
2020.10/install/share/nqp/lib/NQPP6QRegex.moarvm line 1
  in any quote:sym</ /> at /Users/admin/rakudo/rakudo-
2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm line 1
  in any quote at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any value:sym<quote> at /Users/admin/rakudo/rakudo-
2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm line 1
  in any value at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any term:sym<value> at /Users/admin/rakudo/rakudo-
2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm line 1
  in any term at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1

> $_= 'Interpolating regexes with arbitrary captures is fun!';
Interpolating regexes with arbitrary captures is fun!
> say "Nested rx";
Nested rx
> dd m/$AwithB.*'is '$word/;
Regex object coerced to string (please use .gist or .raku to do that)
  in any metachar at /Users/admin/rakudo/rakudo-
2020.10/install/share/nqp/lib/NQPP6QRegex.moarvm line 1
  in any termseq at /Users/admin/rakudo/rakudo-
2020.10/install/share/nqp/lib/NQPP6QRegex.moarvm line 1
  in any quote at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any value:sym<quote> at /Users/admin/rakudo/rakudo-
2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm line 1
  in any value at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any term:sym<value> at /Users/admin/rakudo/rakudo-
2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm line 1
  in any term at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1

Regex object coerced to string (please use .gist or .raku to do that)
  in any metachar at /Users/admin/rakudo/rakudo-
2020.10/install/share/nqp/lib/NQPP6QRegex.moarvm line 1
  in any termseq at /Users/admin/rakudo/rakudo-
2020.10/install/share/nqp/lib/NQPP6QRegex.moarvm line 1
  in any quote at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any value:sym<quote> at /Users/admin/rakudo/rakudo-
2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm line 1
  in any value at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any term:sym<value> at /Users/admin/rakudo/rakudo-
2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm line 1
  in any term at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1

Match $/ = Match.new(:orig("Interpolating regexes with arbitrary captures
is fun!"), :from(0), :pos(49))
>
> say "shallow rx";
shallow rx
> dd m/$word' with '$word.*'is '$word/;
Regex object coerced to string (please use .gist or .raku to do that)
  in any metachar at /Users/admin/rakudo/rakudo-
2020.10/install/share/nqp/lib/NQPP6QRegex.moarvm line 1
  in any termseq at /Users/admin/rakudo/rakudo-
2020.10/install/share/nqp/lib/NQPP6QRegex.moarvm line 1
  in any quote at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any value:sym<quote> at /Users/admin/rakudo/rakudo-
2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm line 1
  in any value at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any term:sym<value> at /Users/admin/rakudo/rakudo-
2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm line 1
  in any term at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1

Regex object coerced to string (please use .gist or .raku to do that)
  in any metachar at /Users/admin/rakudo/rakudo-
2020.10/install/share/nqp/lib/NQPP6QRegex.moarvm line 1
  in any termseq at /Users/admin/rakudo/rakudo-
2020.10/install/share/nqp/lib/NQPP6QRegex.moarvm line 1
  in any quote at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any value:sym<quote> at /Users/admin/rakudo/rakudo-
2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm line 1
  in any value at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any term:sym<value> at /Users/admin/rakudo/rakudo-
2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm line 1
  in any term at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1

Regex object coerced to string (please use .gist or .raku to do that)
  in any metachar at /Users/admin/rakudo/rakudo-
2020.10/install/share/nqp/lib/NQPP6QRegex.moarvm line 1
  in any termseq at /Users/admin/rakudo/rakudo-
2020.10/install/share/nqp/lib/NQPP6QRegex.moarvm line 1
  in any quote at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any value:sym<quote> at /Users/admin/rakudo/rakudo-
2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm line 1
  in any value at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1
  in any term:sym<value> at /Users/admin/rakudo/rakudo-
2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm line 1
  in any term at
/Users/admin/rakudo/rakudo-2020.10/install/share/perl6/lib/Perl6/Grammar.moarvm
line 1

Match $/ = Match.new(:orig("Interpolating regexes with arbitrary captures
is fun!"), :from(21), :pos(49))
> say "no interpolation";
no interpolation
> dd m/(\w+)' with '(\w+).*'is '(\w+)/;
Match $/ = Match.new(:orig("Interpolating regexes with arbitrary captures
is fun!"), :from(14), :pos(52), :list((Match.new(:orig("Interpolating
regexes with arbitrary captures is fun!"), :from(14), :pos(21)),
Match.new(:orig("Interpolating regexes with arbitrary captures is fun!"),
:from(27), :pos(36)), Match.new(:orig("Interpolating regexes with arbitrary
captures is fun!"), :from(49), :pos(52)))))
Nil
>

Best Regards, Bill.


On Fri, Mar 19, 2021 at 11:12 AM yary <not....@gmail.com> wrote:

> My current expectations are a little different than any others previously
> expressed and I don't know how to get the result. I am no longer
> considering named captures from Regex's interpolated inside <angle
> brackets> and am now looking at directly interpolating them.
>
> Perl example:
>
> DB<1> *$word = qr/(\w+)/;*
>
>
> DB<2> *$AwithB = qr/$word with $word/*
>
>
> DB<3> *$_ = 'Interpolating regexes with arbitrary captures is fun!'*
>
>
> DB<4> *x /$AwithB.*is $word/*
>
>
> 0  'regexes'
>
> 1  'arbitrary'
>
> 2  'fun'
>
> That was simple and I like the results of the capture groups being
> first-level.
>
> Raku example:
>
> my $word = /(\w+)/;
> my $AwithB = /$word' with '$word/;
> $_= 'Interpolating regexes with arbitrary captures is fun!';
> say "Nested rx";
> dd m/$AwithB.*'is '$word/;
>
> say "shallow rx";
> dd m/$word' with '$word.*'is '$word/;
>
> say "no interpolation";
> dd m/(\w+)' with '(\w+).*'is '(\w+)/;
> # code end results below
>
> Nested rx
>
> Match $/ = Match.new(:orig("Interpolating regexes with arbitrary captures
> is fun!"), :from(14), :pos(52))
>
> shallow rx
>
> Match $/ = Match.new(:orig("Interpolating regexes with arbitrary captures
> is fun!"), :from(14), :pos(52))
>
> no interpolation
>
> Match $/ = Match.new(:orig("Interpolating regexes with arbitrary captures
> is fun!"), :from(14), :pos(52), :list((Match.new(:orig("Interpolating
> regexes with arbitrary captures is fun!"), :from(14), :pos(21)),
> Match.new(:orig("Interpolating regexes with arbitrary captures is fun!"),
> :from(27), :pos(36)), Match.new(:orig("Interpolating regexes with arbitrary
> captures is fun!"), :from(49), :pos(52)))))
>
> Run against
>
> Welcome to ๐‘๐š๐ค๐ฎ๐๐จโ„ข v2021.02.1.
>
> Implementing the ๐‘๐š๐ค๐ฎโ„ข programming language v6.d.
>
> Built on MoarVM version 2021.02.
>
> What I see from that example code is Raku matching all the regex's as I
> expect regardless of nesting them, all without the named capture grouping
> angle-brackets. Which is what the documentation suggests from its example-
>
> my $string   = 'Is this a regex or a string: 123\w+False$pattern1 ?';
> my $regex    = /\w+/;
> say $string.match: / $regex /;                        #  [4] OUTPUT: ยซ๏ฝขIs๏ฝฃโคยป
>
> Where my expectation differs from the behavior in my example is Raku's
> discarding the capture groups of the interpolated regexes. The overall
> match works, in all cases :from(14) to :pos(52), but Raku treats the
> groupings inside the interpolations as non-capturing.
>
> -y
>
>
> On Thu, Mar 18, 2021 at 6:08 PM Ralph Mellor <ralphdjmel...@gmail.com>
> wrote:
>
>> On Thu, Mar 18, 2021 at 12:59 AM yary <not....@gmail.com> wrote:
>> >
>> > As it is I get same kinds of errors in the REPL, perhaps it is MacOS
>> > with Linenoise that's mucking that up.
>>
>> I can confirm your new test code also works fine in both program
>> and repl forms in 2020.12.
>>
>> Though obviously the case you mark as "interesting" still doesn't do
>> any sub-capturing. Which is to be expected if you know that aspect
>> of Raku's regex language.
>>
>> > I had hoped that by directly interpolating $rd and $rw they would
>> > fill in the top-level match object and fill in $0, $1 โ€“ but it has the
>> > same issue as Joe's original example.
>>
>> Are you just saying that your original expectations were the same
>> as Joe's, but you now understand that's not how Raku regexes
>> work, but it's trivial to get the same result? Or are you saying you
>> don't know how to get the same result?
>>
>> --
>> love, raiph
>>
>

Reply via email to