Token-related definitions

This commit is contained in:
Emmanuel BENOîT 2022-12-30 16:47:30 +01:00
parent dcbb2681c1
commit 987118be8b
2 changed files with 66 additions and 3 deletions

55
src/tokens.rs Normal file
View file

@ -0,0 +1,55 @@
/// The type of a token. May also contain its litteral value.
#[derive(Clone, PartialEq, Debug)]
pub enum TokenType {
LeftParen,
RightParen,
LeftBrace,
RightBrace,
Comma,
Dot,
Minus,
Plus,
Semicolon,
Slash,
Star,
Bang,
BangEqual,
Equal,
EqualEqual,
Greater,
GreaterEqual,
Less,
LessEqual,
Identifier(String),
String(String),
Number(f64),
And,
Class,
Else,
False,
Fun,
For,
If,
Nil,
Or,
Print,
Return,
Super,
This,
True,
Var,
While,
EOF,
}
/// Full information about a token.
#[derive(Clone, Debug)]
pub struct Token {
pub token_type: TokenType,
pub lexeme: String,
pub line: usize,
}