aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorNerdyPepper <[email protected]>2019-03-29 14:41:16 +0000
committerNerdyPepper <[email protected]>2019-03-29 14:41:16 +0000
commit89c3377d06297fdbca376f2d03e53c4af0d6709c (patch)
treea668aa6e748341e1b10876156c89f9c8a41d12ea /src/main.rs
parent0f4443d171ebde023fd0bd58b8499e363dd7f35f (diff)
handle empty lines
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index ddad9b4..c111bf1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -35,6 +35,7 @@ use rustyline::config::{ Builder, ColorMode, EditMode };
35 35
36 36
37fn main() { 37fn main() {
38
38 let args: Vec<String> = env::args().collect(); 39 let args: Vec<String> = env::args().collect();
39 if args.len() > 1 { 40 if args.len() > 1 {
40 let mut expr = String::new(); 41 let mut expr = String::new();
@@ -114,6 +115,9 @@ fn autobalance_parens(input: &str) -> Result<String, CalcError> {
114} 115}
115 116
116fn eval_math_expression(input: &str) -> Result<f64, CalcError> { 117fn eval_math_expression(input: &str) -> Result<f64, CalcError> {
118 if input.len() == 0 {
119 return Ok(0.)
120 }
117 let input = autobalance_parens(&input[..])?; 121 let input = autobalance_parens(&input[..])?;
118 let lexed = lexer(&input[..])?; 122 let lexed = lexer(&input[..])?;
119 let postfixed = to_postfix(lexed)?; 123 let postfixed = to_postfix(lexed)?;