Michael Cohen - 2016-01-17

When defining an element and using setResultsName() to store the match, it sometimes stores the actual string and sometimes it stores a ParseResults() instance. It seems to be storing a plain string if Word() matches and a ParseResults() instance if something else matches e.g. Group()

This is confusing since users have to guess what something will return and if you decide to add e.g. Optional, OneOrMore etc to a Word() it can switch from one behaviour to another.

The return types should be kept consistent.

Here is an example:

import pyparsing

_VALID_TOKEN_CHARS = pyparsing.alphanums + "_"
_TOKEN = pyparsing.Word(_VALID_TOKEN_CHARS)

a = _TOKEN("foo").parseString("dsdfs")
print type(a["foo"])

a = pyparsing.Group(_TOKEN)("foo").parseString("dsdfs")
print type(a["foo"])
<type 'str'>
<class 'pyparsing.ParseResults'>