From e870d8172a13bb77ea0b840f7ef9eafbad246a98 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 8 Aug 2015 00:27:40 -0700 Subject: [PATCH] Make = a keyword --- src/parser.rs | 14 ++++++-------- src/tokenizer.rs | 4 +++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index ebbf827..c1e0b59 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -112,13 +112,11 @@ fn statement(tokens: &mut Tokens) -> ParseResult { fn let_expression(tokens: &mut Tokens) -> ParseResult { expect!(Keyword(Kw::Let), tokens); if let Some(&Identifier(ref name)) = tokens.next() { - if let Some(&Identifier(ref s)) = tokens.next() { - if s == "=" { - if let Ok(expr) = expression(tokens) { - return Ok( - AST::Binding(name.clone(), - Box::new(expr))); - } + if let Some(&Keyword(Kw::Assign)) = tokens.next() { + if let Ok(expr) = expression(tokens) { + return Ok( + AST::Binding(name.clone(), + Box::new(expr))); } } } @@ -160,7 +158,7 @@ fn if_expression(tokens: &mut Tokens) -> ParseResult { expect!(Keyword(Kw::End), tokens); - Ok( AST::IfStatement( + Ok(AST::IfStatement( Box::new(if_clause), Box::new(then_clause), else_clause.map(|ast| Box::new(ast)) diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 64310b4..61d266a 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -21,7 +21,8 @@ pub enum Kw { End, Let, Fn, - Null + Null, + Assign } pub fn tokenize(input: &str) -> Vec { @@ -106,6 +107,7 @@ fn handle_identifier(identifier: String) -> Token { "end" => Kw::End, "fn" => Kw::Fn, "null" => Kw::Null, + "=" => Kw::Assign, _ => return Token::Identifier(identifier) };