aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornic-gaffney <gaffney_nic@protonmail.com>2023-04-14 05:32:18 -0500
committernic-gaffney <gaffney_nic@protonmail.com>2023-04-14 05:32:18 -0500
commit14e34da22f00ef7464eff2c193e645cf419d1edb (patch)
tree2c4e558b1ebbe487e1478be6e31674544149e9fc
parent5dbfa844a37cf00125db891d095d94620ba24879 (diff)
downloadsloth-14e34da22f00ef7464eff2c193e645cf419d1edb.tar.gz
All the tests pass now idk what happened
-rw-r--r--crates/sloth/src/parser/stmt.rs32
1 files 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(),