Add augmented assignment operators for set statements
This allows us to do things like
self.foo += 5
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -587,13 +587,24 @@ impl Parser {
|
||||
let expr = self.expr()?;
|
||||
let stmt: StmtP;
|
||||
|
||||
if expr.as_any_ref().downcast_ref::<GetExpr>().is_some() && self.mat(TokenKind::Eq)? {
|
||||
if expr.as_any_ref().downcast_ref::<GetExpr>().is_some()
|
||||
&& mat!(
|
||||
self,
|
||||
TokenKind::Eq,
|
||||
TokenKind::PlusEq,
|
||||
TokenKind::MinusEq,
|
||||
TokenKind::StarEq,
|
||||
TokenKind::SlashEq
|
||||
)
|
||||
{
|
||||
let op = self.prev.clone().unwrap();
|
||||
let expr = expr.as_any().downcast::<GetExpr>().unwrap();
|
||||
let rhs = self.expr()?;
|
||||
// unpack the GetExpr and turn it into a SetExpr instead
|
||||
stmt = Box::new(SetStmt {
|
||||
expr: expr.expr,
|
||||
name: expr.name,
|
||||
op,
|
||||
rhs,
|
||||
});
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user