Skip to content

Parsing error for Words with setResultsName (regression in 3.2.4) #618

@mstimberg

Description

@mstimberg

We are using pyparsing to parse physical equation and parameter definitions. Potentially we are using it wrong, but the following (simplified) version works in 3.2.3, but fails in 3.2.4:

import string
from pyparsing import Word, Group, Suppress

IDENTIFIER = Word(
    string.ascii_letters + "_", string.ascii_letters + string.digits + "_"
).setResultsName("identifier")

# very broad definition here, whether this corresponds to a valid unit string will be checked later
UNIT = Word(string.ascii_letters + string.digits + "*/.- ").setResultsName("unit")

PARAMETER_EQ = Group(
    IDENTIFIER + Suppress(":") + UNIT
)

print(repr(PARAMETER_EQ.parse_string("speed : meter/second")))

In 3.2.3, this prints:

ParseResults([ParseResults(['speed', 'meter/second'], {'identifier': 'speed', 'unit': 'meter/second'})], {})

whereas in 3.2.4, it fails with:

Traceback (most recent call last):
  File "/home/mstimberg/scratch/pyparsing_issue.py", line 15, in <module>
    print(repr(PARAMETER_EQ.parse_string("speed : meter/second")))
               ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mstimberg/.cache/uv/archive-v0/b2gwMgK-avsJGeZiOPy1f/lib/python3.13/site-packages/pyparsing/core.py", line 1306, in parse_string
    loc, tokens = self._parse(instring, 0)
                  ~~~~~~~~~~~^^^^^^^^^^^^^
  File "/home/mstimberg/.cache/uv/archive-v0/b2gwMgK-avsJGeZiOPy1f/lib/python3.13/site-packages/pyparsing/core.py", line 933, in _parseNoCache
    loc, tokens = self.parseImpl(instring, pre_loc, do_actions)
                  ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mstimberg/.cache/uv/archive-v0/b2gwMgK-avsJGeZiOPy1f/lib/python3.13/site-packages/pyparsing/core.py", line 5034, in parseImpl
    return self.expr._parse(instring, loc, do_actions, callPreParse=False)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mstimberg/.cache/uv/archive-v0/b2gwMgK-avsJGeZiOPy1f/lib/python3.13/site-packages/pyparsing/core.py", line 933, in _parseNoCache
    loc, tokens = self.parseImpl(instring, pre_loc, do_actions)
                  ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mstimberg/.cache/uv/archive-v0/b2gwMgK-avsJGeZiOPy1f/lib/python3.13/site-packages/pyparsing/core.py", line 4513, in parseImpl
    loc, exprtokens = e._parse(instring, loc, do_actions)
                      ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mstimberg/.cache/uv/archive-v0/b2gwMgK-avsJGeZiOPy1f/lib/python3.13/site-packages/pyparsing/core.py", line 937, in _parseNoCache
    loc, tokens = self.parseImpl(instring, pre_loc, do_actions)
                  ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mstimberg/.cache/uv/archive-v0/b2gwMgK-avsJGeZiOPy1f/lib/python3.13/site-packages/pyparsing/core.py", line 3290, in parseImpl_regex
    result = self.re_match(instring, loc)
             ^^^^^^^^^^^^^
AttributeError: 'Word' object has no attribute 're_match'

From reading the changelog, it might be related to the fix for #612?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions