1
0
Fork 0

Added REPL

This commit is contained in:
Ishan Jain 2019-02-05 14:27:20 +05:30
parent 420db45c76
commit 9c018d2fe2
2 changed files with 31 additions and 1 deletions

View File

@ -2,8 +2,11 @@
extern crate lazy_static;
mod lexer;
mod repl;
fn main() {}
fn main() {
repl::init();
}
#[cfg(test)]
mod tests {

27
src/repl/mod.rs Normal file
View File

@ -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<R: BufRead, W: Write>(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);
}
}
}