From 8fcc850d773ab1e2519bc76c356d65b5190dda87 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 25 Jul 2015 15:34:59 -0700 Subject: [PATCH] Added else clause to if parsing --- src/parser.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/parser.rs b/src/parser.rs index 0f5cbd2..b04e009 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -145,12 +145,24 @@ fn if_expression(input: &mut Tokens) -> ParseResult { ParseResult::Ok(ast) => ast }; + let else_clause = match input.peek().map(|i| i.clone()) { + Some(&Keyword(Kw::Else)) => { + input.next(); + match expression(input) { + err@ParseResult::Err(_) => return err, + ParseResult::Ok(ast) => Some(ast) + } + }, + _ => None + }; + expect!(Keyword(Kw::End), input); ParseResult::Ok( AST::IfStatement( Box::new(if_clause), Box::new(then_clause), - None)) + else_clause.map(|ast| Box::new(ast)) + )) } fn rhs(input: &mut Tokens) -> ParseResult {