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

Method parse_enum_decl

crates/hll-to-ir/src/parser.rs:399–444  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

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();

Callers 1

parse_declarationMethod · 0.80

Calls 13

expect_identMethod · 0.80
parse_generic_paramsMethod · 0.80
expect_lbraceMethod · 0.80
consume_terminatorsMethod · 0.80
check_rbraceMethod · 0.80
match_lparenMethod · 0.80
check_rparenMethod · 0.80
pushMethod · 0.80
parse_typeMethod · 0.80
match_commaMethod · 0.80
expect_rparenMethod · 0.80
expect_rbraceMethod · 0.80

Tested by

no test coverage detected