This has broken sexp parsing
This commit is contained in:
parent
844cef36c7
commit
9273773bf4
@ -49,16 +49,25 @@ impl EvaluatorState {
|
|||||||
fn new() -> EvaluatorState { EvaluatorState { } }
|
fn new() -> EvaluatorState { EvaluatorState { } }
|
||||||
fn eval(&mut self, expr: Sexp) -> Result<Sexp, String> {
|
fn eval(&mut self, expr: Sexp) -> Result<Sexp, String> {
|
||||||
use self::Sexp::*;
|
use self::Sexp::*;
|
||||||
|
println!("Eval'd sexp: {:?}", expr);
|
||||||
Ok(match expr {
|
Ok(match expr {
|
||||||
SymbolAtom(sym) => unimplemented!(),
|
SymbolAtom(sym) => unimplemented!(),
|
||||||
expr @ StringAtom(_) => expr,
|
expr @ StringAtom(_) => expr,
|
||||||
expr @ NumberAtom(_) => expr,
|
expr @ NumberAtom(_) => expr,
|
||||||
Cons(car, cdr) => {
|
Cons(box car, box cdr) => {
|
||||||
match *car {
|
match car {
|
||||||
SymbolAtom(ref sym) => match &sym[..] {
|
SymbolAtom(ref sym) => match &sym[..] {
|
||||||
"quote" => *cdr,
|
"quote" => cdr,
|
||||||
"eq?" => unimplemented!(),
|
"eq?" => unimplemented!(),
|
||||||
"cons" => unimplemented!(),
|
"cons" => match cdr {
|
||||||
|
Cons(box cadr, box Cons(box caddr, box Nil)) => {
|
||||||
|
println!("NEWL {:?}|| NEWR {:?}", cadr, caddr);
|
||||||
|
let newl = self.eval(cadr)?;
|
||||||
|
let newr = self.eval(caddr)?;
|
||||||
|
Cons(Box::new(newl), Box::new(newr))
|
||||||
|
},
|
||||||
|
_ => return Err(format!("Bad arguments for cons")),
|
||||||
|
},
|
||||||
"car" => unimplemented!(),
|
"car" => unimplemented!(),
|
||||||
"cdr" => unimplemented!(),
|
"cdr" => unimplemented!(),
|
||||||
"atom?" => unimplemented!(),
|
"atom?" => unimplemented!(),
|
||||||
@ -67,7 +76,7 @@ impl EvaluatorState {
|
|||||||
"cond" => unimplemented!(),
|
"cond" => unimplemented!(),
|
||||||
x => unimplemented!(),
|
x => unimplemented!(),
|
||||||
},
|
},
|
||||||
_ => unimplemented!()
|
other => {println!("OTHER? {:?}", other); unimplemented!() }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Nil => Nil,
|
Nil => Nil,
|
||||||
@ -185,7 +194,7 @@ fn parse_sexp(tokens: &mut Peekable<IntoIter<Token>>) -> Result<Sexp, String> {
|
|||||||
None => return Err(format!("Unexpected end of input")),
|
None => return Err(format!("Unexpected end of input")),
|
||||||
Some(&RParen) => { tokens.next(); break},
|
Some(&RParen) => { tokens.next(); break},
|
||||||
_ => {
|
_ => {
|
||||||
cell = Cons(Box::new(parse(tokens)?), Box::new(cell));
|
cell = Cons(Box::new(cell), Box::new(parse(tokens)?));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user