Discussion:
[Pyparsing] A bug with .asXML()
lilydjwg
2013-04-12 08:22:52 UTC
Permalink
I find the following code can print out two kinds of result:

from pyparsing import *

word = Word(alphas).setResultsName('word')

f = Forward().setResultsName('forward')
f << word + Optional(f)
r = f.parseString('abc def')

print(r.asXML())


Run it multiple times. Sometimes it prints what is expected:

<forward>
<word>abc</word>
<word>def</word>
</forward>

But sometimes I get this:

<forward>
<forward>abc</forward>
<forward>def</forward>
</forward>

pyparsing version 2.0.0. Old version is ok.

This is caused by this statement around line 444 in asXML:

namedItems = dict((v[1],k) for (k,vlist) in self.__tokdict.items() for v in vlist)

v[1] in different items may be the same for some reason.

Sorry I can't make a bug report on SourceForge because it refuses me to
register.
--
Best regards,
lilydjwg
Loading...