Re: [Pyparsing] recursion in _flatten after version 1.5.2
Brought to you by:
ptmcg
From: Paul M. <pt...@au...> - 2011-05-31 03:46:39
|
Luke - I tripped over this same bug doing HTML tag stripping. The latest pyparsing in SVN has a version of _flatten that uses a lot less recursion. Also, a slightly improved version of transformString, which is smart enough to leave out empty strings from the list of strings to be joined. The new _flatten only recurses if there is a nesting of parsed structures: def _flatten(L): ret = [] for i in L: if isinstance(i,list): ret.extend(_flatten(i)) else: ret.append(i) return ret -- Paul -----Original Message----- From: Luke Campagnola [mailto:lca...@em...] Sent: Monday, May 30, 2011 10:28 AM To: pyp...@li... Subject: [Pyparsing] recursion in _flatten after version 1.5.2 Howdy, I have a script that I use to strip comments from C files. The code fails for any pyparsing version later than 1.5.2. Backtrace looks like this: File "CParser.py", line 300, in removeComments self.files[file] = (quotedString | cStyleComment.suppress() | cplusplusLineComment.suppress()).transformString(text) File "c:\python27\lib\site-packages\pyparsing.py", line 1166, in transformString return "".join(map(_ustr,_flatten(out))) File "c:\python27\lib\site-packages\pyparsing.py", line 3190, in _flatten return _flatten(L[0]) + _flatten(L[1:]) File "c:\python27\lib\site-packages\pyparsing.py", line 3190, in _flatten return _flatten(L[0]) + _flatten(L[1:]) . . . File "c:\python27\lib\site-packages\pyparsing.py", line 3188, in _flatten if type(L) is not list: return [L] RuntimeError: maximum recursion depth exceeded while calling a Python object If I remember correctly, 'quotedString' and cStyleComment' are provided by pyparsing, and I have provided this definition: cplusplusLineComment = Literal("//") + restOfLine Any hints? Luke ---------------------------------------------------------------------------- -- vRanger cuts backup time in half-while increasing security. With the market-leading solution for virtual backup and recovery, you get blazing-fast, flexible, and affordable data protection. Download your free trial now. http://p.sf.net/sfu/quest-d2dcopy1 _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users |