Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^5: Regexp not capturing in named subrules

by merlyn (Sage)
on Sep 16, 2009 at 18:29 UTC ( [id://795691]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Regexp not capturing in named subrules
in thread Regexp not capturing in named subrules

The grammar section (?: ... ){0} creates the subroutines...
I'm really confused. Did you invent that construct yourself (which looks broken to me) or is it something special-cased in recent grammars (away from its pointless purpose) and recommended in some document I haven't read yet?

Because if I was writing a regex engine, I'd actually turn {0} into a fatal error, with the invoker needing a clue-bat.

-- Randal L. Schwartz, Perl hacker

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

Replies are listed 'Best First'.
Re^6: Regexp not capturing in named subrules
by diotalevi (Canon) on Sep 16, 2009 at 18:36 UTC

    I read the idea (?<name>...){0} in the Oniguruma documentation but it was applicable to Perl too. In Perl-5.10 implementation, (?:...){0} leaves active elements like regexp routines handy in the regexp. Really, that seems to work just fine. Anyway, it's pretty clear I'm likely doing something Yves never intended when he added (?&name) support.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      I think the way God Intended patterns to be defined for later use is

      qr/(?(DEFINE) (?<name>pattern) )/x

        Oh, hey. I didn't find that earlier because it seems to be misfiled under the (?(condition)yes-pattern|no-pattern) section but it goes on to answer my original question

        From perlre:

        /(?<NAME>(?&NAME_PAT)) (?(DEFINE) (?<NAME_PAT>....) )/x

        Note that capture buffers matched inside of recursion are not accessible after the recursion returns, so the extra layer of capturing buffers is necessary. Thus $+{NAME_PAT} would not be defined even though $+{NAME} would be.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://795691]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-03-29 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found