bbc-basic: Slight tweak to heap size.
[jackhill/mal.git] / rust / step1_read_print.rs
CommitLineData
4ef4b17c
JM
1#[macro_use]
2extern crate lazy_static;
3extern crate regex;
4extern crate itertools;
5extern crate fnv;
6
7extern crate rustyline;
8use rustyline::error::ReadlineError;
9use rustyline::Editor;
10
11#[macro_use]
12#[allow(dead_code)]
13mod types;
14use types::{format_error};
15mod reader;
16mod printer;
17// TODO: figure out a way to avoid including env
18#[allow(dead_code)]
19mod env;
20
21fn main() {
22 // `()` can be used when no completer is required
23 let mut rl = Editor::<()>::new();
24 if rl.load_history(".mal-history").is_err() {
6c4cc8ad 25 eprintln!("No previous history.");
4ef4b17c
JM
26 }
27
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 }
49 }
50 }
51}
52
53// vim: ts=2:sw=2:expandtab