Files
Aura/aurac_parser/src/ast.rs
2026-02-23 08:51:37 -05:00

76 lines
1.3 KiB
Rust

#[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>),
}