Parses the body of a `match` statement. This method expects that the parser is positioned at a `Newline` token. If not, it adds a syntax error and continues parsing.
(&mut self)
| 2696 | /// This method expects that the parser is positioned at a `Newline` token. If not, it adds a |
| 2697 | /// syntax error and continues parsing. |
| 2698 | fn parse_match_body(&mut self) -> Vec<ast::MatchCase> { |
| 2699 | // test_err match_stmt_no_newline_before_case |
| 2700 | // match foo: case _: ... |
| 2701 | self.expect(TokenKind::Newline); |
| 2702 | |
| 2703 | // Use `eat` instead of `expect` for better error message. |
| 2704 | if !self.eat(TokenKind::Indent) { |
| 2705 | // test_err match_stmt_expect_indented_block |
| 2706 | // match foo: |
| 2707 | // case _: ... |
| 2708 | self.add_error( |
| 2709 | ParseErrorType::OtherError( |
| 2710 | "Expected an indented block after `match` statement".to_string(), |
| 2711 | ), |
| 2712 | self.current_token_range(), |
| 2713 | ); |
| 2714 | } |
| 2715 | |
| 2716 | let cases = self.parse_match_case_blocks(); |
| 2717 | |
| 2718 | // TODO(dhruvmanila): Should we expect `Dedent` only if there was an `Indent` present? |
| 2719 | self.expect(TokenKind::Dedent); |
| 2720 | |
| 2721 | cases |
| 2722 | } |
| 2723 | |
| 2724 | /// Parses a list of match case blocks. |
| 2725 | fn parse_match_case_blocks(&mut self) -> Vec<ast::MatchCase> { |
no test coverage detected