gust/src/ast.rs

109 lines
1.6 KiB
Rust

#[derive(Debug)]
pub struct Program {
pub(crate) items: Vec<Item>,
}
/// Range
#[derive(Debug)]
pub struct Loc(usize, usize);
impl Loc {
pub fn new(left: usize, right: usize) -> Self {
Loc(left, right)
}
}
// ===============================================
// Items
#[derive(Debug)]
pub struct Item {
pub(crate) kind: ItemKind,
pub(crate) loc: Loc,
}
#[derive(Debug)]
pub enum ItemKind {
FuncDef(FuncDef),
StructDef(StructDef),
}
// ===============================================
// Functions
#[derive(Debug)]
pub struct FuncDef {
pub(crate) name: Option<String>,
pub(crate) body: Expr,
pub(crate) loc: Loc,
}
// ===============================================
// Structs
#[derive(Debug)]
pub struct StructDef {
}
// ===============================================
// Expr
#[derive(Debug)]
pub struct Expr {
pub(crate) kind: ExprKind,
pub(crate) loc: Loc,
}
#[derive(Debug)]
pub enum ExprKind {
// Literals / primitives
Literal(Literal),
// More copmlex expressionsj
BinOp(Box<Expr>, BinOp, Box<Expr>),
Sequence(Sequence),
Paren(Box<Expr>),
}
#[derive(Debug)]
pub struct Sequence {
pub(crate) stmts: Vec<Stmt>,
pub(crate) inner: Box<Expr>,
}
// Stmts
#[derive(Debug)]
pub struct Stmt {
pub(crate) kind: StmtKind,
pub(crate) loc: Loc,
}
#[derive(Debug)]
pub enum StmtKind {
Expr(Expr),
}
// ===============================================
// Literals
#[derive(Debug)]
pub struct Literal {
pub(crate) kind: LiteralKind,
pub(crate) loc: Loc,
}
#[derive(Debug)]
pub enum LiteralKind {
Int(u64),
}
// ===============================================
// Random shit
#[derive(Debug)]
pub enum BinOp {
Plus,
}