From 14e34da22f00ef7464eff2c193e645cf419d1edb Mon Sep 17 00:00:00 2001 From: nic-gaffney Date: Fri, 14 Apr 2023 05:32:18 -0500 Subject: All the tests pass now idk what happened --- crates/sloth/src/parser/stmt.rs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/crates/sloth/src/parser/stmt.rs b/crates/sloth/src/parser/stmt.rs index c193f4f..6f53119 100644 --- a/crates/sloth/src/parser/stmt.rs +++ b/crates/sloth/src/parser/stmt.rs @@ -212,8 +212,14 @@ impl<'a> AstParser<'a> { ); let mut body = Vec::new(); while !self.eof() && self.peek().tt != TokenType::ClosingBrace { + println!("{:?}", self.peek().tt); body.push(self.statement()); } + self.consume( + TokenType::ClosingBrace, + "Expected '}' after block on while loop", + ); + self.advance(); Stmt::While { condition, body } } @@ -226,17 +232,23 @@ impl<'a> AstParser<'a> { // if let Expr::Literal(_ident) = &expr { // let value = self.expression(); - // self.consume(TokenType::SemiColon, "Expected ';' at end of - // statement"); // return Stmt::DefineVariable { - // // name: (ident.clone()), - // // value: (value), - // // typ: (None), - // // }; + // self.consume( + // TokenType::SemiColon, + // "Expected ';' at end of + // statement", + // ); // return Stmt::DefineVariable { + // // name: (ident.clone()), + // // value: (value), + // // typ: (None), + // // }; // return Stmt::ExprStmt(expr); // } // } - self.consume(TokenType::SemiColon, "Expected ';' at end of statement"); + self.consume( + TokenType::SemiColon, + "Expected ';' at end of expr statement", + ); Stmt::ExprStmt(expr) } @@ -366,7 +378,7 @@ mod tests { let expected_ast = Stmt::DefineFunction { ident: ("test_c".to_string()), - args: Some(vec![ + args: (vec![ FuncArgs { name: ("a".to_string()), typ: None, @@ -562,10 +574,10 @@ mod tests { let expected_ast = Stmt::DefineFunction { ident: ("times_two".to_string()), - args: (Some(vec![FuncArgs { + args: (vec![FuncArgs { name: ("x".to_string()), typ: (Some("int".to_string())), - }])), + }]), body: (vec![ Stmt::DefineValue { name: "y".to_string(), -- cgit v1.2.3