feat(lexer): Add diagnostic and impl error recovering
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Span {
|
||||
start: usize,
|
||||
end: usize,
|
||||
}
|
||||
pub struct CompileUnit {
|
||||
pub global_decls: Vec<GlobalDeclStmt>,
|
||||
}
|
||||
pub enum GlobalDeclStmt {
|
||||
VarDecl(VarDeclStmt),
|
||||
FuncDecl(FuncDeclStmt),
|
||||
}
|
||||
|
||||
pub struct VarDeclStmt {
|
||||
pub name: String,
|
||||
pub var_type: Type,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
pub struct FuncDeclStmt {
|
||||
pub name: String,
|
||||
pub return_type: Type,
|
||||
pub params: Vec<Param>,
|
||||
pub body: BlockStmt,
|
||||
pub span: Span,
|
||||
}
|
||||
pub struct BlockStmt {
|
||||
pub statements: Vec<Statement>,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
pub enum Statement {
|
||||
Return(ReturnStmt),
|
||||
Block(BlockStmt),
|
||||
Expr(Expr),
|
||||
VarDecl(VarDeclStmt),
|
||||
}
|
||||
pub struct ReturnStmt {
|
||||
pub value: Option<Expr>,
|
||||
pub span: Span,
|
||||
}
|
||||
pub struct Expr {
|
||||
pub value: ExprValue,
|
||||
pub span: Span,
|
||||
}
|
||||
pub enum ExprValue {
|
||||
IntLit(i64),
|
||||
Var(String),
|
||||
BinaryOp {
|
||||
lhs: Box<Expr>,
|
||||
op: BinaryOp,
|
||||
rhs: Box<Expr>
|
||||
},
|
||||
FuncCall(String, Vec<Expr>),
|
||||
Assign {
|
||||
lvalue: Box<Expr>,
|
||||
rvalue: Box<Expr>
|
||||
},
|
||||
}
|
||||
|
||||
pub enum BinaryOp {
|
||||
Add, Sub, Mul, Div, Mod,
|
||||
Equal, NotEqual, Less, LessEqual, Greater, GreaterEqual,
|
||||
}
|
||||
|
||||
pub enum Type {
|
||||
Int,
|
||||
Void,
|
||||
}
|
||||
|
||||
pub struct Param {
|
||||
name: String,
|
||||
param_type: Type,
|
||||
span: Span,
|
||||
}
|
||||
Reference in New Issue
Block a user