[parser] Simple REPL that parses input and prints output
This commit is contained in:
parent
cf503838ae
commit
8d8cf34234
1 changed files with 23 additions and 4 deletions
|
@ -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!();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue