diff --git a/src/ast.rs b/src/ast.rs new file mode 100644 index 0000000..f3c1a2e --- /dev/null +++ b/src/ast.rs @@ -0,0 +1,88 @@ +/// A very naive AST definition using recursive enums +/// See the parser for implementation +use std::rc::Rc; + +/// Primitives +/// +/// TODO: add arrays and pointers maybe +#[derive(Debug)] +pub enum Type { + Int, + Float, + Char, +} + +pub type Parent = Vec; + +/// Entities are functions, classes, and modules +#[derive(Debug)] +pub enum Entity { + Fn(Fn), + Class(Class), + Module(Module), +} + +#[derive(Debug)] +pub struct Module { + pub name: Rc, + pub children: Vec, +} + +/// Modules contain functions, classes and statements +#[derive(Debug)] +pub enum ModuleChildren { + Fn(Fn), + Class(Class), + Statement(Statement), +} + +#[derive(Debug)] +pub struct Class { + pub name: Rc, + pub children: Vec, +} + +/// Classes contain functions and statements. +/// +/// TODO: Maybe change statements to something else +#[derive(Debug)] +pub enum ClassChildren { + Fn(Fn), + Statement(Statement), +} + +#[derive(Debug)] +pub struct Fn { + pub name: Rc, + pub return_typ: Option, + pub params: Vec>, + pub block: Vec, +} + +#[derive(Debug)] +pub enum Statement { + Let(Let), + Expr(Expr), + Block(Vec), +} + +#[derive(Debug)] +pub struct Let { + pub name: Rc, + pub typ: Type, + pub expr: Option, +} + +type Op = crate::lexer::TokenSymbol; + +#[derive(Debug)] +pub enum Expr { + Int(i32), + Float(f32), + Char(char), + Op(Op, Box, Option>), + If(Box, Box, Option>), + Loop, + Break, + Continue, +} diff --git a/src/lib.rs b/src/lib.rs index 9c2f664..c832a64 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,2 +1,3 @@ pub mod args; +pub mod ast; pub mod lexer;