diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..950329b --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,34 @@ +use std::io; +use std::io::Write; + +mod cexpr; +mod sexpr; + +pub use cexpr::{CExpr, CNumber}; +pub use sexpr::{sexpr_parse_file, SExpr}; + +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); + } +} |