From 868373f409e0f3396bc932cdbe2732382355c635 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 6 Aug 2015 21:54:43 -0700 Subject: [PATCH] use match syntax in simple_parse --- src/parser.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index e36015a..d673227 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -68,7 +68,6 @@ pub fn parse(input: Vec) -> ParseResult { return ParseResult::Ok(AST::Statements(vec!())); } - match statements(&mut tokens) { ok@ParseResult::Ok(_) => { expect!(EOF, &mut tokens); @@ -250,19 +249,19 @@ fn get_binop_precedence(token: &Token) -> Option { fn simple_expression(tokens: &mut Tokens) -> ParseResult { let next = tokens.next(); - if let Some(&Identifier(ref value)) = next { - return ParseResult::Ok(AST::Name(value.clone())); - } - if let Some(&StrLiteral(ref value)) = next { - return ParseResult::Ok(AST::LangString(value.clone())); - } + match next { + Some(&Identifier(ref value)) => + ParseResult::Ok(AST::Name(value.clone())), - if let Some(&NumLiteral(n)) = next { - return ParseResult::Ok(AST::Number(n)); - } + Some(&StrLiteral(ref value)) => + ParseResult::Ok(AST::LangString(value.clone())), - return ParseResult::Err("Bad parse in simple_expression()".to_string()); + Some(&NumLiteral(n)) => + ParseResult::Ok(AST::Number(n)), + + _ => ParseResult::Err("Bad parse in simple_expression()".to_string()) + } } #[cfg(test)]