Skip to content

Commit 199a512

Browse files
authored
Fix case *_ error (antlr#4280)
* starpattern * test
1 parent 4ac641c commit 199a512

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

python/python3_12/PythonParser.g4

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ THE SOFTWARE.
2727
*
2828
*/
2929

30+
/*
31+
* Contributors :
32+
* [Willie Shen](https://github.com/Willie169) : Fix that `case [a, *_] if a == 0:` throws error `rule soft_kw__not__wildcard failed predicate: {this.isnotEqualToCurrentTokenText("_")}?`
33+
*/
34+
3035
parser grammar PythonParser; // Python 3.12.6 https://docs.python.org/3.12/reference/grammar.html#full-grammar-specification
3136
options {
3237
tokenVocab=PythonLexer;
@@ -427,8 +432,7 @@ maybe_star_pattern
427432
| pattern;
428433

429434
star_pattern
430-
: '*' pattern_capture_target
431-
| '*' wildcard_pattern;
435+
: '*' NAME;
432436

433437
mapping_pattern
434438
: LBRACE RBRACE

python/python3_12/changes.txt renamed to python/python3_12/changes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ Type comments will now be tokenized as plain comment tokens.
55

66
Line continuation for string literals (backslash followed by a newline) is no longer resolved.
77
(backslash+newline is no longer removed from string literals)
8+
9+
---
10+
Oct. 18, 2024
11+
---
12+
Fix that `case [a, *_] if a == 0:` throws error `rule soft_kw__not__wildcard failed predicate: {this.isnotEqualToCurrentTokenText("_")}?`
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# COMMAND LINE:
2+
# grun Python file_input -tokens test_match_case.py
3+
#
4+
# EXPECTATIONS:
5+
# - [@63,234:234='*',<'*'>,12:13]
6+
# - [@64,235:235='_',<NAME>,12:14]
7+
# - no error message
8+
9+
a, *b = [1, 2, 3, 4]
10+
match b:
11+
case [2]:
12+
print("0")
13+
case [f, *_] if f==2:
14+
print("1")
15+
case _:
16+
print("2")

0 commit comments

Comments
 (0)