develooper Front page | perl.perl5.porters | Postings from September 2011

[perl #92898] (*THEN) broken inside condition subpattern

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
September 21, 2011 12:28
Subject:
[perl #92898] (*THEN) broken inside condition subpattern
Message ID:
rt-3.6.HEAD-31297-1316633332-1481.92898-15-0@perl.org
On Wed Sep 21 12:04:45 2011, ph10@hermes.cam.ac.uk wrote:
> On Wed, 21 Sep 2011, Father Chrysostomos via RT wrote:
> > Oddly, I don’t find that counterintuitive at all.  Do we need three
> > versions of prune/then?
> 
> Aha! One person's intuition is always another's totally craziness. :-)
> I wonder what the percentages each way would be if we surveyed the
> general Perl-using population? At least one other person thinks as I 
> do, because it was a bug report for PCRE - which was behaving more like 
> Perl - that got me into this issue in the first place. 
> 
> Is there a forum where we could ask the following question?
> 
>    Folks, consider the pattern ^A(B(*THEN)C), where A, B, and C are 
>    complex patterns. If matching fails in C, do you expect that
>    (a) the entire match should fail, or
>    (b) the matching should backtrack into A?  
> 
> I will ask this question on the pcre-dev mailing list and see what 
> answers (if any) I get. I might try Jeffrey Friedl as well. I will not 
> be in the least offended if I am "outvoted".
> 
> It seems that you intuitively think that a group without a | is a
> different kind of animal to a group that contains a |, whereas I don't.
> I just think that a group without a | has "one alternative", maybe
> better expressed as "one branch" (since "alternative" implies at least
> one of two).
> 
> I can, however, understand your logic; I have to say that to me it seems
> rather mathematically pedantic (with respect :-).
> 
> I'd rather not created yet another version of prune/then! I *thought* I 
> understood these verbs. It seemed to me that they provide different 
> "strengths" of pruning when backtracked onto, as follows (from weakest 
> to strongest):

Come to think of it, we already have your version of (*THEN), as
(?>...). I know I’m just repeating what you said by that. But it has
just occurred to me that it belongs at the top of this list.

So your ^A(B(*THEN)C) translates into ^A((?>B)C).

My understanding of (*THEN) (and perl’s implementation), would be

  [?>^A(B]C)

where I’m using [?>...], as it doesn’t nest.  So the latter meaning
seems more useful, as there is no other way to get it.

> *THEN fails the current alternation branch, and restarts at the next
> alternation in the current group, or fails the whole group if there are
> no more alternatives.
> 
> *PRUNE fails the current match, but allows an advance to the next 
> starting position (unless anchored).
> 
> *SKIP is like *PRUNE, but can skip forward more than one character.
> 
> *COMMIT fails the entire matching process, not allowing any further 
> advance in the subject.
> 
> That's fairly straightforward; the issue between us is what constitutes 
> "the current group". Having two verbs (one for me, one for you) is just 
> a recipe for even more confusion.
> 
> Regards,
> Philip




Thread Previous | Thread Next


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