From 8749ed984d3f9b6c6b6268ad170da0c82ff6e4df Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 4 Dec 2017 01:57:24 -0800 Subject: [PATCH] Some more code --- src/rukka_lang/mod.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/rukka_lang/mod.rs b/src/rukka_lang/mod.rs index 3688c16..7c06009 100644 --- a/src/rukka_lang/mod.rs +++ b/src/rukka_lang/mod.rs @@ -44,7 +44,6 @@ impl ProgrammingLanguageInterface for Rukka { } } - impl EvaluatorState { fn new() -> EvaluatorState { EvaluatorState { } } fn eval(&mut self, expr: Sexp) -> Result { @@ -53,7 +52,19 @@ impl EvaluatorState { SymbolAtom(sym) => unimplemented!(), expr @ StringAtom(_) => expr, expr @ NumberAtom(_) => expr, - List(items) => unimplemented!(), + List(items) => { + if items.len() == 0 { + return Err(format!("Empty list")) + } + let ref first = items[0]; + match first { + &SymbolAtom(ref sym) => match &sym[..] { + "quote" => unimplemented!(), + _ => unimplemented!(), + }, + _ => unimplemented!() + } + } }) } } @@ -152,8 +163,8 @@ fn parse(tokens: &mut Peekable>) -> Result { Some(LParen) => parse_sexp(tokens), Some(RParen) => Err(format!("Unexpected ')'")), Some(Quote) => { - let quoted = parse(tokens)?; - Ok(List(vec![SymbolAtom(format!("quote")), quoted])) + let quoted = parse(tokens)?; + Ok(List(vec![SymbolAtom(format!("quote")), quoted])) }, Some(NumLiteral(n)) => Ok(NumberAtom(n)), None => Err(format!("Unexpected end of input")), @@ -162,6 +173,7 @@ fn parse(tokens: &mut Peekable>) -> Result { fn parse_sexp(tokens: &mut Peekable>) -> Result { use self::Token::*; + use self::Sexp::*; let mut vec = Vec::new(); loop { match tokens.peek() { @@ -170,6 +182,6 @@ fn parse_sexp(tokens: &mut Peekable>) -> Result { _ => vec.push(parse(tokens)?), } } - Ok(Sexp::List(vec)) + Ok(List(vec)) }