mirror of
https://github.com/PaddiM8/kalker.git
synced 2025-01-22 21:18:34 +01:00
Added UnsupportedExpression errors.
This commit is contained in:
parent
643509ce4a
commit
f917b744b5
@ -108,6 +108,14 @@ fn invert_binary(
|
|||||||
// If the left expression contains the unit, invert the right one instead,
|
// If the left expression contains the unit, invert the right one instead,
|
||||||
// since the unit should not be moved.
|
// since the unit should not be moved.
|
||||||
if contains_the_unit(symbol_table, left) {
|
if contains_the_unit(symbol_table, left) {
|
||||||
|
// But if the right expression *also* contains the unit,
|
||||||
|
// throw an error, since it can't handle this yet.
|
||||||
|
if contains_the_unit(symbol_table, right) {
|
||||||
|
return Err(CalcError::UnsupportedExpression(String::from(
|
||||||
|
"Can't invert expressions with several instances of an unknown variable (yet).",
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
return Ok(invert(
|
return Ok(invert(
|
||||||
Expr::Binary(Box::new(target_expr), op_inv, Box::new(right.clone())),
|
Expr::Binary(Box::new(target_expr), op_inv, Box::new(right.clone())),
|
||||||
symbol_table,
|
symbol_table,
|
||||||
@ -148,7 +156,9 @@ fn invert_unit(
|
|||||||
_identifier: &str,
|
_identifier: &str,
|
||||||
_expr: &Expr,
|
_expr: &Expr,
|
||||||
) -> Result<(Expr, Expr), CalcError> {
|
) -> Result<(Expr, Expr), CalcError> {
|
||||||
unimplemented!()
|
Err(CalcError::UnsupportedExpression(String::from(
|
||||||
|
"Cannot invert expressions containing other units (yet).",
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn invert_var(
|
fn invert_var(
|
||||||
@ -253,6 +263,9 @@ fn multiply_into(expr: &Expr, base_expr: &Expr) -> Result<Expr, CalcError> {
|
|||||||
TokenKind::Star,
|
TokenKind::Star,
|
||||||
Box::new(base_expr.clone()),
|
Box::new(base_expr.clone()),
|
||||||
)),
|
)),
|
||||||
|
Expr::Group(_) => Err(CalcError::UnsupportedExpression(String::from(
|
||||||
|
"Cannot invert parenthesis multiplied with parenthesis (yet).",
|
||||||
|
))),
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,7 @@ pub enum CalcError {
|
|||||||
UnexpectedToken(TokenKind),
|
UnexpectedToken(TokenKind),
|
||||||
UndefinedFn(String),
|
UndefinedFn(String),
|
||||||
UndefinedVar(String),
|
UndefinedVar(String),
|
||||||
|
UnsupportedExpression(String),
|
||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +96,7 @@ fn print_calc_err(err: CalcError) {
|
|||||||
UnexpectedToken(kind) => format!("Unexpected token: '{:?}'.", kind),
|
UnexpectedToken(kind) => format!("Unexpected token: '{:?}'.", kind),
|
||||||
UndefinedFn(name) => format!("Undefined function: '{}'.", name),
|
UndefinedFn(name) => format!("Undefined function: '{}'.", name),
|
||||||
UndefinedVar(name) => format!("Undefined variable: '{}'.", name),
|
UndefinedVar(name) => format!("Undefined variable: '{}'.", name),
|
||||||
|
UnsupportedExpression(msg) => format!("{}", msg),
|
||||||
Unknown => format!("Unknown error."),
|
Unknown => format!("Unknown error."),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user