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

Method parse_match_pattern_lhs

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

Parses a pattern. See:

(&mut self, allow_star_pattern: AllowStarPattern)

Source from the content-addressed store, hash-verified

140 ///
141 /// See: <https://docs.python.org/3/reference/compound_stmts.html#grammar-token-python-grammar-closed_pattern>
142 fn parse_match_pattern_lhs(&mut self, allow_star_pattern: AllowStarPattern) -> Pattern {
143 self.with_recursion(|parser| {
144 let start = parser.node_start();
145
146 let mut lhs = match parser.current_token_kind() {
147 TokenKind::Lbrace => Pattern::MatchMapping(parser.parse_match_pattern_mapping()),
148 TokenKind::Star => {
149 let star_pattern = parser.parse_match_pattern_star();
150 if allow_star_pattern.is_no() {
151 parser.add_error(ParseErrorType::InvalidStarPatternUsage, &star_pattern);
152 }
153 Pattern::MatchStar(star_pattern)
154 }
155 TokenKind::Lpar | TokenKind::Lsqb => {
156 parser.parse_parenthesized_or_sequence_pattern()
157 }
158 _ => parser.parse_match_pattern_literal(),
159 };
160
161 if parser.at(TokenKind::Lpar) {
162 lhs = Pattern::MatchClass(parser.parse_match_pattern_class(lhs, start));
163 }
164
165 if matches!(
166 parser.current_token_kind(),
167 TokenKind::Plus | TokenKind::Minus
168 ) {
169 lhs = Pattern::MatchValue(parser.parse_complex_literal_pattern(lhs, start));
170 }
171
172 lhs
173 })
174 }
175
176 /// Parses a mapping pattern.
177 ///

Callers 3

parse_match_patternMethod · 0.80

Calls 12

with_recursionMethod · 0.80
node_startMethod · 0.80
current_token_kindMethod · 0.80
is_noMethod · 0.45
add_errorMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected