[parser] Simple REPL that parses input and prints output

This commit is contained in:
Eryn Wells 2018-08-25 20:38:54 -07:00
parent cf503838ae
commit 8d8cf34234

View file

@ -5,13 +5,32 @@
extern crate sibillexer;
extern crate sibilparser;
use std::io::prelude::*;
use std::io;
use sibillexer::Lexer;
use sibilparser::Parser;
fn main() {
let lexer = Lexer::new("(ab)".chars());
let parser = Parser::new(lexer);
for thing in parser {
println!("main: token -> {:?}", thing);
loop {
// Print a prompt.
print!("> ");
io::stdout().flush().ok().expect("couldn't flush");
// Read a line from stdin.
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
// Remove the trailing newline.
input.pop();
// Create a lexer and parser and process the input.
let lexer = Lexer::new(input.chars());
let parser = Parser::new(lexer);
// Print the parser's output.
for thing in parser {
println!("{:?}", thing);
}
println!();
}
}