diff options
author | Dominick Allen <dominick.allen1989@gmail.com> | 2020-06-26 21:12:16 -0500 |
---|---|---|
committer | Dominick Allen <dominick.allen1989@gmail.com> | 2020-06-26 21:12:16 -0500 |
commit | ad9f7e6a689c7fe42444cbe22ecdf1de8d092d5b (patch) | |
tree | f387be46e818cdfafeae36c69a94d09ed1da26f9 /src/lib/parse.rs | |
parent | 36e1bf722a3d366cea20ab7315d63d588d23dc48 (diff) |
Evaluate basic arithmetic.
Diffstat (limited to 'src/lib/parse.rs')
-rw-r--r-- | src/lib/parse.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/lib/parse.rs b/src/lib/parse.rs index 8e9c785..047b374 100644 --- a/src/lib/parse.rs +++ b/src/lib/parse.rs @@ -1,7 +1,7 @@ use super::types::Type; use super::types::Number; use super::types::Op; -use super::types::SEXP; +use super::sexpr::SExpr; pub type MaybeToken = (Option<Result<Token, String>>, usize); @@ -250,7 +250,7 @@ pub fn is_float(word: &str) -> MaybeToken { } } -pub fn parse(expr: &str) -> Result<SEXP, String> { +pub fn parse(expr: &str) -> Result<SExpr, String> { let mut tokenstream = TokenStream::default(expr); match tokenstream.peek() { Some(Ok(Token::LParen)) => { @@ -258,13 +258,13 @@ pub fn parse(expr: &str) -> Result<SEXP, String> { descend(&mut tokenstream) }, Some(Ok(Token::RParen)) => Err("Malformed expression".to_string()), - Some(Ok(Token::Value(x))) => Ok(SEXP::Atom(x)), + Some(Ok(Token::Value(x))) => Ok(SExpr::Atom(x)), Some(Err(f)) => Err(f), None => Err("Empty expression".to_string()) } } -pub fn descend(tokenstream: &mut TokenStream) -> Result<SEXP, String> { +pub fn descend(tokenstream: &mut TokenStream) -> Result<SExpr, String> { let mut sexp = Vec::new(); loop { let token = match tokenstream.next() { @@ -286,11 +286,11 @@ pub fn descend(tokenstream: &mut TokenStream) -> Result<SEXP, String> { break; }, Token::Value(atom) => { - sexp.push(SEXP::Atom(atom)); + sexp.push(SExpr::Atom(atom)); continue; } } } - Ok(SEXP::Sexpr(sexp)) + Ok(SExpr::Sexpr(sexp)) } |