On Mar 24, 5:39 pm, Peter Waller <peter.wal...@gmail.com> wrote:
> I've since heard that a 'better way' would be to use pyparsing. Also,
> I saw that python has dropped the idea of having recursive regular
> expressions at the moment.

I've written a pyparsing parser which is very much shorter and nicer
than the original parser. I have not yet figured out how to process
the result yet though, I'm having a hard time dealing with the
recursion in my brain. Here it is anyway, in case someone smarter than
me can figure out how to turn the output of this into the relevant
list of expansions.

from pyparsing import (Suppress, Optional, CharsNotIn, Forward,
Group,
                       ZeroOrMore, delimitedList)

lbrack, rbrack = map(Suppress, "{}")

optAnything = Group(Optional(CharsNotIn("{},")))



braceExpr = Forward()

listItem = optAnything ^ Group(braceExpr)

bracketedList = Group(lbrack + delimitedList(listItem) + rbrack)

braceExpr << optAnything + ZeroOrMore(bracketedList + optAnything)



result = braceExpr.parseString(text).asList()
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to