MCPcopy Create free account
hub / github.com/astral-sh/ruff / parse_match_statement

Method parse_match_statement

crates/ruff_python_parser/src/parser/statement.rs:2610–2641  ·  view source on GitHub ↗

Parses a match statement. # Panics If the parser isn't positioned at a `match` token. See:

(&mut self)

Source from the content-addressed store, hash-verified

2608 ///
2609 /// See: <https://docs.python.org/3/reference/compound_stmts.html#the-match-statement>
2610 fn parse_match_statement(&mut self) -> ast::StmtMatch {
2611 let start = self.node_start();
2612 self.bump(TokenKind::Match);
2613
2614 let match_range = self.node_range(start);
2615
2616 let subject = self.parse_match_subject_expression();
2617 self.expect(TokenKind::Colon);
2618
2619 let cases = self.parse_match_body();
2620
2621 // test_err match_before_py310
2622 // # parse_options: { "target-version": "3.9" }
2623 // match 2:
2624 // case 1:
2625 // pass
2626
2627 // test_ok match_after_py310
2628 // # parse_options: { "target-version": "3.10" }
2629 // match 2:
2630 // case 1:
2631 // pass
2632
2633 self.add_unsupported_syntax_error(UnsupportedSyntaxErrorKind::Match, match_range);
2634
2635 ast::StmtMatch {
2636 subject: Box::new(subject),
2637 cases,
2638 range: self.node_range(start),
2639 node_index: AtomicNodeIndex::NONE,
2640 }
2641 }
2642
2643 /// Parses the subject expression for a `match` statement.
2644 fn parse_match_subject_expression(&mut self) -> Expr {

Callers 1

parse_statementMethod · 0.80

Calls 7

node_startMethod · 0.80
node_rangeMethod · 0.80
expectMethod · 0.80
parse_match_bodyMethod · 0.80
bumpMethod · 0.45

Tested by

no test coverage detected