Lex dots: .
This commit is contained in:
parent
c34064f51a
commit
c42d69bd47
3 changed files with 14 additions and 0 deletions
|
@ -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;
|
||||
|
@ -32,6 +33,10 @@ impl Lexable for char {
|
|||
*self == '#'
|
||||
}
|
||||
|
||||
fn is_dot(&self) -> bool {
|
||||
*self == '.'
|
||||
}
|
||||
|
||||
fn is_string_quote(&self) -> bool {
|
||||
*self == '"'
|
||||
}
|
||||
|
|
|
@ -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")));
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
pub enum Token {
|
||||
LeftParen(String),
|
||||
RightParen(String),
|
||||
Dot,
|
||||
Identifier(String),
|
||||
Boolean(bool),
|
||||
String(String),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue