Added REPL
This commit is contained in:
parent
420db45c76
commit
9c018d2fe2
|
@ -2,8 +2,11 @@
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
|
||||||
mod lexer;
|
mod lexer;
|
||||||
|
mod repl;
|
||||||
|
|
||||||
fn main() {}
|
fn main() {
|
||||||
|
repl::init();
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
27
src/repl/mod.rs
Normal file
27
src/repl/mod.rs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user