diff --git a/src/tokens.rs b/src/tokens.rs index f9a91ea..de10921 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -53,3 +53,17 @@ pub struct Token { pub lexeme: String, pub line: usize, } + +impl Token { + /// Check whether a token corresponds to a litteral value. + pub fn is_litteral(&self) -> bool { + match self.token_type { + TokenType::True + | TokenType::False + | TokenType::Nil + | TokenType::String(_) + | TokenType::Number(_) => true, + _ => false, + } + } +}