[parser, types] Call subparser_completed
This commit is contained in:
parent
d3520be67e
commit
c35fce7727
2 changed files with 16 additions and 15 deletions
|
@ -42,7 +42,7 @@ impl<T> Parser<T> where T: Iterator<Item=LexerResult> {
|
||||||
fn prepare(&mut self) {
|
fn prepare(&mut self) {
|
||||||
assert_eq!(self.parsers.len(), 0);
|
assert_eq!(self.parsers.len(), 0);
|
||||||
let program_parser = Box::new(ProgramParser::new());
|
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 {
|
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) {
|
fn pop_parser(&mut self) {
|
||||||
let popped = self.parsers.pop();
|
let popped = self.parsers.pop();
|
||||||
println!("popped parser stack, {} parser{} remain --> {:?}",
|
println!("popped parser stack --> {:?}", self.parsers);
|
||||||
self.parsers.len(),
|
|
||||||
if self.parsers.len() == 1 { " " } else { "s" },
|
|
||||||
popped);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_parser(&mut self, next: Box<NodeParser>) {
|
fn push_parser(&mut self, next: Box<NodeParser>) {
|
||||||
self.parsers.push(next);
|
self.parsers.push(next);
|
||||||
println!("pushed onto parser stack, {} now -> {:?}",
|
println!("pushed onto parser stack -> {:?}", self.parsers);
|
||||||
self.parsers.len(),
|
|
||||||
self.parsers.last());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_lex(&mut self) -> Option<T::Item> {
|
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::Continue) => self.next_lex(),
|
||||||
Some(NodeParseResult::Complete{ obj }) => {
|
Some(NodeParseResult::Complete{ obj }) => {
|
||||||
|
println!("{:?} completed with {:?}", self.parsers.last().unwrap(), obj);
|
||||||
self.pop_parser();
|
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.
|
||||||
println!("we are done");
|
println!("we are done");
|
||||||
out = Some(Ok(obj));
|
out = Some(Ok(obj));
|
||||||
break;
|
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()
|
self.next_lex()
|
||||||
},
|
},
|
||||||
Some(NodeParseResult::Push{ next }) => {
|
Some(NodeParseResult::Push{ next }) => {
|
||||||
|
|
|
@ -7,9 +7,10 @@ use std::fmt;
|
||||||
use super::*;
|
use super::*;
|
||||||
use object::Object;
|
use object::Object;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct Pair {
|
pub struct Pair {
|
||||||
car: Obj,
|
pub car: Obj,
|
||||||
cdr: Obj
|
pub cdr: Obj
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Pair {
|
impl Pair {
|
||||||
|
@ -17,6 +18,10 @@ impl Pair {
|
||||||
Pair { car: Obj::Null, cdr: Obj::Null }
|
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 {
|
fn fmt_pair(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
let r = write!(f, "{}", self.car);
|
let r = write!(f, "{}", self.car);
|
||||||
r.and_then(|r| match self.cdr {
|
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue