From 96e92230edf8ba9bbb460b695b728072af458b6d Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Fri, 24 Aug 2018 08:14:39 -0700 Subject: [PATCH] [parser] Fill in the iteration cases --- parser/src/lib.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/parser/src/lib.rs b/parser/src/lib.rs index f0c754a..4b52d08 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -52,8 +52,26 @@ impl Iterator for Parser where T: Iterator { fn next(&mut self) -> Option { let mut out: Option = None; let mut result: Option = None; + let mut input_lex: Option = None; loop { - match self.input.next() { + input_lex = match result { + None => self.input.next(), // Starting condition + Some(NodeParseResult::Continue) => self.input.next(), + Some(NodeParseResult::Complete{ obj }) => { + self.parsers.pop(); + // TODO: Handle obj + self.input.next() + }, + Some(NodeParseResult::Push{ next }) => { + self.parsers.push(next); + input_lex + }, + Some(NodeParseResult::Error{ msg }) => { + out = Some(Err(ParseError::ParserError{ msg: msg })); + break; + } + }; + match input_lex { Some(Ok(ref lex)) => { // TODO: Valid Lex from our input. Hand it off to the // current parser and process the result. @@ -61,7 +79,8 @@ impl Iterator for Parser where T: Iterator { }, Some(Err(ref error)) => { // TODO: Lexer error. Throw it up and out. - out = Some(Err(ParseError::LexerError { msg: error.msg().to_string() })); + let msg = error.msg().to_string(); + out = Some(Err(ParseError::LexerError { msg: msg })); break; }, None => {