diff --git a/parser/src/lib.rs b/parser/src/lib.rs index 4b52d08..0c26db7 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -44,6 +44,11 @@ impl Parser where T: Iterator { let parser = self.parsers.last_mut().expect("couldn't get a parser -- this is unexpected"); parser.parse(lex) } + + fn parse_none(&mut self) -> NodeParseResult { + let parser = self.parsers.last_mut().expect("couldn't get a parser -- this is unexpected"); + parser.none() + } } impl Iterator for Parser where T: Iterator { @@ -59,7 +64,11 @@ impl Iterator for Parser where T: Iterator { Some(NodeParseResult::Continue) => self.input.next(), Some(NodeParseResult::Complete{ obj }) => { self.parsers.pop(); - // TODO: Handle obj + if self.parsers.len() == 0 && input_lex.is_none() { + // We are done. + out = Some(Ok(obj)); + break; + } self.input.next() }, Some(NodeParseResult::Push{ next }) => { @@ -87,7 +96,7 @@ impl Iterator for Parser where T: Iterator { // TODO: We didn't get a Lex from the input, which means the // input is done. If there's any parse result waiting // around, clean it up and return it or return an error. - break; + result = Some(self.parse_none()); } } } diff --git a/parser/src/list_parser.rs b/parser/src/list_parser.rs index 3e993fb..6c1322a 100644 --- a/parser/src/list_parser.rs +++ b/parser/src/list_parser.rs @@ -46,4 +46,9 @@ impl NodeParser for ListParser { } } } + + fn none(&mut self) -> NodeParseResult { + let msg = format!("Unmatched paren, found EOF"); + NodeParseResult::Error { msg } + } } diff --git a/parser/src/node_parser.rs b/parser/src/node_parser.rs index 7effe29..3801422 100644 --- a/parser/src/node_parser.rs +++ b/parser/src/node_parser.rs @@ -33,4 +33,6 @@ impl NodeParseResult { /// nodes it encounters. pub trait NodeParser: Debug { fn parse(&mut self, lex: &Lex) -> NodeParseResult; + /// Called on a NodeParser when None is encountered in the input. + fn none(&mut self) -> NodeParseResult; } diff --git a/parser/src/program_parser.rs b/parser/src/program_parser.rs index d40226f..665ae4f 100644 --- a/parser/src/program_parser.rs +++ b/parser/src/program_parser.rs @@ -3,6 +3,7 @@ */ use sibillexer::{Lex, Token}; +use sibiltypes::Obj; use list_parser::ListParser; use node_parser::{NodeParser, NodeParseResult}; use sym_parser::SymParser; @@ -35,5 +36,9 @@ impl NodeParser for ProgramParser { } } } + + fn none(&mut self) -> NodeParseResult { + NodeParseResult::Complete { obj: Obj::Null } + } } diff --git a/parser/src/sym_parser.rs b/parser/src/sym_parser.rs index def12fe..b0257a4 100644 --- a/parser/src/sym_parser.rs +++ b/parser/src/sym_parser.rs @@ -19,9 +19,14 @@ impl NodeParser for SymParser { NodeParseResult::Complete { obj: obj } } _ => { - let msg = format!("Expected symbol found {:?}", lex); + let msg = format!("Expected symbol, found {:?}", lex); NodeParseResult::error(msg) } } } + + fn none(&mut self) -> NodeParseResult { + let msg = format!("Expected symbol, found EOF"); + NodeParseResult::Error { msg } + } }