desguar += and -=

This commit is contained in:
2026-06-06 18:53:11 +02:00
parent 535364931e
commit 22874181cd
32 changed files with 185 additions and 146 deletions

View File

@@ -355,6 +355,35 @@ impl Parser {
op,
value,
})
} else if self.match_token(&[TokenType::PlusEqual, TokenType::MinusEqual]) {
let op = self.previous().clone();
let right = self.expression()?;
let binary_token = Token {
token_type: match op.token_type {
TokenType::PlusEqual => TokenType::Plus,
TokenType::MinusEqual => TokenType::Minus,
_ => unreachable!(),
},
lexeme: match op.token_type {
TokenType::PlusEqual => String::from("+"),
TokenType::MinusEqual => String::from("-"),
_ => unreachable!(),
},
loc: op.loc.clone(),
};
Ok(Stmt::Assign {
left: expr.clone(),
op: Token {
token_type: TokenType::Equal,
lexeme: String::from("="),
loc: op.loc,
},
value: Expr::new(ExprKind::Binary {
left: Box::new(expr),
op: binary_token,
right: Box::new(right),
}),
})
} else {
Ok(Stmt::Expression(expr))
}