diff --git a/lexer/src/chars.rs b/lexer/src/chars.rs index ae17af1..8aa2e2c 100644 --- a/lexer/src/chars.rs +++ b/lexer/src/chars.rs @@ -10,6 +10,7 @@ pub trait Lexable { fn is_identifier_initial(&self) -> bool; fn is_identifier_subsequent(&self) -> bool; fn is_left_paren(&self) -> bool; + fn is_quote(&self) -> bool; fn is_radix(&self) -> bool; fn is_right_paren(&self) -> bool; } @@ -43,6 +44,10 @@ impl Lexable for char { self.is_whitespace() || self.is_left_paren() || self.is_right_paren() } + fn is_quote(&self) -> bool { + *self == '\'' + } + fn is_radix(&self) -> bool { let radishes = &['b', 'd', 'o', 'x']; radishes.contains(self) diff --git a/lexer/src/states/begin.rs b/lexer/src/states/begin.rs index 4daff23..5f839d0 100644 --- a/lexer/src/states/begin.rs +++ b/lexer/src/states/begin.rs @@ -36,6 +36,8 @@ impl State for Begin { StateResult::advance(Box::new(Hash::new())) } else if let Some(st) = Digit::with_char(&Builder::new(), c) { StateResult::advance(Box::new(st)) + } else if c.is_quote() { + StateResult::Emit(Token::Quote, Resume::AtNext) } else { StateResult::fail(Error::invalid_char(c)) } diff --git a/lexer/src/token.rs b/lexer/src/token.rs index 57135b5..5d79222 100644 --- a/lexer/src/token.rs +++ b/lexer/src/token.rs @@ -14,10 +14,11 @@ pub struct Lex { pub enum Token { Bool(bool), Dot, - Num(i64), + Id, LeftParen, + Num(i64), + Quote, RightParen, - Id } impl Lex { diff --git a/lexer/tests/single_tokens.rs b/lexer/tests/single_tokens.rs index acd7c3d..f60481c 100644 --- a/lexer/tests/single_tokens.rs +++ b/lexer/tests/single_tokens.rs @@ -95,3 +95,10 @@ fn dot() { assert_eq!(lex.next(), Some(Ok(Lex::new(Token::Dot, ".", 0, 0)))); assert_eq!(lex.next(), None); } + +#[test] +fn quote() { + let mut lex = Lexer::new("'".chars()); + assert_eq!(lex.next(), Some(Ok(Lex::new(Token::Quote, "'", 0, 0)))); + assert_eq!(lex.next(), None); +}