mirror of
https://github.com/TheM1Stery/izanami.git
synced 2025-04-19 16:31:11 +00:00
Compare commits
2 Commits
be15364e3b
...
3cfde406d3
Author | SHA1 | Date | |
---|---|---|---|
3cfde406d3 | |||
2d1701e7f7 |
@ -62,12 +62,14 @@ fn binary(
|
||||
(Minus, Number(left), Number(right)) => Ok(Number(left - right)),
|
||||
(Plus, Number(left), Number(right)) => Ok(Number(left + right)),
|
||||
(Plus, String(left), String(right)) => Ok(String(format!("{left}{right}"))),
|
||||
(Plus, String(left), Number(right)) => Ok(String(format!("{left}{right}"))),
|
||||
(Plus, Number(left), String(right)) => Ok(String(format!("{left}{right}"))),
|
||||
(Slash, Number(left), Number(right)) => Ok(Number(left / right)),
|
||||
(Star, Number(left), Number(right)) => Ok(Number(left * right)),
|
||||
/* comma operator discard the left operand, so we just return the evaluation of the right operand */
|
||||
(Comma, _,_) => Ok(right.clone()),
|
||||
(Greater | GreaterEqual | Less | LessEqual | Minus | Slash | Star, _, _) => Err(RuntimeError::new(op, "Operands must be numbers")),
|
||||
(Plus, _, _) => Err(RuntimeError::new(op, "Operands must be two numbers or two strings")),
|
||||
/* comma operator discard the left operand, so we just return the evaluation of the right operand */
|
||||
|
||||
_ => unreachable!("Shouldn't happen. Expr::Binary for interpret. Some case is a binary operation that wasn't matched")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user