Skip to content

Commit

Permalink
Attempt to add parser for return function
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenhuyn committed Oct 23, 2024
1 parent be80989 commit 5e4fe18
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
28 changes: 28 additions & 0 deletions vine/examples/break_return.vi
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

use std::{io::println, u32};

fn main(io) {
println("hey");


// let a = unit();
// let b = loop_unit();

println("hey");

/*
if a == b {
println("Hurray for units!")
}
*/
}

fn unit() {
return;
}

fn loop_unit() {
return loop {
break;
}
}
16 changes: 15 additions & 1 deletion vine/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,24 @@ impl<'ctx, 'src> VineParser<'ctx, 'src> {

fn _parse_expr_prefix(&mut self, span: usize) -> Parse<'src, ExprKind> {
if self.eat(Token::Return)? {
if self.check(Token::Semi) {
self.eat(Token::Semi)?;
return Ok(ExprKind::Return(Box::new(Expr {
span: self.span(),
kind: ExprKind::Tuple(Vec::new()),
})));
}
return Ok(ExprKind::Return(Box::new(self.parse_expr_bp(BP::ControlFlow)?)));
}
if self.eat(Token::Break)? {
return Ok(ExprKind::Break(Box::new(self.parse_expr_bp(BP::ControlFlow)?)));
if self.check(Token::Semi) {
self.eat(Token::Semi)?;
return Ok(ExprKind::Return(Box::new(Expr {
span: self.span(),
kind: ExprKind::Tuple(Vec::new()),
})));
}
return Ok(ExprKind::Return(Box::new(self.parse_expr_bp(BP::ControlFlow)?)));
}
if self.eat(Token::Continue)? {
return Ok(ExprKind::Continue);
Expand Down

0 comments on commit 5e4fe18

Please sign in to comment.