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

Parses a pattern. See:

(&mut self, allow_star_pattern: AllowStarPattern)

Source from the content-addressed store, hash-verified

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

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