From: Batuhan Taskaya Date: Tue, 21 Dec 2021 18:16:55 +0000 (+0300) Subject: Support multiple top-level as-expressions on case statements (#2716) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/3fafd806b30cbff5788525f050a635639d97b11c?ds=sidebyside Support multiple top-level as-expressions on case statements (#2716) --- diff --git a/CHANGES.md b/CHANGES.md index 252f2cc..d5cfb62 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ underlying SyntaxError (#2693) - Fix mapping cases that contain as-expressions, like `case {"key": 1 | 2 as password}` (#2686) +- Fix cases that contain multiple top-level as-expressions, like `case 1 as a, 2 as b` + (#2716) - No longer color diff headers white as it's unreadable in light themed terminals (#2691) - Tuple unpacking on `return` and `yield` constructs now implies 3.8+ (#2700) diff --git a/src/blib2to3/Grammar.txt b/src/blib2to3/Grammar.txt index 600712c..27776a3 100644 --- a/src/blib2to3/Grammar.txt +++ b/src/blib2to3/Grammar.txt @@ -247,5 +247,5 @@ subject_expr: (namedexpr_test|star_expr) (',' (namedexpr_test|star_expr))* [','] # cases case_block: "case" patterns [guard] ':' suite guard: 'if' namedexpr_test -patterns: pattern ['as' pattern] -pattern: (expr|star_expr) (',' (expr|star_expr))* [','] +patterns: pattern (',' pattern)* [','] +pattern: (expr|star_expr) ['as' expr] diff --git a/tests/data/pattern_matching_extras.py b/tests/data/pattern_matching_extras.py index c00585e..b652d26 100644 --- a/tests/data/pattern_matching_extras.py +++ b/tests/data/pattern_matching_extras.py @@ -92,3 +92,14 @@ match something: pass case {"maybe": something(complicated as this) as that}: pass + + +match something: + case 1 as a: + pass + + case 2 as b, 3 as c: + pass + + case 4 as d, (5 as e), (6 | 7 as g), *h: + pass