feat(lexer): Finish lexer parse and add tests
This commit is contained in:
@@ -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,
|
||||
}
|
||||
Reference in New Issue
Block a user