MCPcopy Create free account
hub / github.com/LPC4/Full-Stack / parse_impl_block

Method parse_impl_block

crates/hll-to-ir/src/parser.rs:488–540  ·  view source on GitHub ↗

Parse `impl Type { method: (self: Type*, ...) -> R { ... } }`; each method desugars to a free function `Type_method` (static dispatch, explicit self).

(&mut self)

Source from the content-addressed store, hash-verified

486 }
487 self.expect_rparen()?;
488 }
489 variants.push(Variant {
490 name: variant_name,
491 payload,
492 });
493
494 let newline_separated = matches!(self.peek(), Some(Token::StatementTerminator));
495 self.consume_terminators();
496 if self.match_comma() {
497 self.consume_terminators();
498 } else if !newline_separated && !self.check_rbrace() {
499 return Err(self.error("expected `,` or newline between enum variants"));
500 }
501 }
502
503 self.expect_rbrace()?;
504 Ok(DeclNode::Enum {
505 name,
506 generics,
507 bounds,
508 variants,
509 })
510 }
511
512 fn parse_function_decl(
513 &mut self,
514 is_extern: bool,
515 is_import_interface: bool,
516 ) -> Result<DeclNode, ParserError> {
517 let name = self.expect_ident()?;
518 self.expect_colon()?;
519
520 let (generics, bounds) = self.parse_generic_params_with_bounds()?;
521
522 let params = self.parse_param_list()?;
523
524 let return_type = if self.match_arrow() {
525 if self.peek() == Some(&Token::LParen) && self.peek_n(1) == Some(&Token::RParen) {
526 return Err(self.error("void functions omit `->`; `-> ()` is not valid"));
527 }
528 Some(self.parse_return_type()?)
529 } else {
530 None
531 };
532
533 let body = if is_extern {
534 None
535 } else if self.check_lbrace() {
536 Some(self.parse_block()?)
537 } else {
538 return Err(self.error("expected function body block"));
539 };
540
541 Ok(DeclNode::Function {
542 name,
543 generics,

Callers 1

parse_programMethod · 0.80

Calls 9

expect_identMethod · 0.80
expect_lbraceMethod · 0.80
consume_terminatorsMethod · 0.80
check_rbraceMethod · 0.80
parse_function_declMethod · 0.80
pushMethod · 0.80
expect_rbraceMethod · 0.80
advanceMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected