Parses a pattern. See:
(&mut self, allow_star_pattern: AllowStarPattern)
| 162 | /// |
| 163 | /// See: <https://docs.python.org/3/reference/compound_stmts.html#grammar-token-python-grammar-closed_pattern> |
| 164 | fn parse_match_pattern_lhs(&mut self, allow_star_pattern: AllowStarPattern) -> Pattern { |
| 165 | let start = self.node_start(); |
| 166 | |
| 167 | let mut lhs = match self.current_token_kind() { |
| 168 | TokenKind::Lbrace => Pattern::MatchMapping(self.parse_match_pattern_mapping()), |
| 169 | TokenKind::Star => { |
| 170 | let star_pattern = self.parse_match_pattern_star(); |
| 171 | if allow_star_pattern.is_no() { |
| 172 | self.add_error(ParseErrorType::InvalidStarPatternUsage, &star_pattern); |
| 173 | } |
| 174 | Pattern::MatchStar(star_pattern) |
| 175 | } |
| 176 | TokenKind::Lpar | TokenKind::Lsqb => self.parse_parenthesized_or_sequence_pattern(), |
| 177 | _ => self.parse_match_pattern_literal(), |
| 178 | }; |
| 179 | |
| 180 | if self.at(TokenKind::Lpar) { |
| 181 | lhs = Pattern::MatchClass(self.parse_match_pattern_class(lhs, start)); |
| 182 | } |
| 183 | |
| 184 | if matches!( |
| 185 | self.current_token_kind(), |
| 186 | TokenKind::Plus | TokenKind::Minus |
| 187 | ) { |
| 188 | lhs = Pattern::MatchValue(self.parse_complex_literal_pattern(lhs, start)); |
| 189 | } |
| 190 | |
| 191 | lhs |
| 192 | } |
| 193 | |
| 194 | /// Parses a mapping pattern. |
| 195 | /// |
no test coverage detected