Some more code

This commit is contained in:
greg 2017-12-04 01:57:24 -08:00
parent 2f8ef99b08
commit a1e38aba8e

View File

@ -44,7 +44,6 @@ impl ProgrammingLanguageInterface for Rukka {
}
}
impl EvaluatorState {
fn new() -> EvaluatorState { EvaluatorState { } }
fn eval(&mut self, expr: Sexp) -> Result<Sexp, String> {
@ -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!()
}
}
})
}
}
@ -162,6 +173,7 @@ fn parse(tokens: &mut Peekable<IntoIter<Token>>) -> Result<Sexp, String> {
fn parse_sexp(tokens: &mut Peekable<IntoIter<Token>>) -> Result<Sexp, String> {
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<IntoIter<Token>>) -> Result<Sexp, String> {
_ => vec.push(parse(tokens)?),
}
}
Ok(Sexp::List(vec))
Ok(List(vec))
}