Tighten code
This commit is contained in:
parent
35e715dfd6
commit
523bd179a4
@ -48,11 +48,8 @@ fn read(input: &str) -> Result<Vec<Sexp>, String> {
|
||||
let mut chars: Peekable<Chars> = input.chars().peekable();
|
||||
let mut tokens = tokenize(&mut chars).into_iter().peekable();
|
||||
let mut sexps = Vec::new();
|
||||
loop {
|
||||
while let Some(_) = tokens.peek() {
|
||||
sexps.push(parse(&mut tokens)?);
|
||||
if let None = tokens.peek() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(sexps)
|
||||
}
|
||||
@ -64,6 +61,18 @@ enum Token {
|
||||
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> {
|
||||
use self::Token::*;
|
||||
let mut tokens = Vec::new();
|
||||
@ -111,18 +120,6 @@ fn parse_sexp(tokens: &mut Peekable<IntoIter<Token>>) -> Result<Sexp, String> {
|
||||
Ok(Sexp::List(vec))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Sexp {
|
||||
Atom(AtomT),
|
||||
List(Vec<Sexp>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum AtomT {
|
||||
Symbol(String),
|
||||
//Number(u64),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct PointerList<'a> {
|
||||
next: Option<&'a PointerList<'a>>,
|
||||
|
Loading…
Reference in New Issue
Block a user