MCPcopy Create free account
hub / github.com/borgo-lang/borgo / parse_pat_struct

Method parse_pat_struct

compiler/src/parser.rs:1236–1275  ·  view source on GitHub ↗
(&mut self, ident: String)

Source from the content-addressed store, hash-verified

1234 }
1235
1236 fn parse_pat_struct(&mut self, ident: String) -> Pat {
1237 assert!(self.tok.kind == TokenKind::LCurly);
1238
1239 // consume '{'
1240 let start = self.next();
1241
1242 let mut fields = vec![];
1243
1244 while self.is_not(TokenKind::RCurly) {
1245 // Parse field: value
1246 let field = self.parse_one_ident();
1247 let value = if self.tok.kind == TokenKind::Colon {
1248 // consume ':'
1249 self.next();
1250 self.parse_pat()
1251 } else {
1252 Pat::Type {
1253 ident: field.clone(),
1254 is_mut: false,
1255 ann: TypeAst::Unknown,
1256 span: self.make_span(start),
1257 }
1258 };
1259
1260 fields.push(StructFieldPat { name: field, value });
1261
1262 if self.tok.kind == TokenKind::Comma {
1263 self.next();
1264 }
1265 }
1266
1267 self.expect(TokenKind::RCurly);
1268
1269 Pat::Struct {
1270 ident,
1271 fields,
1272 ty: Type::dummy(),
1273 span: self.make_span(start),
1274 }
1275 }
1276
1277 fn parse_pat_lit(&mut self) -> Pat {
1278 let expr = self.parse_expr();

Callers 1

parse_pat_identMethod · 0.80

Calls 6

is_notMethod · 0.80
parse_one_identMethod · 0.80
parse_patMethod · 0.80
make_spanMethod · 0.80
expectMethod · 0.80
nextMethod · 0.45

Tested by

no test coverage detected