Add parser support for expression statements

This commit is contained in:
d0cd 2022-10-21 18:00:13 -07:00
parent 30391c8bd4
commit a7795b72db
2 changed files with 6 additions and 13 deletions

View File

@ -99,11 +99,12 @@ impl ParserContext<'_> {
Ok(Statement::Assign(Box::new(AssignStatement { span, place, value })))
} else {
// Error on `expr;` but recover as an empty block `{}`.
self.expect(&Token::Semicolon)?;
let span = place.span() + self.prev_token.span;
self.emit_err(ParserError::expr_stmts_disallowed(span));
Ok(Statement::dummy(span))
// Parse the expression as a statement.
let end = self.expect(&Token::Semicolon)?;
Ok(Statement::Expression(ExpressionStatement {
span: place.span() + end,
expression: place,
}))
}
}

View File

@ -199,14 +199,6 @@ create_messages!(
help: None,
}
/// Parsed an expression statement.
@formatted
expr_stmts_disallowed {
args: (),
msg: "Expression statements are not supported.",
help: None,
}
/// Parsed an unknown method call on the type of an expression.
@formatted
invalid_method_call {