Skip to content
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

Fix case *_ error #4280

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions python/python3_12/PythonParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ THE SOFTWARE.
*
*/

/*
* Contributors :
* [Willie Shen](https://github.com/Willie169) : Fix that `case [a, *_] if a == 0:` throws error `rule soft_kw__not__wildcard failed predicate: {this.isnotEqualToCurrentTokenText("_")}?`
*/

parser grammar PythonParser; // Python 3.12.6 https://docs.python.org/3.12/reference/grammar.html#full-grammar-specification
options {
tokenVocab=PythonLexer;
Expand Down Expand Up @@ -427,8 +432,7 @@ maybe_star_pattern
| pattern;

star_pattern
: '*' pattern_capture_target
| '*' wildcard_pattern;
: '*' NAME;
Willie169 marked this conversation as resolved.
Show resolved Hide resolved

mapping_pattern
: LBRACE RBRACE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ Type comments will now be tokenized as plain comment tokens.

Line continuation for string literals (backslash followed by a newline) is no longer resolved.
(backslash+newline is no longer removed from string literals)

---
Oct. 18, 2024
---
Fix that `case [a, *_] if a == 0:` throws error `rule soft_kw__not__wildcard failed predicate: {this.isnotEqualToCurrentTokenText("_")}?`
16 changes: 16 additions & 0 deletions python/python3_12/tests/test_match_case.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# COMMAND LINE:
# grun Python file_input -tokens test_match_case.py
#
# EXPECTATIONS:
# - [@63,234:234='*',<'*'>,12:13]
# - [@64,235:235='_',<NAME>,12:14]
# - no error message

a, *b = [1, 2, 3, 4]
match b:
case [2]:
print("0")
case [f, *_] if f==2:
print("1")
case _:
print("2")