diff --git a/src/main.rs b/src/main.rs index eb2fb5d..b0c3820 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,8 +2,11 @@ extern crate lazy_static; mod lexer; +mod repl; -fn main() {} +fn main() { + repl::init(); +} #[cfg(test)] mod tests { diff --git a/src/repl/mod.rs b/src/repl/mod.rs new file mode 100644 index 0000000..ae1b975 --- /dev/null +++ b/src/repl/mod.rs @@ -0,0 +1,27 @@ +use crate::lexer::Lexer; +use std::io::{self, BufRead, Write}; + +const PROMPT: &'static str = ">> "; + +pub fn init() { + let stdin = io::stdin(); + let read_handle = stdin.lock(); + let stdout = io::stdout(); + let write_handle = stdout.lock(); + + start(read_handle, write_handle); +} + +fn start(mut ip: R, mut out: W) { + loop { + out.write_fmt(format_args!("{}", PROMPT)).unwrap(); + out.flush().unwrap(); + let mut s = String::new(); + ip.read_line(&mut s).unwrap(); + let tokens = Lexer::new(&s); + + for token in tokens { + println!("{:?}", token); + } + } +}