[parser] Clean up a little; add some prints for debugging
This commit is contained in:
parent
1ff349e147
commit
e822a6b6ec
1 changed files with 26 additions and 5 deletions
|
@ -49,6 +49,27 @@ impl<T> Parser<T> where T: Iterator<Item=LexerResult> {
|
||||||
let parser = self.parsers.last_mut().expect("couldn't get a parser -- this is unexpected");
|
let parser = self.parsers.last_mut().expect("couldn't get a parser -- this is unexpected");
|
||||||
parser.none()
|
parser.none()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn pop_parser(&mut self) {
|
||||||
|
let popped = self.parsers.pop();
|
||||||
|
print!("popped parser stack, {} parser{} remain --> {:?}\n",
|
||||||
|
self.parsers.len(),
|
||||||
|
if self.parsers.len() == 1 { " " } else { "s" },
|
||||||
|
popped);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn push_parser(&mut self, next: Box<NodeParser>) {
|
||||||
|
self.parsers.push(next);
|
||||||
|
print!("pushed onto parser stack, {} now -> {:?}\n",
|
||||||
|
self.parsers.len(),
|
||||||
|
self.parsers.last());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn next_lex(&mut self) -> Option<T::Item> {
|
||||||
|
let next = self.input.next();
|
||||||
|
print!("next lex: {:?}\n", next);
|
||||||
|
next
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Iterator for Parser<T> where T: Iterator<Item=LexerResult> {
|
impl<T> Iterator for Parser<T> where T: Iterator<Item=LexerResult> {
|
||||||
|
@ -60,19 +81,19 @@ impl<T> Iterator for Parser<T> where T: Iterator<Item=LexerResult> {
|
||||||
let mut input_lex: Option<T::Item> = None;
|
let mut input_lex: Option<T::Item> = None;
|
||||||
loop {
|
loop {
|
||||||
input_lex = match result {
|
input_lex = match result {
|
||||||
None => self.input.next(), // Starting condition
|
None => self.next_lex(), // Starting condition
|
||||||
Some(NodeParseResult::Continue) => self.input.next(),
|
Some(NodeParseResult::Continue) => self.next_lex(),
|
||||||
Some(NodeParseResult::Complete{ obj }) => {
|
Some(NodeParseResult::Complete{ obj }) => {
|
||||||
self.parsers.pop();
|
self.pop_parser();
|
||||||
if self.parsers.len() == 0 && input_lex.is_none() {
|
if self.parsers.len() == 0 && input_lex.is_none() {
|
||||||
// We are done.
|
// We are done.
|
||||||
out = Some(Ok(obj));
|
out = Some(Ok(obj));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
self.input.next()
|
self.next_lex()
|
||||||
},
|
},
|
||||||
Some(NodeParseResult::Push{ next }) => {
|
Some(NodeParseResult::Push{ next }) => {
|
||||||
self.parsers.push(next);
|
self.push_parser(next);
|
||||||
input_lex
|
input_lex
|
||||||
},
|
},
|
||||||
Some(NodeParseResult::Error{ msg }) => {
|
Some(NodeParseResult::Error{ msg }) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue