(&mut self)
| 397 | let init = if self.match_assign() { |
| 398 | Some(self.parse_expression()?) |
| 399 | } else { |
| 400 | return Err(self |
| 401 | .error("explicit declarations require an initializer: `name: Type = expression`")); |
| 402 | }; |
| 403 | |
| 404 | Ok(DeclNode::Variable { |
| 405 | name, |
| 406 | ty, |
| 407 | init, |
| 408 | is_extern: false, |
| 409 | }) |
| 410 | } |
| 411 | |
| 412 | fn parse_inferred_variable_decl(&mut self) -> Result<DeclNode, ParserError> { |
| 413 | let name = self.expect_ident()?; |
| 414 | self.expect_colon_equal()?; |
| 415 | let init = self.parse_expression()?; |
| 416 | Ok(DeclNode::InferredVariable { name, init }) |
| 417 | } |
| 418 | |
| 419 | // Consume `import ( string )` and return the path literal, with `import` next. |
| 420 | // Used by the `alias := import(...)` and `const alias = import(...)` module forms. |
| 421 | fn parse_import_call(&mut self) -> Result<String, ParserError> { |
| 422 | self.advance(); // `import` |
| 423 | self.expect_lparen()?; |
| 424 | let path = self.expect_string_literal()?; |
| 425 | self.expect_rparen()?; |
| 426 | Ok(path) |
| 427 | } |
| 428 | |
| 429 | fn parse_struct_decl(&mut self) -> Result<DeclNode, ParserError> { |
| 430 | let name = self.expect_ident()?; |
| 431 | let (generics, bounds) = self.parse_generic_params_with_bounds()?; |
| 432 | self.expect_lbrace()?; |
| 433 | let mut fields = Vec::new(); |
| 434 | self.consume_terminators(); |
| 435 | |
| 436 | while !self.check_rbrace() { |
| 437 | let field_name = self.expect_ident()?; |
| 438 | self.expect_colon()?; |
| 439 | let ty = self.parse_type()?; |
| 440 | fields.push(FieldDecl { |
| 441 | name: field_name, |
| 442 | ty, |
| 443 | init: None, |
| 444 | }); |
| 445 | |
| 446 | let newline_separated = matches!(self.peek(), Some(Token::StatementTerminator)); |
| 447 | self.consume_terminators(); |
no test coverage detected