From c42d69bd4747ec7806eb97c8269a89f19df9e141 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sun, 25 Dec 2016 20:54:47 -0700 Subject: [PATCH] Lex dots: . --- src/lexer/char.rs | 5 +++++ src/lexer/mod.rs | 8 ++++++++ src/lexer/token.rs | 1 + 3 files changed, 14 insertions(+) diff --git a/src/lexer/char.rs b/src/lexer/char.rs index 084467a..2ceabf1 100644 --- a/src/lexer/char.rs +++ b/src/lexer/char.rs @@ -8,6 +8,7 @@ pub trait Lexable { fn is_left_paren(&self) -> bool; fn is_right_paren(&self) -> bool; fn is_hash(&self) -> bool; + fn is_dot(&self) -> bool; fn is_string_quote(&self) -> bool; fn is_newline(&self) -> bool; fn is_eof(&self) -> bool; @@ -31,6 +32,10 @@ impl Lexable for char { fn is_hash(&self) -> bool { *self == '#' } + + fn is_dot(&self) -> bool { + *self == '.' + } fn is_string_quote(&self) -> bool { *self == '"' diff --git a/src/lexer/mod.rs b/src/lexer/mod.rs index 88e9d12..8f4bb09 100644 --- a/src/lexer/mod.rs +++ b/src/lexer/mod.rs @@ -89,6 +89,9 @@ impl Lexer { else if c.is_right_paren() { *token = Some(Token::RightParen(c.to_string())); } + else if c.is_dot() { + *token = Some(Token::Dot); + } else if c.is_hash() { self.state = State::Hash; self.advance(); @@ -207,6 +210,11 @@ mod tests { check_single_token(")", Token::RightParen(String::from(")"))); } + #[test] + fn lexer_finds_dots() { + check_single_token(".", Token::Dot); + } + #[test] fn lexer_finds_identifiers() { check_single_token("abc", Token::Identifier(String::from("abc"))); diff --git a/src/lexer/token.rs b/src/lexer/token.rs index aaf1114..ab66c69 100644 --- a/src/lexer/token.rs +++ b/src/lexer/token.rs @@ -7,6 +7,7 @@ pub enum Token { LeftParen(String), RightParen(String), + Dot, Identifier(String), Boolean(bool), String(String),