2009/10/28 Dave Rolsky <autarch@urth.org>:
> On Wed, 28 Oct 2009, Zefram wrote:
>
>> Dave Rolsky wrote:
>>>
>>> I've been playing with Regexp::Grammars, and I realized that modifiers
>>> like (?s:) are not carried into a named pattern when recursing.
>>
>> Looks perfectly correct to me. I'd consider it a bug if modifiers
>> from the call site were to affect the behaviour of the called code.
>> Implementing it would also screw up regexp compilation.
>
> It's really not clear what's intended from the docs. Here are the docs for
> the (?:s) modifier:
>
> One or more embedded pattern-match modifiers, to be turned on (or turned
> off, if preceded by "-") for the remainder of the pattern or the
> remainder of the enclosing pattern group (if any).
>
> So what is the definition of "the enclosing pattern group" when the pattern
> group encloses a reference to a named sub-pattern?
>
> It's hardly obviously to me that the named sub-pattern is a separate thing.
Well, the modifiers are effectively lexically scoped pragmatta within
the pattern that change the way that the regex is compiled. This is
broadly comparable to the following code not producing warnings.
{
{
use warnings;
sub X {
Y(@_)
}
}
sub Y {
shift(@_)+1
}
}
X(undef);
And yes it is deliberate. Well, not deliberate in the sense of "an
intended feature of the implementation", it was more a byproduct of
how the implementation works, specifically that named capture buffers
"sit on top" of normal capture buffers, and "gosub" sits on top of
named capture buffers. I think you would be quite surprised if:
((?i)((?-i)X)(Y))
resulted in both X and Y being matched case - sensitively, and this
pattern is analagous to what you have here.
Anyway, a doc patch is certainly welcome if you feel that somehow
things could have been worded better.
cheers,
Yves
--
perl -Mre=debug -e "/just|another|perl|hacker/"
Thread Previous
|
Thread Next