Hi Colin,
Handling of the (?R) construct is problematic, since
the regex engine literally re-executes the entire regex
including the Regexp::Debugger set-up code. It may
be possible to fix that behaviour, but it won't be trivial
and I won't be able to do so in the near future.
For the time being, I recommend avoiding the (?R)
construct if you need to debug using Regexp::Debugger.
For instance, your example could be rewritten:
/(?&AZ) (?(DEFINE) (?<AZ> a (?&AZ)? z ))/x
This is how I write all my non-trivial regexes nowadays:
effectively as a single "call" to a sub-pattern like (?&AZ),
followed by a (?(DEFINE)...) block in which the various
components are defined.
Regexp::Debugger definitely handles that approach correctly.
Indeed, when it comes to fixing the handling of (?R) I will
probably do so by wrapping the entire regex in a single
"call" of this nature.
That is:
/a (?R)? z/x
will first be converted to:
/(?&R) (?(DEFINE) (?<R> a (?&R)? z ))/x
before the debugging code is inserted.
But, as I mentioned before, that's a non-trivial amount of work,
so it will have to wait until I have the spare time to look at it properly.
Thanks for the report, and sorry I can't offer a quicker or simpler
solution.
Damian