Skip to content

Preserve the failure position of described parsers - #91

Closed
Aschenbath wants to merge 1 commit into
python-parsy:masterfrom
Aschenbath:fix/desc-failure-position-77
Closed

Aschenbath wants to merge 1 commit into
python-parsy:masterfrom
Aschenbath:fix/desc-failure-position-77

Conversation

@Aschenbath

Copy link
Copy Markdown

Calling .desc() on a combined parser reset a failed parse's position to the start of that parser. For example, (string('a') >> string('b')).desc('a pair').parse('ax') reported column 0 even though parsing failed at column 1.

Preserve the underlying result's furthest failure position while replacing its expected text with the supplied description, as discussed in #77. Successful results retain their existing values and backtracking information. Add regressions for alternatives, generators, nonzero offsets, bytes and token lists, plus documentation and a release note.

Fixes #77.

Validation:

  • The original implementation fails six of the seven new regression tests (seven failures when counting both stream subcases).
  • Python 3.10 and 3.12: 93 passed, 2 skipped; 100% module coverage on 3.12.
  • All repository pre-commit checks pass using the configured Python 3.10 tools.
  • Sphinx HTML build succeeds with the existing missing docs/_static warning. Wheel and source distribution build; direct wheel-import checks pass.
  • Independent review checked 5,473 combinations of labels, offsets and combinators without findings.

Prepared with AI assistance; validation was run locally on Windows.

@spookylukey

Copy link
Copy Markdown
Member

This PR doesn't address the issues raised in my last comment in #77

Consider this (master branch):

>>> import parsy as P
>>> a_and_b = P.string('a') + P.string('b')
>>> a_and_b.parse('a')
...
parsy.ParseError: expected 'b' at 0:1
>>> a_and_b.desc('a and b').parse('a')
parsy.ParseError: expected 'a and b' at 0:0

With the PR you instead get:

parsy.ParseError: expected 'a and b' at 0:1

which is incorrect, 'a and b' is not expected at 0:1, only 'b' is.

In terms of quality I'm closing this immediately as slop https://lukeplant.me.uk/blog/posts/why-im-calling-your-contribution-slop/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Parser.desc() causes loss of error information, simple fix

2 participants