Initial commit
This commit is contained in:
75
aurac_parser/src/ast.rs
Normal file
75
aurac_parser/src/ast.rs
Normal file
@@ -0,0 +1,75 @@
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Program {
|
||||
pub decls: Vec<Decl>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Decl {
|
||||
Struct(StructDecl),
|
||||
Fn(FnDecl),
|
||||
TypeAlias(String, TypeExpr),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct StructDecl {
|
||||
pub name: String,
|
||||
pub fields: Vec<FieldDecl>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct FieldDecl {
|
||||
pub name: String,
|
||||
pub ty: TypeExpr,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct FnDecl {
|
||||
pub is_pure: bool,
|
||||
pub is_gpu: bool,
|
||||
pub name: String,
|
||||
pub params: Vec<Param>,
|
||||
pub return_type: TypeExpr,
|
||||
pub body: Block,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Param {
|
||||
pub name: String,
|
||||
pub ty: TypeExpr,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Block {
|
||||
pub statements: Vec<Stmt>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Stmt {
|
||||
Return(Expr),
|
||||
ExprStmt(Expr),
|
||||
LetBind(String, Expr),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Expr {
|
||||
Binary(Box<Expr>, BinaryOp, Box<Expr>),
|
||||
Literal(String),
|
||||
Identifier(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum BinaryOp {
|
||||
Add,
|
||||
Sub,
|
||||
Mul,
|
||||
Div,
|
||||
Gt,
|
||||
Lt,
|
||||
Eq,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum TypeExpr {
|
||||
BaseType(String),
|
||||
Refined(Box<TypeExpr>, String, Box<Expr>),
|
||||
}
|
||||
Reference in New Issue
Block a user