feat(lexer): Finish lexer parse and add tests

This commit is contained in:
2026-05-06 14:30:32 +08:00
commit e8b50ae0d7
10 changed files with 696 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
use strum::EnumString;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Token {
pub value: TokenValue,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Span {
pub line: usize,
pub column: usize,
pub length: usize,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TokenValue {
IntLit(i64), // TODO: more literal types
Ident(String),
TypeIdent(TypeIdent),
Plus, Minus, Star, Slash, Percent,
Equal, DoubleEqual, NotEqual, Less, LessEqual, Greater, GreaterEqual,
LParen, RParen,
LBrace, RBrace,
Comma, Semicolon,
If, Else, While, Return, Break, Continue,
Eof,
Unrecognized(char),
}
#[derive(Debug, Clone, PartialEq, Eq, EnumString)]
pub enum TypeIdent {
#[strum(serialize = "int")]
Int,
#[strum(serialize = "void")]
Void,
}