Sitelet https://web.archive.org/web/20250817083642/https://github.com/RustPython/RustPython/pull/4329
Skip to content

Parse Python 3.9+ parenthesized context managers #4329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 12, 2022

Conversation

andersk
Copy link
Contributor

@andersk andersk commented Dec 12, 2022

Since the upstream grammar for this is not LR(1), we abuse LALRPOP macros and the Into/TryInto traits to build a cover grammar that converts to either tuples or with items after additional validation. It’s annoying and ugly, but something like this is basically our only option short of switching to a more powerful parser algorithm.

Fixes #4145.

(Cc @charliermarsh, who I know is working on a more powerful parser algorithm in astral-sh/ruff#286. But this may be a useful stopgap.)

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Since the upstream grammar for this is not LR(1), we abuse LALRPOP
macros and the Into/TryInto traits to build a cover grammar that
converts to either tuples or `with` items after additional validation.
It’s annoying and ugly, but something like this is basically our only
option short of switching to a more powerful parser algorithm.

Fixes RustPython#4145.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you. Do you have a good idea about match too?

@youknowone youknowone merged commit 29391eb into RustPython:main Dec 12, 2022
@andersk andersk deleted the paren-contexts branch December 12, 2022 11:23
@charliermarsh
Copy link
Collaborator

Amazing work!

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.

Unable to parse parenthesized context managers
3 participants