diff --git a/asklyphe-frontend/src/math.rs b/asklyphe-frontend/src/math.rs index 3f100c4..4e15f72 100644 --- a/asklyphe-frontend/src/math.rs +++ b/asklyphe-frontend/src/math.rs @@ -10,12 +10,13 @@ pub struct Calculation { pub fn calculate(query: &str) -> Option { debug!("Got query {}", query); let mut parser = Parser::new(Lexer::new(query)); - let res = parser.parse()?; + let tree = parser.parse()?; + let res = tree.eval(); debug!("Calculation: {}", query); - debug!("Tree: {:?}", res); - debug!("Result: {}", res.eval()); - None + debug!("Tree: {:?}", tree); + debug!("Result: {}", res); + Some(Calculation {equation: query.to_string(), result: res.to_string()}) } // TODO: put into own crate with dependency astro-float = "0.9.2" so I can use more than f64 @@ -45,7 +46,7 @@ impl Op { BinOp::Divide => 2.0, BinOp::Exponent => 3.0, }, - Op::Func(_) => 0.9, // TODO: decide if this is a good LBP + Op::Func(_) => 0.0, // TODO: decide if this is a good LBP } } diff --git a/asklyphe-frontend/templates/search_js.html b/asklyphe-frontend/templates/search_js.html index ea00300..6e166db 100644 --- a/asklyphe-frontend/templates/search_js.html +++ b/asklyphe-frontend/templates/search_js.html @@ -67,6 +67,13 @@ {% when None %} {% endmatch %} + {% match complications.math %} + {% when Some with (math) %} +
+

{{ math.equation }} = {{ math.result }}

+
+ {% when None %} + {% endmatch %} {% endmatch %}