Make the Parser dump tokens and quit
Write a main() for sibilparser that just does that.
This commit is contained in:
parent
2a7626c75f
commit
efe0c27d93
2 changed files with 45 additions and 5 deletions
|
@ -5,14 +5,39 @@
|
||||||
extern crate sibillexer;
|
extern crate sibillexer;
|
||||||
extern crate sibiltypes;
|
extern crate sibiltypes;
|
||||||
|
|
||||||
mod program;
|
use std::iter::Peekable;
|
||||||
|
use sibillexer::Result as LexerResult;
|
||||||
use sibillexer::Lexer;
|
|
||||||
use sibiltypes::Object;
|
use sibiltypes::Object;
|
||||||
|
|
||||||
struct ParseError { }
|
pub struct ParseError;
|
||||||
|
|
||||||
type Result = std::result::Result<Object, ParseError>;
|
pub type Result = std::result::Result<Object, ParseError>;
|
||||||
|
|
||||||
|
pub struct Parser<T> where T: Iterator<Item=LexerResult> {
|
||||||
|
input: Peekable<T>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Parser<T> where T: Iterator<Item=LexerResult> {
|
||||||
|
pub fn new(input: T) -> Parser<T> {
|
||||||
|
Parser { input: input.peekable() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Iterator for Parser<T> where T: Iterator<Item=LexerResult> {
|
||||||
|
type Item = Result;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
loop {
|
||||||
|
if let Some(lex) = self.input.next() {
|
||||||
|
println!("{:?}", lex)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
15
parser/src/main.rs
Normal file
15
parser/src/main.rs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/* parser/src/main.rs
|
||||||
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern crate sibillexer;
|
||||||
|
extern crate sibilparser;
|
||||||
|
|
||||||
|
use sibillexer::Lexer;
|
||||||
|
use sibilparser::Parser;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let lexer = Lexer::new("(ab)".chars());
|
||||||
|
let parser = Parser::new(lexer);
|
||||||
|
for thing in parser { }
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue