Skip to content

ParseException of MatchFirst with shared "prefix"-element mentions only partial expected element #592

@WhiteGobo

Description

@WhiteGobo

With following parser and string i would expect an exception description which states, that {Re:('a') | Re:('b')} is expected. Instead it only mentions 'Re:('a')':

from pyparsing import *

ab = Regex("prefix") + (Regex("a") | Regex("b"))
s = "prefix c"
ab.parse_string(s)

The exception only lists Re:('a'):

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    q.parse_string(s)
  File "/usr/lib/python3.12/site-packages/pyparsing/core.py", line 1200, in parse_string
    raise exc.with_traceback(None)
pyparsing.exceptions.ParseException: Expected Re:('a'), found 'c'  (at char 7), (line:1, col:8)

I can directly specify the exception message directly with q.set_fail_action. I havent found any other workaround.

Metadata

Metadata

Assignees

No one assigned

    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