aboutsummaryrefslogtreecommitdiff
path: root/src/lex
diff options
context:
space:
mode:
authorIvan Tham <[email protected]>2019-08-03 06:49:17 +0100
committerIvan Tham <[email protected]>2019-08-03 06:49:17 +0100
commit6c38d9b13b8e1cc976f9b22d15d100fd03ee54d4 (patch)
treea4f0ae975f768031315ff59e6f5a24fac361a087 /src/lex
parent8b49603f0c6d06bcb444bd0ee14aa5c1fbc4648c (diff)
Reuse ans output and fix tests
Diffstat (limited to 'src/lex')
-rw-r--r--src/lex/mod.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/lex/mod.rs b/src/lex/mod.rs
index cac16ca..caafd4b 100644
--- a/src/lex/mod.rs
+++ b/src/lex/mod.rs
@@ -122,7 +122,7 @@ fn factorial (n: f64) -> f64 {
122 n.signum() * (1.. n.abs() as u64 +1).fold(1, |p, n| p*n) as f64 122 n.signum() * (1.. n.abs() as u64 +1).fold(1, |p, n| p*n) as f64
123} 123}
124 124
125pub fn lexer(input: &str, prev_ans: &mut f64) -> Result<Vec<Token>, CalcError> { 125pub fn lexer(input: &str, prev_ans: f64) -> Result<Vec<Token>, CalcError> {
126 let functions: HashMap<&str, Token> = get_functions(); 126 let functions: HashMap<&str, Token> = get_functions();
127 let operators: HashMap<char, Token> = get_operators(); 127 let operators: HashMap<char, Token> = get_operators();
128 128
@@ -159,7 +159,7 @@ pub fn lexer(input: &str, prev_ans: &mut f64) -> Result<Vec<Token>, CalcError> {
159 num_vec.clear(); 159 num_vec.clear();
160 } 160 }
161 last_char_is_op = false; 161 last_char_is_op = false;
162 result.push(Token::Num(*prev_ans)); 162 result.push(Token::Num(prev_ans));
163 } 163 }
164 'a'...'z' | 'A'...'Z' => { 164 'a'...'z' | 'A'...'Z' => {
165 let parse_num = num_vec.parse::<f64>().ok(); 165 let parse_num = num_vec.parse::<f64>().ok();