DISABLE FDs (REMOVE ME).
[jackhill/mal.git] / rust / step1_read_print.rs
CommitLineData
4ef4b17c
JM
1#[macro_use]
2extern crate lazy_static;
4ef4b17c 3extern crate fnv;
4a649b37
RF
4extern crate itertools;
5extern crate regex;
4ef4b17c
JM
6
7extern crate rustyline;
8use rustyline::error::ReadlineError;
9use rustyline::Editor;
10
11#[macro_use]
12#[allow(dead_code)]
13mod types;
c9b18677 14use crate::types::format_error;
4ef4b17c 15mod printer;
4a649b37 16mod reader;
4ef4b17c
JM
17// TODO: figure out a way to avoid including env
18#[allow(dead_code)]
19mod env;
20
21fn main() {
4a649b37
RF
22 // `()` can be used when no completer is required
23 let mut rl = Editor::<()>::new();
24 if rl.load_history(".mal-history").is_err() {
25 eprintln!("No previous history.");
26 }
4ef4b17c 27
4a649b37
RF
28 loop {
29 let readline = rl.readline("user> ");
30 match readline {
31 Ok(line) => {
32 rl.add_history_entry(&line);
33 rl.save_history(".mal-history").unwrap();
34 if line.len() > 0 {
35 match reader::read_str(line) {
36 Ok(mv) => {
37 println!("{}", mv.pr_str(true));
38 }
39 Err(e) => println!("Error: {}", format_error(e)),
40 }
41 }
42 }
43 Err(ReadlineError::Interrupted) => continue,
44 Err(ReadlineError::Eof) => break,
45 Err(err) => {
46 println!("Error: {:?}", err);
47 break;
48 }
4ef4b17c 49 }
4ef4b17c 50 }
4ef4b17c 51}