aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/math/expression.rs19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/math/expression.rs b/src/math/expression.rs
index 14a3eb8..63255d0 100644
--- a/src/math/expression.rs
+++ b/src/math/expression.rs
@@ -1,8 +1,8 @@
use super::complex::Complex;
use super::context::Context;
use super::function::FunctionArgument;
-use super::string::{ContainsAndSkipBrackets, SplitMatchingBracket};
use super::operation::Operation;
+use super::string::{ContainsAndSkipBrackets, SplitMatchingBracket};
#[derive(PartialEq, Eq, Hash, Clone)]
enum ExpressionType {
@@ -43,7 +43,7 @@ impl Expression {
let (oprepr, r) = self.repr.split_on_matching_bracket();
if r.is_empty() {
let repr = oprepr[1..oprepr.len() - 1].to_string();
- (repr.clone(), repr)
+ (repr.to_string(), repr)
} else {
(self.repr.to_string(), r.to_string())
}
@@ -55,7 +55,10 @@ impl Expression {
let curop: Option<_> = {
let mut o = None;
for op in operations {
- if oprepr.contains_and_skip_brackets(op.sign().to_string().as_str()) {
+ if oprepr
+ .to_string()
+ .contains_and_skip_brackets(op.sign().to_string().as_str())
+ {
o = Some(op);
break;
}
@@ -67,7 +70,8 @@ impl Expression {
let (first, rest) = repr.split_once_and_skipt_brackets(op.sign()).unwrap();
let first_expr = Expression::from_string(first, operations);
let rest_expr = Expression::from_string(rest, operations);
- self.expr_type = ExpressionType::Operation(op.clone(), Box::new(first_expr), Box::new(rest_expr));
+ self.expr_type =
+ ExpressionType::Operation(op.clone(), Box::new(first_expr), Box::new(rest_expr));
} else if let Ok(r) = repr.parse::<Complex>() {
self.expr_type = ExpressionType::Value(r);
} else if let Some((func, args)) = repr.split_once('(') {
@@ -77,7 +81,10 @@ impl Expression {
argv.push(Expression::from_string(arg, operations));
}
- self.expr_type = ExpressionType::Function(func.to_string(), FunctionArgument::from_expressions(argv));
+ self.expr_type = ExpressionType::Function(
+ func.to_string(),
+ FunctionArgument::from_expressions(argv),
+ );
} else {
self.expr_type = ExpressionType::Variable(repr);
}
@@ -92,7 +99,7 @@ impl Expression {
} else {
Err(format!("variable '{var}' not found"))
}
- },
+ }
ExpressionType::Function(func, args) => {
if let Some(f) = ctx.function(&func) {
f.eval(args, ctx)