diff --git a/kalk/src/inverter.rs b/kalk/src/inverter.rs index ffdd22e..d9965d4 100644 --- a/kalk/src/inverter.rs +++ b/kalk/src/inverter.rs @@ -108,6 +108,14 @@ fn invert_binary( // If the left expression contains the unit, invert the right one instead, // since the unit should not be moved. 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( Expr::Binary(Box::new(target_expr), op_inv, Box::new(right.clone())), symbol_table, @@ -148,7 +156,9 @@ fn invert_unit( _identifier: &str, _expr: &Expr, ) -> Result<(Expr, Expr), CalcError> { - unimplemented!() + Err(CalcError::UnsupportedExpression(String::from( + "Cannot invert expressions containing other units (yet).", + ))) } fn invert_var( @@ -253,6 +263,9 @@ fn multiply_into(expr: &Expr, base_expr: &Expr) -> Result { TokenKind::Star, Box::new(base_expr.clone()), )), + Expr::Group(_) => Err(CalcError::UnsupportedExpression(String::from( + "Cannot invert parenthesis multiplied with parenthesis (yet).", + ))), _ => unimplemented!(), } } diff --git a/kalk/src/parser.rs b/kalk/src/parser.rs index e78aa28..0dd94d2 100644 --- a/kalk/src/parser.rs +++ b/kalk/src/parser.rs @@ -70,6 +70,7 @@ pub enum CalcError { UnexpectedToken(TokenKind), UndefinedFn(String), UndefinedVar(String), + UnsupportedExpression(String), Unknown, } diff --git a/kalk_cli/src/output.rs b/kalk_cli/src/output.rs index ba7260a..984b0f0 100644 --- a/kalk_cli/src/output.rs +++ b/kalk_cli/src/output.rs @@ -96,6 +96,7 @@ fn print_calc_err(err: CalcError) { UnexpectedToken(kind) => format!("Unexpected token: '{:?}'.", kind), UndefinedFn(name) => format!("Undefined function: '{}'.", name), UndefinedVar(name) => format!("Undefined variable: '{}'.", name), + UnsupportedExpression(msg) => format!("{}", msg), Unknown => format!("Unknown error."), }); }