On Apr 25, 9:02 pm, Paul McGuire <[EMAIL PROTECTED]> wrote: > 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"']
Oh, you probably don't want those quotation marks in the parsed strings. Change: pp.ZeroOrMore( pp.quotedString | pp.Group(list_) ) + to: pp.ZeroOrMore( pp.quotedString.setParseAction(pp.removeQuotes) | pp.Group(list_) ) + -- Paul -- http://mail.python.org/mailman/listinfo/python-list