aboutsummaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
Diffstat (limited to 'src/math')
-rw-r--r--src/math/expression_function.rs26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/math/expression_function.rs b/src/math/expression_function.rs
index 44f83d1..b9a480f 100644
--- a/src/math/expression_function.rs
+++ b/src/math/expression_function.rs
@@ -17,19 +17,23 @@ pub struct ExpressionFunction {
}
impl ExpressionFunction {
- pub fn from_string(str: String, operations: &Vec<Operation>) -> Self {
+ pub fn from_string(str: String, operations: &Vec<Operation>) -> Result<Self, ()> {
let str = str.replace(' ', "");
- let (lhs, expr) = str.split_once('=').unwrap();
- let (name, a) = lhs.split_once('(').unwrap();
- let args: Vec<String> = a[0..a.len() - 1]
- .split(',')
- .map(|s| s.to_string())
- .collect();
- Self {
- expr: Expression::from_string(expr, operations),
- name: name.to_string(),
- args,
+ if let Some((lhs, expr)) = str.split_once('=') {
+ if let Some((name, a)) = lhs.split_once('(') {
+ let args: Vec<String> = a[0..a.len() - 1]
+ .split(',')
+ .map(|s| s.to_string())
+ .collect();
+
+ return Ok(Self {
+ expr: Expression::from_string(expr, operations),
+ name: name.to_string(),
+ args,
+ })
+ }
}
+ Err(())
}
pub fn name(&self) -> &str {