1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// support precompiled regexes in reader.rs
#![feature(phase)]
#[phase(plugin)]
extern crate regex_macros;
extern crate regex;
use types::{MalVal,MalRet,MalError,ErrString,ErrMalVal};
mod readline;
mod types;
mod env;
mod reader;
mod printer;
// read
fn read(str: String) -> MalRet {
reader::read_str(str)
}
// eval
fn eval(ast: MalVal) -> MalRet {
Ok(ast)
}
// print
fn print(exp: MalVal) -> String {
exp.pr_str(true)
}
fn rep(str: String) -> Result<String,MalError> {
match read(str) {
Err(e) => Err(e),
Ok(ast) => {
//println!("read: {}", ast);
match eval(ast) {
Err(e) => Err(e),
Ok(exp) => Ok(print(exp)),
}
}
}
}
fn main() {
loop {
let line = readline::mal_readline("user> ");
match line { None => break, _ => () }
match rep(line.unwrap()) {
Ok(str) => println!("{}", str),
Err(ErrMalVal(_)) => (), // Blank line
Err(ErrString(s)) => println!("Error: {}", s),
}
}
}
|