develooper Front page | perl.perl5.porters | Postings from July 2016

Re: RFC: seeking syntax for allowing script run pattern matching

Thread Previous | Thread Next
July 7, 2016 08:28
Re: RFC: seeking syntax for allowing script run pattern matching
Message ID: writes:

> Zefram <> wrote:
> : wrote:
> : 
> : >                                                we have exactly
> : > that concept with the flags and /(?f:...)/ construct.
> : 
> : It doesn't make sense as a flag in this way.  The existing flags
> : affect the interpretation of individual regexp elements, so turning
> : them on and off locally has obvious semantics.  But the script-run
> : feature affects the meaning of a whole group.
> Hmm, I mostly see your point, but I also expect the commonest desire
> will be to apply a single sr to a whole pattern.

So maybe we'll eventually need both. But we could go with adding
in-regexp syntax such as (*sr:...) first, then if it turns out that a
common use of it is to wrap all the rest of the pattern in it, and if
doing that feels awkwardly verbose, a flag could be added which does
that for you.

Another common case may be that you want each ‘word’ only to use a
single script, but you're OK with different words using different

It'd be great if we could come up with some real-world places where
users would use this feature, so we can see how they would look in
any proposed syntaxes.

> I had assumed /(*sr: \w+ x \w+ )/x would require two words sharing a
> common script separated by a literal x. Are you expecting rather that
> it would require the literal x also to be part of the common script?

What about if it were:

  my $foo = 'x';
  /(*sr: \w+ $foo \w+ )/x

In that case I think it'd be reasonable to want the \w+-s to be in the
same script as the interpolated text. But it'd be surprising if merely
abstracting some constant text from a pattern in to a variable changed
what it matched.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About