mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-23 07:07:07 +03:00
Add parser support for expression statements
This commit is contained in:
parent
30391c8bd4
commit
a7795b72db
@ -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,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user