Keep It Simple, Stupid | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Regular expressions are not parsers.
A regular expression can refer to itself, but that is a kludgy hack. To do that use the ??{ } form inside a regex. There are better solutions though. If you want to clean up your perl code, perltidy helps. If you want to do custom transformations, PPI is well suited for the job. Larry Wall is working on the perl 5 to perl 6 converter, and he's using the parsing code from perl 5 itself to emit a canonical format... When he makes a release that might be useful. If you want to parse it on your own, try looking at Parse::RecDescent. Back to your problem - since perl's grammar is recursive: (... ( sub expression ) ...) you have to keep track of parenthesis balancing. You need to use some kind of stack structure (an explicit one or the call stack) to nibble paren tokens, and construct nested subexpressions. Once you can build that much you need to reserialize your structures back. Since you are only going two levels deep, this will be a problem soon. You can use regexes to find tokens, but the notion of state must be maintained, and this is not taken into account in your code. Your subroutine regex is the problem there, btw. It doesn't match a closing paren, so the collected string ends in "WebGUIProfile", and stops there. A hard coded paren for the method call is printed, and that's where it ends.
-nuffin zz zZ Z Z #!perl In reply to Re: Nesting regexen
by nothingmuch
|
|