A better search term might be "regular expression grammar" since a
grammar is what a regular expression parser would require.

Here's one I just found for Perl regexes:
http://www.cs.sfu.ca/~cameron/Teaching/384/99-3/regexp-plg.html
via http://stackoverflow.com/questions/265457/regex-grammar

If I were you I'd use the Perl one as a starting point for writing a
Treetop grammar for Ruby regexes. Or ask around on the Treetop list
and see if someone's already done that.

https://github.com/nathansobo/treetop
http://thingsaaronmade.com/blog/a-quick-intro-to-writing-a-parser-using-tre=
etop.html
http://groups.google.com/group/treetop-dev


On Thu, Feb 16, 2012 at 9:53 AM, Brian Candler <b.candler / pobox.com> wrote:
> Is there some existing code (preferably ruby) which can take a regular
> expression and
> build a parse tree from it? e.g. I want to turn
>
> "^(foo|(bar|baz)*|qux)$"
>
> into something like this:
>
> =A0 =A0 <seq>
> =A0 =A0/ =A0| =A0\
> <bol> =A0| =A0 <eol>
> =A0 =A0 <alt>
> =A0 / =A0 | =A0 \
> foo =A0 <*> =A0 qux
> =A0 =A0 =A0 |
> =A0 =A0 <alt>
> =A0 =A0 / =A0 \
> =A0 bar =A0 baz
>
> or some equivalent representation of the regular expression itself.
>
> (The trouble is, when you google for 'ruby regular expression parser'
> you get all sorts of parsers written *using* regular expressions, not
> parsers *for* regular expressions!)
>
> Thanks,
>
> Brian.
>
> --
> Posted via http://www.ruby-forum.com/.
>



--=20
Alex Chaffee - alex / stinky.com
http://alexchaffee.com
http://twitter.com/alexch