Minor cleanup
parent
b4e1fa7690
commit
893dab62c7
|
@ -85,7 +85,7 @@ impl ExprVisitor<Result<EvaluatedValue, ScriptError>> for InterpreterRunner<'_>
|
||||||
) -> Result<EvaluatedValue, ScriptError> {
|
) -> Result<EvaluatedValue, ScriptError> {
|
||||||
let operand = self.visit_expr(expr)?;
|
let operand = self.visit_expr(expr)?;
|
||||||
match operator.kind() {
|
match operator.kind() {
|
||||||
TokenKind::Minus => evaluate_negation(operand, operator),
|
TokenKind::Minus => evaluate_negation(&operand, operator),
|
||||||
TokenKind::Bang => Ok(EvaluatedValue::Boolean(!operand.is_truthy())),
|
TokenKind::Bang => Ok(EvaluatedValue::Boolean(!operand.is_truthy())),
|
||||||
_ => unreachable!(
|
_ => unreachable!(
|
||||||
"attempted to evaluate non-unary operator as unary operator: {:?}",
|
"attempted to evaluate non-unary operator as unary operator: {:?}",
|
||||||
|
@ -274,7 +274,7 @@ fn evaluate_addition(
|
||||||
_ => Err(ScriptError {
|
_ => Err(ScriptError {
|
||||||
line: operator.line(),
|
line: operator.line(),
|
||||||
location: String::new(),
|
location: String::new(),
|
||||||
message: format!("left and right operands must be both numbers or both strings"),
|
message: "left and right operands must be both numbers or both strings".to_string(),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -291,7 +291,7 @@ fn evaluate_binary_arithmetic<F: FnOnce(f64, f64) -> EvaluatedValue>(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn evaluate_negation(
|
fn evaluate_negation(
|
||||||
operand: EvaluatedValue,
|
operand: &EvaluatedValue,
|
||||||
operator: &Token,
|
operator: &Token,
|
||||||
) -> Result<EvaluatedValue, ScriptError> {
|
) -> Result<EvaluatedValue, ScriptError> {
|
||||||
match operand {
|
match operand {
|
||||||
|
@ -299,7 +299,7 @@ fn evaluate_negation(
|
||||||
_ => Err(ScriptError {
|
_ => Err(ScriptError {
|
||||||
line: operator.line(),
|
line: operator.line(),
|
||||||
location: String::new(),
|
location: String::new(),
|
||||||
message: format!("operand must be a number"),
|
message: "operand must be a number".to_string(),
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue