(&mut self)
| 964 | } |
| 965 | |
| 966 | fn parse_mapping_pattern(&mut self) -> Result<MatchPattern, ParsingError> { |
| 967 | let node = self.start_node(); |
| 968 | self.expect(Kind::LeftBracket)?; |
| 969 | let mut keys = vec![]; |
| 970 | let mut patterns = vec![]; |
| 971 | let mut rest = None; |
| 972 | loop { |
| 973 | if self.eat(Kind::RightBracket) { |
| 974 | break; |
| 975 | } |
| 976 | if self.eat(Kind::Pow) { |
| 977 | rest = Some(self.cur_token().to_string(self.source)); |
| 978 | self.bump(Kind::Identifier); |
| 979 | // consume the trailing comma |
| 980 | self.bump(Kind::Comma); |
| 981 | // rest is the last element so we expect the closing bracket |
| 982 | self.expect(Kind::RightBracket)?; |
| 983 | break; |
| 984 | } else { |
| 985 | // TODO: here we cannot accept all primary expressions |
| 986 | // but python docs do not have the full list of what is allowed |
| 987 | // so we just do this for now |
| 988 | keys.push(self.parse_primary(None)?); |
| 989 | self.expect(Kind::Colon)?; |
| 990 | patterns.push(self.parse_pattern()?); |
| 991 | } |
| 992 | |
| 993 | if !self.at(Kind::RightBracket) { |
| 994 | self.expect(Kind::Comma)?; |
| 995 | } |
| 996 | } |
| 997 | |
| 998 | Ok(MatchPattern::MatchMapping(MatchMapping { |
| 999 | node: self.finish_node(node), |
| 1000 | keys, |
| 1001 | patterns, |
| 1002 | rest, |
| 1003 | })) |
| 1004 | } |
| 1005 | |
| 1006 | fn parse_literal_or_value_pattern(&mut self) -> Result<MatchPattern, ParsingError> { |
| 1007 | if self.at(Kind::Identifier) && !matches!(self.peek_kind(), Ok(Kind::Colon)) { |
no test coverage detected