State for eval
This commit is contained in:
parent
ecdcb7ff3d
commit
bf42b58ca5
@ -4,10 +4,14 @@ use std::iter::Peekable;
|
|||||||
use std::vec::IntoIter;
|
use std::vec::IntoIter;
|
||||||
use std::str::Chars;
|
use std::str::Chars;
|
||||||
|
|
||||||
pub struct Rukka { }
|
pub struct EvaluatorState { }
|
||||||
|
|
||||||
|
pub struct Rukka {
|
||||||
|
state: EvaluatorState
|
||||||
|
}
|
||||||
|
|
||||||
impl Rukka {
|
impl Rukka {
|
||||||
pub fn new() -> Rukka { Rukka { } }
|
pub fn new() -> Rukka { Rukka { state: EvaluatorState::new() } }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProgrammingLanguageInterface for Rukka {
|
impl ProgrammingLanguageInterface for Rukka {
|
||||||
@ -30,7 +34,7 @@ impl ProgrammingLanguageInterface for Rukka {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let output_str: String = sexps.into_iter().enumerate().map(|(i, sexp)| {
|
let output_str: String = sexps.into_iter().enumerate().map(|(i, sexp)| {
|
||||||
match eval(sexp) {
|
match self.state.eval(sexp) {
|
||||||
Ok(result) => format!("{}: {}", i, result.print()),
|
Ok(result) => format!("{}: {}", i, result.print()),
|
||||||
Err(err) => format!("{} Error: {}", i, err),
|
Err(err) => format!("{} Error: {}", i, err),
|
||||||
}
|
}
|
||||||
@ -40,7 +44,10 @@ impl ProgrammingLanguageInterface for Rukka {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eval(expr: Sexp) -> Result<Sexp, String> {
|
|
||||||
|
impl EvaluatorState {
|
||||||
|
fn new() -> EvaluatorState { EvaluatorState { } }
|
||||||
|
fn eval(&mut self, expr: Sexp) -> Result<Sexp, String> {
|
||||||
use self::Sexp::*; use self::AtomT::*;
|
use self::Sexp::*; use self::AtomT::*;
|
||||||
Ok(match expr {
|
Ok(match expr {
|
||||||
Atom(atom) => match atom {
|
Atom(atom) => match atom {
|
||||||
@ -51,6 +58,7 @@ fn eval(expr: Sexp) -> Result<Sexp, String> {
|
|||||||
List(items) => unimplemented!(),
|
List(items) => unimplemented!(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn read(input: &str) -> Result<Vec<Sexp>, String> {
|
fn read(input: &str) -> Result<Vec<Sexp>, String> {
|
||||||
let mut chars: Peekable<Chars> = input.chars().peekable();
|
let mut chars: Peekable<Chars> = input.chars().peekable();
|
||||||
|
Loading…
Reference in New Issue
Block a user