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

Method parse_match_patterns

crates/ruff_python_parser/src/parser/pattern.rs:69–85  ·  view source on GitHub ↗

Entry point to start parsing a pattern. See:

(&mut self)

Source from the content-addressed store, hash-verified

67 ///
68 /// See: <https://docs.python.org/3/reference/compound_stmts.html#grammar-token-python-grammar-patterns>
69 pub(super) fn parse_match_patterns(&mut self) -> Pattern {
70 let start = self.node_start();
71
72 // We don't yet know if it's a sequence pattern or a single pattern, so
73 // we need to allow star pattern here.
74 let pattern = self.parse_match_pattern(AllowStarPattern::Yes);
75
76 if self.at(TokenKind::Comma) {
77 Pattern::MatchSequence(self.parse_sequence_match_pattern(pattern, start, None))
78 } else {
79 // We know it's not a sequence pattern now, so check for star pattern usage.
80 if pattern.is_match_star() {
81 self.add_error(ParseErrorType::InvalidStarPatternUsage, &pattern);
82 }
83 pattern
84 }
85 }
86
87 /// Parses an `or_pattern` or an `as_pattern`.
88 ///

Callers 1

parse_match_caseMethod · 0.80

Calls 6

node_startMethod · 0.80
parse_match_patternMethod · 0.80
is_match_starMethod · 0.80
atMethod · 0.45
add_errorMethod · 0.45

Tested by

no test coverage detected