From 05238bced3803d25bba80f7853083375f105c64e Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 24 Jul 2015 02:23:18 -0700 Subject: [PATCH] rhs production --- src/parser.rs | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 3825989..e288113 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -104,20 +104,10 @@ fn let_expression(input: &mut Tokens) -> ParseResult { if let Some(&Identifier(ref name)) = input.next() { if let Some(&Identifier(ref s)) = input.next() { if s == "=" { - let next = input.next(); - if let Some(&Identifier(ref value)) = next { - let ast = AST::Binding(name.clone(), Box::new(AST::Name(value.clone()))); - return ParseResult::Ok(ast); - } - - if let Some(&StrLiteral(ref value)) = next { - let ast = AST::Binding(name.clone(), Box::new(AST::LangString(value.clone()))); - return ParseResult::Ok(ast); - } - - if let Some(&NumLiteral(n)) = next { - let ast = AST::Binding(name.clone(), Box::new(AST::Number(n))); - return ParseResult::Ok(ast); + if let ParseResult::Ok(rhs) = rhs(input) { + return ParseResult::Ok( + AST::Binding(name.clone(), + Box::new(rhs))); } } } @@ -125,3 +115,20 @@ fn let_expression(input: &mut Tokens) -> ParseResult { return ParseResult::Err("Bad parse in let_expression()".to_string()); } + +fn rhs(input: &mut Tokens) -> ParseResult { + let next = input.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())); + } + + if let Some(&NumLiteral(n)) = next { + return ParseResult::Ok(AST::Number(n)); + } + + return ParseResult::Err("Bad parse in rhs()".to_string()); +}