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:70–86  ·  view source on GitHub ↗

Entry point to start parsing a pattern. See:

(&mut self)

Source from the content-addressed store, hash-verified

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

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