15
src/ast.rs
15
src/ast.rs
@@ -1,6 +1,5 @@
|
|||||||
/// A very naive AST definition using recursive enums
|
/// A very naive AST definition using recursive enums
|
||||||
/// See the parser for implementation
|
/// See the parser for implementation
|
||||||
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
pub type Parent = Vec<Entity>;
|
pub type Parent = Vec<Entity>;
|
||||||
@@ -24,7 +23,8 @@ pub struct Module {
|
|||||||
pub enum ModuleChildren {
|
pub enum ModuleChildren {
|
||||||
Fn(Fn),
|
Fn(Fn),
|
||||||
Class(Class),
|
Class(Class),
|
||||||
Statement(Statement),
|
Module(Module),
|
||||||
|
Const(Let),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -45,22 +45,22 @@ pub enum ClassChildren {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Fn {
|
pub struct Fn {
|
||||||
pub name: Rc<str>,
|
pub name: Rc<str>,
|
||||||
pub return_typ: Option<Primitive>,
|
pub return_ty: Option<Ty>,
|
||||||
pub params: Vec<(Rc<str>, Primitive)>,
|
pub params: Vec<(Rc<str>, Ty)>,
|
||||||
pub children: Vec<Statement>,
|
pub children: Vec<Statement>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Statement {
|
pub enum Statement {
|
||||||
|
Const(Let),
|
||||||
Let(Let),
|
Let(Let),
|
||||||
Expr(Expr),
|
Expr(Expr),
|
||||||
Block(Vec<Statement>),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Let {
|
pub struct Let {
|
||||||
pub name: Rc<str>,
|
pub name: Rc<str>,
|
||||||
pub typ: Primitive,
|
pub ty: Ty,
|
||||||
pub expr: Option<Expr>,
|
pub expr: Option<Expr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +73,7 @@ pub enum Expr {
|
|||||||
Char(char),
|
Char(char),
|
||||||
Op(Op, Box<Expr>, Option<Box<Expr>>),
|
Op(Op, Box<Expr>, Option<Box<Expr>>),
|
||||||
If(Box<Expr>, Box<Expr>, Option<Box<Expr>>),
|
If(Box<Expr>, Box<Expr>, Option<Box<Expr>>),
|
||||||
|
Block(Vec<Statement>),
|
||||||
Loop,
|
Loop,
|
||||||
Break,
|
Break,
|
||||||
Continue,
|
Continue,
|
||||||
@@ -82,7 +83,7 @@ pub enum Expr {
|
|||||||
///
|
///
|
||||||
/// TODO: add arrays and pointers maybe
|
/// TODO: add arrays and pointers maybe
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Primitive {
|
pub enum Ty {
|
||||||
Int,
|
Int,
|
||||||
Float,
|
Float,
|
||||||
Char,
|
Char,
|
||||||
|
Reference in New Issue
Block a user