Repository navigation
Add support for the match statement - #246
Closed
SahilRajputdotexe wants to merge 1 commit into
Closed
SahilRajputdotexe wants to merge 1 commit into
SahilRajputdotexe wants to merge 1 commit into
Conversation
Parse PEP 634 match statements with the grammars for Python 3.10 and later. match and case stay usable as names; match is only a statement keyword when the logical line starts with it and ends with a colon. The error finder reports the same syntax errors as CPython for the new statement, and the diff parser and the pep8 normalizer know about it.
Owner
|
LLM slop, closing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds parsing of the
matchstatement (PEP 634) to the Python 3.10 and later grammars. Refs #138, which discusses how to handle the soft keywords.matchandcaseare soft keywords, somatch = 1,match(x)andmatch[0]: inthave to keep working. Amatchthat starts a logical line and whose line ends in a colon is parsed as the statement, anything else is a name. The parser also falls back to a name whencaseis not accepted as a keyword. This does not follow the demo branch linked in the issue, which makes the parser semi-LL(1). The lookahead here is a small wrapper around the token stream. No new tree classes are added. The new nodes are plainmatch_stmt,case_blockand pattern nodes, andmatch_stmtandcase_blockare registered as flow containers.The error finder reports what CPython reports for the new syntax, for example an irrefutable pattern that is not last, a repeated capture name,
*patterns outside a sequence and bad mapping or class patterns. The diff parser and the pep8 normalizer also understand the statement.I ran the full test suite on Python 3.8 to 3.14 locally. New tests are in test_parser.py, test_diff_parser.py, test_pep8.py and failing_examples.py, which is compared against CPython's own messages on 3.10 and later.