dark_vm/tokens/token.rs
1//! The Token struct holds the tokens that are generated by the Lexer.
2//! The Token struct maintains the position where the token was generated and the value of the token.
3//! Using an enum for the values increases the readibility of the code.
4
5use super::token_kind::TokenKind;
6
7#[derive(Debug)]
8pub struct Token {
9 pub kind: TokenKind,
10 pub pos: usize,
11}
12
13impl Token {
14 /// Constructs a new token with the given value and position.
15 ///
16 /// # Arguments
17 /// `kind` - The value of this Token.
18 /// `pos` - The position where this Token was created.
19 pub fn new(kind: TokenKind, pos: usize) -> Token {
20 Token { kind, pos }
21 }
22}