Skip to content

Commit 1871a16

Browse files
Treat match and case as soft keywords in lambda assignments (RustPython#4623)
1 parent 4e19be7 commit 1871a16

File tree

3 files changed

+243
-1
lines changed

3 files changed

+243
-1
lines changed

compiler/parser/src/parser.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,8 @@ match match:
604604
case 1: pass
605605
case 2:
606606
pass
607+
match = lambda query: query == event
608+
print(match(12))
607609
"#,
608610
"<test>",
609611
)

compiler/parser/src/snapshots/rustpython_parser__parser__tests__match_as_identifier.snap

Lines changed: 236 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/parser/src/soft_keywords.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,15 @@ where
5959
let mut nesting = 0;
6060
let mut first = true;
6161
let mut seen_colon = false;
62+
let mut seen_lambda = false;
6263
while let Some(Ok((_, tok, _))) = self.underlying.peek() {
6364
match tok {
6465
Tok::Newline => break,
66+
Tok::Lambda if nesting == 0 => seen_lambda = true,
6567
Tok::Colon if nesting == 0 => {
66-
if !first {
68+
if seen_lambda {
69+
seen_lambda = false;
70+
} else if !first {
6771
seen_colon = true;
6872
}
6973
}

0 commit comments

Comments
 (0)