blob: 4137840f0d8316007104fa7c79286503517d1030 (
plain)
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
|
use std::io;
use std::io::Write;
mod cexpr;
mod sexpr;
pub use cexpr::{CExpr, CNumber};
pub use sexpr::{sexpr_parse_file, SExpr};
pub type Result<T, E = String> = std::result::Result<T, E>;
pub fn repl(_verbose: bool) {
let stdin = io::stdin();
let mut stdout = io::stdout();
loop {
let raw_input = &mut String::new();
stdout.write(b"\ncasual> ").unwrap();
stdout.flush().unwrap();
stdin.read_line(raw_input).unwrap();
let raw_input = raw_input; // mutable to immutable reference
if raw_input.len() == 0 {
// end-of-line, aka Ctrl-D. Blank line will still have newline char
stdout.write(b"\nCiao!\n").unwrap();
return;
}
let expr = match CExpr::from_str(&raw_input) {
Ok(expr) => expr,
Err(e) => {
println!("error: {}", e);
continue;
}
};
println!("{}", expr);
}
}
|