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

Method parse_variable_decl

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

Source from the content-addressed store, hash-verified

327 }
328 Some(Token::Ident(_)) if self.peek_n(1) == Some(&Token::ColonEqual) => {
329 let name = self.expect_ident()?;
330 self.expect_colon_equal()?;
331 if matches!(self.peek(), Some(Token::Import)) {
332 return Err(self.error(
333 "`import(...)` is only valid as a top-level module binding \
334 (`alias := import(\"...\")`), not inside a function body",
335 ));
336 }
337 let init = self.parse_expression()?;
338 Ok(Statement::InferredVariableDecl { name, init })
339 }
340 Some(Token::Import) => Err(self.error(
341 "`import(...)` is only valid as a top-level module binding \
342 (`alias := import(\"...\")`), not inside a function body",
343 )),
344 Some(_) => Ok(Statement::Expression(self.parse_expression()?)),
345 None => Err(self.error("unexpected end of input while parsing statement")),
346 }
347 }
348
349 fn parse_expression(&mut self) -> Result<Expression, ParserError> {

Callers 1

parse_declarationMethod · 0.80

Calls 6

expect_identMethod · 0.80
expect_colonMethod · 0.80
parse_typeMethod · 0.80
match_assignMethod · 0.80
parse_expressionMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected