From ccc6fe0320bf59a203650bde6231e5a5e83a7639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sat, 31 Dec 2022 00:49:54 +0100 Subject: [PATCH] Token - is_litteral() method --- src/tokens.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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, + } + } +}