Re: [pcre-dev] (*THEN) works differently in Perl

Página superior
Eliminar este mensaje
Autor: ph10
Fecha:  
A: Zoltán Herczeg
Cc: pcre-dev@exim.org, ND
Asunto: Re: [pcre-dev] (*THEN) works differently in Perl
On Tue, 2 Jul 2019, Zoltán Herczeg wrote:

> Perhaps the misunderstanding comes from the fact that we are talking
> about the pattern and they talk about the matching process. So (*THEN)
> simply starts a backtrack, and when an alternation is encountered, it
> switches to the next alternative.


That is indeed what happens in the pcre2_match() interpreter.

> But this happens normally as well, so what is the exact purpose of
> this verb then?


Not quite. (*THEN) suppresses going back to a previous backtrack inside
the branch. In the Perl example

( COND (*THEN) FOO | COND2 (*THEN) BAR | COND3 (*THEN) BAZ )

if COND matches, but FOO fails to match, it does not go back to
backtrack points inside COND (which it would do without (*THEN)), but
instead abandons the entire branch and jumps to try to match COND2. It's
a sort of branch-level (*COMMIT).

At a simple level I suppose it's also equivalent to

((?>COND) FOO | ...

but perhaps there are more complicated examples that can't be written
that way.

Philip

--
Philip Hazel