From: Alex Chaffee Date: 2012-02-17T03:11:51+09:00 Subject: Re: Any parser *for* regular expressions? 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-treetop.html http://groups.google.com/group/treetop-dev On Thu, Feb 16, 2012 at 9:53 AM, Brian Candler 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: > >     >    /  |  \ >  |   >     >   /   |   \ > foo   <*>   qux >       | >     >     /   \ >   bar   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/. > -- Alex Chaffee - alex@stinky.com http://alexchaffee.com http://twitter.com/alexch