develooper Front page | perl.perl6.users | Postings from June 2020

Re: Code assertions to spy on regexps behavior

Thread Previous
From:
Joseph Brenner
Date:
June 17, 2020 19:42
Subject:
Re: Code assertions to spy on regexps behavior
Message ID:
CAFfgvXVJC=Gc60MCp1m1z8V8FOPWg0d9ZHjpYksFFBcWohPMwg@mail.gmail.com
> It doesn't have to be an assertion. Just a code block would do the same.

Yes, good point.

In the docs, in the section Regex Interpolation, they don't mention
that feature, presumably because it literally does no interpolation,
but I'd argue that the null case is worth including in  this table:

  Syntax 	Description
  $variable 	Interpolates stringified contents of variable literally.
  $(code) 	Runs Raku code inside the regex, and interpolates the
stringified return value literally.
  <$variable> 	Interpolates stringified contents of variable as a regex.
  <{code}> 	Runs Raku code inside the regex, and interpolates the
stringified return value as a regex.

Notably, it is included in Table 4-3 in the Moritz Lenz book "Parsing
with Perl 6 Regexes and Grammars":

  { CODE }     Runs Perl 6 code; no effect on regex match



On 6/14/20, Vadim Belman <vrurg@lflat.org> wrote:
> It doesn't have to be an assertion. Just a code block would do the same.
>
> Best regards,
> Vadim Belman
>
>> On Jun 14, 2020, at 8:55 PM, Joseph Brenner <doomvox@gmail.com> wrote:
>>
>> $_ = "Alpha beta gamma";
>>  my @matches = m:g/(a) <?{ put $0.pos }>/;
>
>

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About