[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 sibillexer;
|
||||||
extern crate sibilparser;
|
extern crate sibilparser;
|
||||||
|
|
||||||
|
use std::io::prelude::*;
|
||||||
|
use std::io;
|
||||||
use sibillexer::Lexer;
|
use sibillexer::Lexer;
|
||||||
use sibilparser::Parser;
|
use sibilparser::Parser;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let lexer = Lexer::new("(ab)".chars());
|
loop {
|
||||||
let parser = Parser::new(lexer);
|
// Print a prompt.
|
||||||
for thing in parser {
|
print!("> ");
|
||||||
println!("main: token -> {:?}", thing);
|
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