develooper Front page | perl.perl5.porters | Postings from June 2013

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

Thread Previous | Thread Next
From:
ph10
Date:
June 23, 2013 14:51
Subject:
Re: [perl #92898] (*THEN) broken inside condition subpattern
Message ID:
alpine.LNX.2.03.1306231541330.17457@hermes.cam.ac.uk
On Sun, 23 Jun 2013, demerphq wrote:

> Cool. I will try to find time to read the PCRE docs and look for
> discrepancies and investigate.

This is perhaps the relevant section of the "pcrepattern" man page:

-----------------------------------------------------------------------
   More than one backtracking verb

       If  more  than  one  backtracking verb is present in a pattern, the one
       that is backtracked onto first acts. For example,  consider  this  pat-
       tern, where A, B, etc. are complex pattern fragments:

         (A(*COMMIT)B(*THEN)C|ABD)

       If  A matches but B fails, the backtrack to (*COMMIT) causes the entire
       match to fail. However, if A and B match, but C fails, the backtrack to
       (*THEN)  causes  the next alternative (ABD) to be tried. This behaviour
       is consistent, but is not always the same as Perl's. It means  that  if
       two  or  more backtracking verbs appear in succession, all the the last
       of them has no effect. Consider this example:

         ...(*COMMIT)(*PRUNE)...

       If there is a matching failure to the right, backtracking onto (*PRUNE)
       causes it to be triggered, and its action is taken. There can never be
       a backtrack onto (*COMMIT).

   Backtracking verbs in repeated groups

       PCRE differs from  Perl  in  its  handling  of  backtracking  verbs  in
       repeated groups. For example, consider:

         /(a(*COMMIT)b)+ac/

       If  the  subject  is  "abac",  Perl matches, but PCRE fails because the
       (*COMMIT) in the second repeat of the group acts.

   Backtracking verbs in assertions

       (*FAIL) in an assertion has its normal effect: it forces  an  immediate
       backtrack.

       (*ACCEPT) in a positive assertion causes the assertion to succeed with-
       out any further processing. In a negative assertion,  (*ACCEPT)  causes
       the assertion to fail without any further processing.

       The  other  backtracking verbs are not treated specially if they appear
       in a positive assertion. In  particular,  (*THEN)  skips  to  the  next
       alternative  in  the  innermost  enclosing group that has alternations,
       whether or not this is within the assertion.

       Negative assertions are, however, different, in order  to  ensure  that
       changing  a  positive  assertion  into a negative assertion changes its
       result. Backtracking into (*COMMIT), (*SKIP), or (*PRUNE) causes a neg-
       ative assertion to be true, without considering any further alternative
       branches in the assertion.  Backtracking into (*THEN) causes it to skip
       to  the next enclosing alternative within the assertion (the normal be-
       haviour), but if the assertion  does  not  have  such  an  alternative,
       (*THEN) behaves like (*PRUNE).

   Backtracking verbs in subroutines

       These  behaviours  occur whether or not the subpattern is called recur-
       sively.  Perl's treatment of subroutines is different in some cases.

       (*FAIL) in a subpattern called as a subroutine has its  normal  effect:
       it forces an immediate backtrack.

       (*ACCEPT)  in a subpattern called as a subroutine causes the subroutine
       match to succeed without any further processing. Matching then  contin-
       ues after the subroutine call.

       (*COMMIT), (*SKIP), and (*PRUNE) in a subpattern called as a subroutine
       cause the subroutine match to fail.

       (*THEN) skips to the next alternative in the innermost enclosing  group
       within  the subpattern that has alternatives. If there is no such group
       within the subpattern, (*THEN) causes the subroutine match to fail.
-----------------------------------------------------------------------

Regards,
Philip

-- 
Philip Hazel

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