From 2ffb5357e0e35d415311a40eea14e9cc99dd54ab Mon Sep 17 00:00:00 2001 From: Dominick Allen Date: Sun, 28 Jun 2020 19:50:35 -0500 Subject: Improve read functionality. --- src/lib/eval/arith.rs | 5 +++-- src/lib/tokenize.rs | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'src/lib') diff --git a/src/lib/eval/arith.rs b/src/lib/eval/arith.rs index fe3a06b..d7d53e0 100644 --- a/src/lib/eval/arith.rs +++ b/src/lib/eval/arith.rs @@ -1,10 +1,11 @@ use std::ops::{Add, Sub, Mul, Div}; use super::super::types::Type; +use super::super::types::FloatType; use super::super::types::Number; fn apply_arithmetic( func_i: fn(isize, isize) -> isize, - func_f: fn(f32, f32) -> f32, + func_f: fn(FloatType, FloatType) -> FloatType, operand_a: &Type, operand_b: &Type) -> Result { @@ -17,7 +18,7 @@ fn apply_arithmetic( (Type::Number(Number::Int(i)), Type::Number(Number::Float(f))) | (Type::Number(Number::Float(f)), Type::Number(Number::Int(i))) => { - Ok(Type::Number(Number::Float(func_f(*f, *i as f32)))) + Ok(Type::Number(Number::Float(func_f(*f, *i as FloatType)))) }, (Type::Number(Number::Int(a)), Type::Number(Number::Int(b))) => { diff --git a/src/lib/tokenize.rs b/src/lib/tokenize.rs index 0a50036..483536f 100644 --- a/src/lib/tokenize.rs +++ b/src/lib/tokenize.rs @@ -1,4 +1,5 @@ use super::types::Type; +use super::types::FloatType; use super::types::Number; use super::types::Op; use super::sexpr::SExpr; @@ -242,7 +243,7 @@ pub fn is_int(word: &str) -> MaybeToken { } pub fn is_float(word: &str) -> MaybeToken { - match word.parse::() { + match word.parse::() { Ok(x) => (Some(Ok(Token::Value(Type::Number(Number::Float(x))))), word.len()), _ => (None, 0) } @@ -268,7 +269,7 @@ pub fn descend(tokenstream: &mut TokenStream) -> Result { let token = match tokenstream.next() { Some(Ok(x)) => x, Some(Err(f)) => return Err(f), - None => panic!("Empty string".to_string()) + None => return Err("Unexpected end of expression".to_string()) }; match token { -- cgit v1.2.3