semi-colons working after function invocations

This commit is contained in:
2024-11-22 22:02:40 -07:00
parent b5ee169a75
commit 856e51a384
2 changed files with 17 additions and 10 deletions

View File

@@ -128,7 +128,13 @@ impl Parser {
/// Parses the input from the tokenizer buffer and returns the resulting expression
pub fn parse(&mut self) -> Result<Option<tree_node::Expression>, 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()?);