Expect indented case block instead of match stmt (#11033)

## Summary

This PR adds a new `Clause::Case` and uses it to parse the body of a
`case` block. Earlier, it was using `Match` which would give an
incorrect error message like:

```
  |
1 | match subject:
2 |     case 1:
3 |     case 2: ...
  |     ^^^^ Syntax Error: Expected an indented block after `match` statement
  |
```

## Test Plan

Add test case and update the snapshot.
This commit is contained in:
Dhruv Manilawala 2024-04-19 16:46:15 +05:30 committed by GitHub
parent 06c248a126
commit 9bb23b0a38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 95 additions and 3 deletions

View file

@ -2492,7 +2492,12 @@ impl<'src> Parser<'src> {
};
self.expect(TokenKind::Colon);
let body = self.parse_body(Clause::Match);
// test_err case_expect_indented_block
// match subject:
// case 1:
// case 2: ...
let body = self.parse_body(Clause::Case);
ast::MatchCase {
pattern,
@ -3363,7 +3368,7 @@ enum Clause {
Class,
While,
FunctionDef,
Match,
Case,
Try,
Except,
Finally,
@ -3380,7 +3385,7 @@ impl Display for Clause {
Clause::Class => write!(f, "`class` definition"),
Clause::While => write!(f, "`while` statement"),
Clause::FunctionDef => write!(f, "function definition"),
Clause::Match => write!(f, "`match` statement"),
Clause::Case => write!(f, "`case` block"),
Clause::Try => write!(f, "`try` statement"),
Clause::Except => write!(f, "`except` clause"),
Clause::Finally => write!(f, "`finally` clause"),