On Apr 24, 12:30 pm, Nick Craig-Wood <[EMAIL PROTECTED]> wrote:
>
> Someone normally chimes in with pyparsing at this point...
>


Well it *is* a short pyparsing routine, after all...

-- Someone


tests = """\
("." ".." "cdslib_cleanup.py" "cadence.py"
"cdsinit_cdsenv_cleanup.py")
("." ("cadence.py" "foo_cleanup.py") "cdslib_cleanup.py" "cadence.py"
"cdsinit_cdsenv_cleanup.py") """.splitlines()

import pyparsing as pp

LPAR,RPAR = map(pp.Suppress,"()")
list_ = pp.Forward()
list_ << ( LPAR +
           pp.ZeroOrMore( pp.quotedString | pp.Group(list_) ) +
           RPAR )

for t in tests:
    result = list_.parseString(t)
    print result.asList()

Prints:
['"."', '".."', '"cdslib_cleanup.py"', '"cadence.py"',
'"cdsinit_cdsenv_cleanup.py"']
['"."', ['"cadence.py"', '"foo_cleanup.py"'], '"cdslib_cleanup.py"',
'"cadence.py"', '"cdsinit_cdsenv_cleanup.py"']

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to