Token - is_litteral() method

This commit is contained in:
Emmanuel BENOîT 2022-12-31 00:49:54 +01:00
parent 984ba5f600
commit ccc6fe0320

View file

@ -53,3 +53,17 @@ pub struct Token {
pub lexeme: String, pub lexeme: String,
pub line: usize, 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,
}
}
}