MCPcopy Create free account
hub / github.com/Glyphack/enderpy / parse_mapping_pattern

Method parse_mapping_pattern

parser/src/parser/parser.rs:966–1004  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

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)) {

Callers 1

parse_closed_patternMethod · 0.80

Calls 11

MatchMappingClass · 0.85
start_nodeMethod · 0.80
expectMethod · 0.80
eatMethod · 0.80
to_stringMethod · 0.80
cur_tokenMethod · 0.80
bumpMethod · 0.80
parse_primaryMethod · 0.80
parse_patternMethod · 0.80
atMethod · 0.80
finish_nodeMethod · 0.80

Tested by

no test coverage detected