1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
#[repr(u8)] #[derive(Debug, PartialEq, Clone, Copy, Hash, Eq)] pub enum TokenType { LParen, RParen, LCurly, RCurly, LBracket, RBracket, Comma, Dot, Semicolon, Plus, Minus, Star, Slash, Bang, BangEqual, Equal, EqualEqual, Greater, GreaterEqual, Less, LessEqual, Colon, Identifier, String, Number, KwAnd, KwOr, KwSelf, KwStruct, KwReturn, KwImport, KwLet, KwFn, KwMut, KwIf, KwElse, KwWhile, KwFor, KwBreak, KwTrue, KwFalse, KwNil, KwAs, Err, Eof, } pub use ast::Position; #[derive(Debug, Clone)] pub enum TokenData { None, String(String), Number(f64), Str(&'static str), } #[derive(Debug, Clone)] pub struct Token { pub type_: TokenType, pub data: TokenData, pub pos: Position, } impl Token { pub fn new(type_: TokenType, data: TokenData, pos: Position) -> Self { Token { type_, data, pos } } } impl ToString for Token { fn to_string(&self) -> String { format!( "{:?}, {:?}, line: {}, col: {}", self.type_, self.data, self.pos.line, self.pos.col ) } }