126 lines
2.0 KiB
Rust
126 lines
2.0 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 {
|
|
Import(Import),
|
|
FuncDef(FuncDef),
|
|
StructDef(StructDef),
|
|
}
|
|
|
|
// ===============================================
|
|
// Import
|
|
|
|
#[derive(Debug)]
|
|
pub struct Import {
|
|
pub(crate) from: String,
|
|
pub(crate) items: ImportItem,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum ImportItem {
|
|
SelfItem(Option<String>),
|
|
Item(String, Option<String>),
|
|
Module(String, Vec<ImportItem>),
|
|
}
|
|
|
|
// ===============================================
|
|
// 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,
|
|
}
|