Tighten code

This commit is contained in:
greg 2017-12-01 02:39:17 -08:00
parent b1da524a8f
commit 9e8a3d1f08

View File

@ -48,11 +48,8 @@ fn read(input: &str) -> Result<Vec<Sexp>, String> {
let mut chars: Peekable<Chars> = input.chars().peekable(); let mut chars: Peekable<Chars> = input.chars().peekable();
let mut tokens = tokenize(&mut chars).into_iter().peekable(); let mut tokens = tokenize(&mut chars).into_iter().peekable();
let mut sexps = Vec::new(); let mut sexps = Vec::new();
loop { while let Some(_) = tokens.peek() {
sexps.push(parse(&mut tokens)?); sexps.push(parse(&mut tokens)?);
if let None = tokens.peek() {
break;
}
} }
Ok(sexps) Ok(sexps)
} }
@ -64,6 +61,18 @@ enum Token {
Symbol(String) Symbol(String)
} }
#[derive(Debug)]
enum Sexp {
Atom(AtomT),
List(Vec<Sexp>),
}
#[derive(Debug)]
enum AtomT {
Symbol(String),
//Number(u64),
}
fn tokenize(input: &mut Peekable<Chars>) -> Vec<Token> { fn tokenize(input: &mut Peekable<Chars>) -> Vec<Token> {
use self::Token::*; use self::Token::*;
let mut tokens = Vec::new(); let mut tokens = Vec::new();
@ -111,18 +120,6 @@ fn parse_sexp(tokens: &mut Peekable<IntoIter<Token>>) -> Result<Sexp, String> {
Ok(Sexp::List(vec)) Ok(Sexp::List(vec))
} }
#[derive(Debug)]
enum Sexp {
Atom(AtomT),
List(Vec<Sexp>),
}
#[derive(Debug)]
enum AtomT {
Symbol(String),
//Number(u64),
}
#[derive(Debug)] #[derive(Debug)]
struct PointerList<'a> { struct PointerList<'a> {
next: Option<&'a PointerList<'a>>, next: Option<&'a PointerList<'a>>,