From c9fdd5e83cba2c49f80510a4da33578cf8e4c6cb Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 25 Jul 2015 16:55:58 -0700 Subject: [PATCH] Simplified statements-parsing Still a little wonky wrt extraneous Separators, need to adjust grammar to fix I think --- src/parser.rs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 8eaeb8f..53bc066 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -71,26 +71,26 @@ fn statements(tokens: &mut Tokens) -> ParseResult { let mut statements = Vec::new(); - let initial_statement = statement(tokens); - match initial_statement { - ParseResult::Ok(ast) => { - statements.push(ast); - loop { - let lookahead = tokens.peek().map(|i| i.clone()); - if let Some(&Separator) = lookahead { - tokens.next(); - if let ParseResult::Ok(ast_next) = statement(tokens) { + let initial_statement = match statement(tokens) { + err@ParseResult::Err(_) => return err, + ParseResult::Ok(ast) => ast + }; + + statements.push(initial_statement); + + loop { + let lookahead = tokens.peek().map(|i| i.clone()); + match lookahead { + Some(&Separator) => { + tokens.next(); + match statement(tokens) { + ParseResult::Ok(ast_next) => { statements.push(ast_next); - } else { - return ParseResult::Err("bad thing happened".to_string()); - } - } else { - break; - } - } - }, - err@ParseResult::Err(_) => { - return err; + }, + err@ParseResult::Err(_) => return err + }; + }, + _ => break } }