This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
first step cleaning up regexp recursion "return" logic
authorYves Orton <demerphq@gmail.com>
Sat, 5 Mar 2016 19:40:36 +0000 (20:40 +0100)
committerYves Orton <demerphq@gmail.com>
Sun, 6 Mar 2016 13:02:14 +0000 (14:02 +0100)
commit24be310237a0f8f19cfdb71de1b068b4ce9572a0
tree39f3536dbc2c898f0535b3f3a34dc5cf926d7490
parent4b63804857c9bd58e6f67f23b9a9d007fa7c1071
first step cleaning up regexp recursion "return" logic

When we do a GOSUB/GOSTART we need to know where the recursion
"returns" to the previous position in the pattern. Currently
this is done by comparing cur_eval->u.eval.close_paren to the
the argument of CLOSE parens, and within END blocks (for GOSTART).

However, there is a problem. The state machinery for GOSUB/GOSTART
is shared with EVAL ( implementing /(??{ ... })/ ), which also sets
cur_eval->u.eval.close_paren to 0. This for instance breaks /(?(R)YES|NO)/
by making it return true within a /(??{ ... })/ when arguably it
shouldn't. It also is confusing.

So we change the meaning of close_paren so that 0 means "from EVAL",
and that otherwise the value is "+1", so 1 means GOSTART (trigger for
END), and 2 means "CLOSE1", etc. In order to make this transparent
this patch adds the EVAL_CLOSE_PAREN_IS( cur_eval, EXPR ) macro which
does the right thing:

    ( cur_eval && cur_eval->u.eval.close_paren &&
      ( ( cur_eval->u.eval.close_paren - 1 ) == EXPR ) )
regcomp.c
regexec.c
regexp.h