Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Dynamic regex assertions, capturing groups, and parsers: joy and terror

by itub (Priest)
on Oct 03, 2005 at 19:03 UTC ( #497021=note: print w/replies, xml ) Need Help??


in reply to Dynamic regex assertions, capturing groups, and parsers: joy and terror

I once wrote a parser as a huge regex, full of "experimental" features.

I'll never do it again.

I started getting all sorts of weird errors such as segfaults, and they varied wildly between perl versions. I could never find a simple example to reproduce the crash, so I couldn't even file a proper bug report. Also, the huge regex was unmaintainable. Now I'd rather use a parser generator. I'm happy with Parse::YAPP. It's not as trendy as Parse::RecDescent, but it's way faster in my experience.

  • Comment on Re: Dynamic regex assertions, capturing groups, and parsers: joy and terror

Replies are listed 'Best First'.
Re^2: Dynamic regex assertions, capturing groups, and parsers: joy and terror
by diotalevi (Canon) on Oct 03, 2005 at 23:20 UTC

    It might help to remind that you can't run anything using the regex engine while you're inside a (?{...}) or (??{...}) block. You'll usually get segfaults and such if you do that. The engine isn't re-entrant and if you invoke a regex during a regex, you scribble on memory. Its supposed to have gotten better during 5.8 but I haven't tried it again.

      Thanks, that might be what was happening! I was calling subroutines from the ?{} blocks and it is very likely that some of them used regexes internally.
Re^2: Dynamic regex assertions, capturing groups, and parsers: joy and terror
by Aristotle (Chancellor) on Oct 09, 2005 at 12:55 UTC

    A much better alternative that using lots of experimental features to write a single-regex parser is to split the matching across lots of /gc regexes. The resulting code is much easier to follow too, and you don’t need contortions to keep a grip on backtracking (my kingdom for Perl6’s commit!).

    Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2020-06-01 21:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (11 votes). Check out past polls.

    Notices?