Skip to content

Commit

Permalink
fix(parser): infinite loop on missing semicolon
Browse files Browse the repository at this point in the history
Signed-off-by: Prajwal S N <[email protected]>
  • Loading branch information
snprajwal committed Dec 22, 2023
1 parent fea68dd commit 3a06690
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions lost_syntax/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,40 +448,39 @@ impl<'a> Parser<'a> {
fn parse_func_call(&mut self) -> Result<Expr, Error> {
let mut expr = self.parse_primary()?;
loop {
if let Some(t) = self.stream.peek() {
match t.kind {
TokenKind::LPAREN => {
// Consume the opening parenthesis
self.advance();
let mut args = vec![];
if self.advance_if(|t| t.kind == TokenKind::RPAREN).is_none() {
loop {
args.push(self.parse_expr()?);
if self.advance_if(|t| t.kind == TokenKind::COMMA).is_none() {
break;
}
let Some(t) = self.stream.peek() else { break };
match t.kind {
TokenKind::LPAREN => {
// Consume the opening parenthesis
self.advance();
let mut args = vec![];
if self.advance_if(|t| t.kind == TokenKind::RPAREN).is_none() {
loop {
args.push(self.parse_expr()?);
if self.advance_if(|t| t.kind == TokenKind::COMMA).is_none() {
break;
}
// Consume the closing parenthesis
self.advance_or_err(TokenKind::RPAREN, ErrorMsg::MissingClosingParen)?;
}
expr = Expr::Call {
func: Box::new(expr),
args,
};
// Consume the closing parenthesis
self.advance_or_err(TokenKind::RPAREN, ErrorMsg::MissingClosingParen)?;
}
TokenKind::DOT => {
// Consume the dot
self.advance();
expr = Expr::FieldGet {
object: Box::new(expr),
field: Literal::Ident(
self.advance_or_err(TokenKind::IDENT, ErrorMsg::InvalidIdent)?
.lexeme,
),
}
expr = Expr::Call {
func: Box::new(expr),
args,
};
}
TokenKind::DOT => {
// Consume the dot
self.advance();
expr = Expr::FieldGet {
object: Box::new(expr),
field: Literal::Ident(
self.advance_or_err(TokenKind::IDENT, ErrorMsg::InvalidIdent)?
.lexeme,
),
}
_ => break,
}
_ => break,
}
}

Expand Down

0 comments on commit 3a06690

Please sign in to comment.