[parser, types] Call subparser_completed

This commit is contained in:
Eryn Wells 2018-08-24 21:07:04 -07:00
parent d3520be67e
commit c35fce7727
2 changed files with 16 additions and 15 deletions

View file

@ -42,7 +42,7 @@ impl<T> Parser<T> where T: Iterator<Item=LexerResult> {
fn prepare(&mut self) {
assert_eq!(self.parsers.len(), 0);
let program_parser = Box::new(ProgramParser::new());
self.parsers.push(program_parser);
self.push_parser(program_parser);
}
fn parse_lex(&mut self, lex: &Lex) -> NodeParseResult {
@ -57,17 +57,12 @@ impl<T> Parser<T> where T: Iterator<Item=LexerResult> {
fn pop_parser(&mut self) {
let popped = self.parsers.pop();
println!("popped parser stack, {} parser{} remain --> {:?}",
self.parsers.len(),
if self.parsers.len() == 1 { " " } else { "s" },
popped);
println!("popped parser stack --> {:?}", self.parsers);
}
fn push_parser(&mut self, next: Box<NodeParser>) {
self.parsers.push(next);
println!("pushed onto parser stack, {} now -> {:?}",
self.parsers.len(),
self.parsers.last());
println!("pushed onto parser stack -> {:?}", self.parsers);
}
fn next_lex(&mut self) -> Option<T::Item> {
@ -100,13 +95,19 @@ impl<T> Iterator for Parser<T> where T: Iterator<Item=LexerResult> {
}
Some(NodeParseResult::Continue) => self.next_lex(),
Some(NodeParseResult::Complete{ obj }) => {
println!("{:?} completed with {:?}", self.parsers.last().unwrap(), obj);
self.pop_parser();
if self.parsers.len() == 0 && input_lex.is_none() {
// We are done.
println!("we are done");
out = Some(Ok(obj));
break;
} else {
let prev_parser = self.parsers.last_mut().unwrap();
prev_parser.subparser_completed(obj);
// TODO: Handle the result from above.
}
println!("parsers {:?}", self.parsers);
self.next_lex()
},
Some(NodeParseResult::Push{ next }) => {

View file

@ -7,9 +7,10 @@ use std::fmt;
use super::*;
use object::Object;
#[derive(Debug)]
pub struct Pair {
car: Obj,
cdr: Obj
pub car: Obj,
pub cdr: Obj
}
impl Pair {
@ -17,6 +18,10 @@ impl Pair {
Pair { car: Obj::Null, cdr: Obj::Null }
}
pub fn with_car(car: Obj) -> Pair {
Pair { car: car, cdr: Obj::Null }
}
fn fmt_pair(&self, f: &mut fmt::Formatter) -> fmt::Result {
let r = write!(f, "{}", self.car);
r.and_then(|r| match self.cdr {
@ -44,8 +49,3 @@ impl fmt::Display for Pair {
}
}
impl fmt::Debug for Pair {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self)
}
}