From 523bd179a45dda293850d320169df75a09109d94 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 1 Dec 2017 02:39:17 -0800 Subject: [PATCH] Tighten code --- src/rukka_lang/mod.rs | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/rukka_lang/mod.rs b/src/rukka_lang/mod.rs index 18cb1b9..d0d2635 100644 --- a/src/rukka_lang/mod.rs +++ b/src/rukka_lang/mod.rs @@ -48,11 +48,8 @@ fn read(input: &str) -> Result, String> { let mut chars: Peekable = 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), +} + +#[derive(Debug)] +enum AtomT { + Symbol(String), + //Number(u64), +} + fn tokenize(input: &mut Peekable) -> Vec { use self::Token::*; let mut tokens = Vec::new(); @@ -111,18 +120,6 @@ fn parse_sexp(tokens: &mut Peekable>) -> Result { Ok(Sexp::List(vec)) } -#[derive(Debug)] -enum Sexp { - Atom(AtomT), - List(Vec), -} - -#[derive(Debug)] -enum AtomT { - Symbol(String), - //Number(u64), -} - #[derive(Debug)] struct PointerList<'a> { next: Option<&'a PointerList<'a>>,