diff options
author | NerdyPepper <[email protected]> | 2019-03-29 14:41:16 +0000 |
---|---|---|
committer | NerdyPepper <[email protected]> | 2019-03-29 14:41:16 +0000 |
commit | 89c3377d06297fdbca376f2d03e53c4af0d6709c (patch) | |
tree | a668aa6e748341e1b10876156c89f9c8a41d12ea | |
parent | 0f4443d171ebde023fd0bd58b8499e363dd7f35f (diff) |
handle empty lines
-rw-r--r-- | src/main.rs | 4 |
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 | ||
37 | fn main() { | 37 | fn 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 | ||
116 | fn eval_math_expression(input: &str) -> Result<f64, CalcError> { | 117 | fn 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)?; |