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.