Parses a match statement. # Panics If the parser isn't positioned at a `match` token. See:
(&mut self)
| 2651 | /// |
| 2652 | /// See: <https://docs.python.org/3/reference/compound_stmts.html#the-match-statement> |
| 2653 | fn parse_match_statement(&mut self) -> ast::StmtMatch { |
| 2654 | let start = self.node_start(); |
| 2655 | self.bump_match_statement_keyword(); |
| 2656 | |
| 2657 | let match_range = self.node_range(start); |
| 2658 | |
| 2659 | let subject = self.parse_match_subject_expression(); |
| 2660 | self.expect(TokenKind::Colon); |
| 2661 | |
| 2662 | let cases = self.parse_match_body(); |
| 2663 | |
| 2664 | // test_err match_before_py310 |
| 2665 | // # parse_options: { "target-version": "3.9" } |
| 2666 | // match 2: |
| 2667 | // case 1: |
| 2668 | // pass |
| 2669 | |
| 2670 | // test_ok match_after_py310 |
| 2671 | // # parse_options: { "target-version": "3.10" } |
| 2672 | // match 2: |
| 2673 | // case 1: |
| 2674 | // pass |
| 2675 | |
| 2676 | self.add_unsupported_syntax_error(UnsupportedSyntaxErrorKind::Match, match_range); |
| 2677 | |
| 2678 | ast::StmtMatch { |
| 2679 | subject: Box::new(subject), |
| 2680 | cases, |
| 2681 | range: self.node_range(start), |
| 2682 | node_index: AtomicNodeIndex::NONE, |
| 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | /// Parses the subject expression for a `match` statement. |
| 2687 | fn parse_match_subject_expression(&mut self) -> Expr { |
no test coverage detected