On 2 August 2010 00:54, karl williamson <public@khwilliamson.com> wrote: > Ben Morrow wrote: >> >> Quoth public@khwilliamson.com (karl williamson): >>> >>> Ben Morrow wrote: >>>> >>>> Quoth public@khwilliamson.com (karl williamson): >>>>> >>>>> But there must be some reason that xism are always shown in the >>>>> stringification, whether they are in effect or not in effect. But I can't >>>>> think what it might be. It would have been simpler for the original design >>>>> to only output them in the stringification when different from the default. >>>>> So there must be a reason why the plus or minus of them is always output. >>>>> Does that reason apply to these new modifiers? >>>> >>>> The reason is so that interpolation under different flags works >>>> properly. Currently, if I have >>>> >>>> my $rx = qr/f./s; >>>> >>>> is stringifies to (?s-xim:f.), which means that when I interpolate it >>>> into a pattern with different flags >>>> >>>> "AFx" =~ /a$rx/i; >>>> >>>> the /i is 'cancelled' for the duration of the interpolation (and /s >>>> activated). If it were changed to stringify to (?s:f.) only, the match >>>> above would change from failing to passing. >>> >>> I still don't understand. I had considered interpolation, and it still >>> seems to me that the absence of a modifier means use the underlying default >>> for the duration of that interpolation, no matter what the outer regex says. >>> I don't see a flaw in that thinking. >> >> Um, it's not what actually happens :)? >> >> ~/src/perl% perl -E'say "F" =~ /(?s:f)/i' >> 1 >> ~/src/perl% perl -E'say "F" =~ /(?s-ixm:f)/i' >> >> ~/src/perl% >> >> Complete absence of a modifier means 'leave this modifier as it was >> outside this group'. I don't think that can (or should) be changed now. >> >> As Avar said, this could potentially be changed for the simple case of >> direct interpolation, by looking up the flags on the interpolated regex >> directly. However, a lot of code assumes it can stringify a qr//, write >> it to a file/pass it across the network/whatever, and re-qr// to get an >> equivalent pattern back. >> >> My alternative suggestion was to introduce a new grouping construct, >> which I tentatively called (?~sixm:) (I don't much like that, but there >> aren't many alternatives at this point), which *does* do what you >> expect; and use that for stringification instead. That way we change the >> stringification once, now, and then never again. >> >> Ben >> > > I think I like your idea. Let me make sure I understand. A tilde > immediately following '(?' means that the clustering group is to have the > default modifiers, subject to any flags that come after it. Thus (?~:abc) > means all default flags. (?~x:abc) means the defaults except use the x > modifier, and (?~-x:abc) means the defaults without the x modifier, which is > a somewhat more complicated way of writing the equivalent (?~:abc). > > regex stringification could change to output just the non-defaults, or we > could leave them as-is, and just add the tilde. Since we would already be > breaking compatibility, I would think we might as well remove them. > > A tilde is not the ideal choice because it can easily be confused with a > minus sign. I don't know if there are other characters that could be used > instead. Can you paint a picture for me as to how you think this is useful and would work in practice? What problem it solves? Right now I would vote against this idea in terms of minimal benefit for long term costs, so maybe I don't understand the point properly. Top of my mind questions: How do you define "the default modifiers"? Assume we have them, and they end up user configurable, what happens when a regex is compiled in one context and the interpolated in another? What is the difference between /(?~i:foo)/ and /(?i)foo/ cheers Yves -- perl -Mre=debug -e "/just|another|perl|hacker/"Thread Previous | Thread Next