Re: [Pyparsing] Bug report: setResultsName works inconsistently on Optional in Each
Brought to you by:
ptmcg
From: Paul M. <pt...@au...> - 2015-11-10 01:05:10
|
Nice report, Max, especially boiling the bug repro down to a single statement - very helpful! Just finishing the check-in of a fix to SourceForge SVN, will be included in the next release. -- Paul -----Original Message----- From: Max Rothman [mailto:max...@gm...] Sent: Sunday, November 08, 2015 8:15 PM To: pyp...@li... Subject: [Pyparsing] Bug report: setResultsName works inconsistently on Optional in Each It seems that Optional.setResultsName joined by Each does not behave consistently with other ParserElements. For example: >>> (Optional('foo')('one') & >>> pp.Optional('bar')('two')).parseString('foo bar') (['foo', 'bar'], {}) >>> (Optional('bar')('two') & Optional('foo')('one')).parseString('foo >>> bar') (['foo', 'bar'], {'two': [('bar', 1)]}) A workaround is to name the Literals themselves instead of the Optionals: >>> (Optional(Literal('bar')('two')) & Optional(Literal('foo')('one'))).parseString('foo bar') (['foo', 'bar'], {'two': [('bar', 1)], 'one': [('foo', 0)]}) >>> (Optional(Literal('foo')('one')) & Optional(Literal('bar')('two'))).parseString('foo bar') (['foo', 'bar'], {'two': [('bar', 1)], 'one': [('foo', 0)]}) The problem does not manifest when joining Optional objects with And: >>> (Optional('foo')('one') + >>> pp.Optional('bar')('two')).parseString('foo bar') (['foo', 'bar'], {'two': [('bar', 1)], 'one': [('foo', 0)]}) Thanks, Max ---------------------------------------------------------------------------- -- Presto, an open source distributed SQL query engine for big data, initially developed by Facebook, enables you to easily query your data on Hadoop in a more interactive manner. Teradata is also now providing full enterprise support for Presto. Download a free open source copy now. http://pubads.g.doubleclick.net/gampad/clk?id=250295911&iu=/4140 _______________________________________________ Pyparsing-users mailing list Pyp...@li... https://lists.sourceforge.net/lists/listinfo/pyparsing-users --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus |