diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 00d8b7e..9906fe4 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -128,7 +128,13 @@ impl Parser { /// Parses the input from the tokenizer buffer and returns the resulting expression pub fn parse(&mut self) -> Result, ParseError> { self.assign_next()?; - self.expression() + let expr = self.expression()?; + + if self_matches_peek!(self, TokenType::Symbol(Symbol::Semicolon)) { + self.assign_next()?; + } + + Ok(expr) } /// Assigns the next token in the tokenizer buffer to the current token @@ -426,7 +432,8 @@ impl Parser { }); } - let expression = self.parse()?.ok_or(ParseError::UnexpectedEOF)?; + self.assign_next()?; + let expression = self.expression()?.ok_or(ParseError::UnexpectedEOF)?; let current_token = token_from_option!(self.get_next()?); if !token_matches!(current_token, TokenType::Symbol(Symbol::RParen)) { @@ -511,14 +518,13 @@ impl Parser { }); } - while !token_matches!( - token_from_option!(self.get_next()?), - TokenType::Symbol(Symbol::RBrace) - ) { - let expression = self.expression()?.ok_or(ParseError::UnexpectedEOF)?; + while !self_matches_peek!(self, TokenType::Symbol(Symbol::RBrace)) { + let expression = self.parse()?.ok_or(ParseError::UnexpectedEOF)?; expressions.push(expression); } + self.assign_next()?; + Ok(BlockExpression(expressions)) } @@ -545,7 +551,8 @@ impl Parser { }); } - let assignment_expression = self.parse()?.ok_or(ParseError::UnexpectedEOF)?; + self.assign_next()?; + let assignment_expression = self.expression()?.ok_or(ParseError::UnexpectedEOF)?; // make sure the next token is a semi-colon let current_token = token_from_option!(self.get_next()?); diff --git a/tests/file.stlg b/tests/file.stlg index 10ac01f..208005d 100644 --- a/tests/file.stlg +++ b/tests/file.stlg @@ -10,5 +10,5 @@ fn doThings(x, y, z) { fn main() { - doThings(1, 2, 3) -} \ No newline at end of file + doThings(1, 2, 3); +}