aboutsummaryrefslogtreecommitdiff
path: root/rust/src/step1_read_print.rs
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-10-25 11:42:07 -0500
committerJoel Martin <github@martintribe.org>2015-01-06 21:58:35 -0600
commitabdd56ebc0e01cd92f694ef2bcafcc394453d055 (patch)
treed1ace96ac90e5d888e4d4d05dd4ca0c0445a856e /rust/src/step1_read_print.rs
parentf41866dbe99080f0916512261f0412c5bc65f190 (diff)
downloadmal-abdd56ebc0e01cd92f694ef2bcafcc394453d055.tar.gz
mal-abdd56ebc0e01cd92f694ef2bcafcc394453d055.zip
Rust: step0_repl and step1_read_print
Diffstat (limited to 'rust/src/step1_read_print.rs')
-rw-r--r--rust/src/step1_read_print.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/rust/src/step1_read_print.rs b/rust/src/step1_read_print.rs
new file mode 100644
index 0000000..c6f87d0
--- /dev/null
+++ b/rust/src/step1_read_print.rs
@@ -0,0 +1,51 @@
+// support precompiled regexes in reader.rs
+#![feature(phase)]
+#[phase(plugin)]
+extern crate regex_macros;
+extern crate regex;
+
+use std::rc::Rc;
+use types::{MalVal,List,Vector,Int,Nil};
+mod readline;
+mod types;
+mod reader;
+mod printer;
+
+// read
+fn read(str: String) -> Result<MalVal,String> {
+ reader::read_str(str)
+}
+
+// eval
+fn eval(ast: MalVal) -> Result<MalVal,String> {
+ Ok(ast)
+}
+
+// print
+fn print(exp: MalVal) -> String {
+ exp.pr_str(true)
+}
+
+fn rep(str: String) -> Result<String,String> {
+ 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(str) => println!("Error: {}", str),
+ }
+ }
+}