On Nov 4, 9:56 pm, Paul McGuire <[EMAIL PROTECTED]> wrote: > On Nov 4, 1:34 pm, George Sakkis <[EMAIL PROTECTED]> wrote: > > > > > Is there any package that parses regular expressions and returns an > > AST ? Something like: > > > >>> parse_rx(r'i (love|hate) h(is|er) (cat|dog)s?\s*!+') > > > Regex('i ', Or('love', 'hate'), ' h', Or('is', 'er'), ' ', Or('cat', > > 'dog'), Optional('s'), ZeroOrMore(r'\s'), OneOrMore('!')) > > > Given such a structure, I want to create a generator that can generate > > all strings matched by this regexp. Obviously if the regexp contains a > > '*' or '+' the generator is infinite, and although it can be > > artificially constrained by, say, a maxdepth parameter, for now I'm > > interested in finite regexps only. It shouldn't be too hard to write > > one from scratch but just in case someone has already done it, so much > > the better. > > > George > > Check out this pyparsing regex > inverter:http://pyparsing.wikispaces.com/file/view/invRegex.py >
Neat, seems like a good excuse to look into pyparsing :) Best, George -- http://mail.python.org/mailman/listinfo/python-list