in reply to Altering regular expression trees

While Perl's regular expressions are generally hard to access and modify on the level you require, the Parse::RecDescent module can probably do the job you require pretty well. You can produce a parse tree with P::RD and then evaluate it, skipping the nodes you need to avoid. You can also have actions associated with "good" nodes that execute them, and actions associated with "bad" nodes that print a warning, die, whatever is appropriate. In P::RD nodes are called "rules" and you should be able to pick up basic usage of the module in just a few minutes. It is possible to actually modify rules while the parser is running, but chances are you'll be happy with a parse tree.

Replies are listed 'Best First'.
Re: Re: Altering regular expression trees
by benizi (Hermit) on Jul 31, 2003 at 16:25 UTC
    While I've found P::RD to be very cool and useful in the past (parsing an old machine-readable dictionary with embedded type-setting codes), I've never used it for anything as complicated as perl regular expressions. I'd imagine that would be a non-trivial task.

    For now, I'm going with japhy's YAPE::Regex, as suggested by diotalevi. I like the design, and it allows you to do most of the things tzz describes above, without having to create a regular expression grammar.

      Actually, that's the point. YAPE::Regex has a grammar in it. You'd just be reimplementing Y::R if you wrote your own grammar.

      I was unclear. I didn't mean you should try to parse generic Perl regular expressions with P::RD, but instead that you can give your users a simpler syntax that they may like better. Your original message implied you don't need exact compatibility with the Perl regex syntax. With P::RD you can design a syntax that matches what the users need, rather than trying to teach them Perl regular expressions. I've found the latter to be a difficult battle for most users.