Derive more traits for ast
This commit is contained in:
parent
8bfd99fc20
commit
ae2a0122d8
|
@ -3,12 +3,12 @@
|
|||
|
||||
use super::lexer::Token;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct Ast<'a> {
|
||||
pub defs: Vec<Definition<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum Definition<'a> {
|
||||
Struct {
|
||||
name: &'a str,
|
||||
|
@ -29,38 +29,38 @@ pub enum Definition<'a> {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct FnImpl<'a> {
|
||||
pub def: FnDef<'a>,
|
||||
pub body: BranchBody<'a>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct FnDef<'a> {
|
||||
pub mutable: bool,
|
||||
pub name: &'a str,
|
||||
pub signature: FnSig<'a>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct StructMember<'a> {
|
||||
pub type_name: &'a str,
|
||||
pub name: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct FnSig<'a> {
|
||||
pub args: Vec<FnArg<'a>>,
|
||||
pub return_type: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct FnArg<'a> {
|
||||
pub type_name: &'a str,
|
||||
pub name: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct BranchBody<'a> {
|
||||
pub statements: Vec<Statement<'a>>,
|
||||
pub tail_expr: Option<Box<Expr<'a>>>,
|
||||
|
@ -68,7 +68,7 @@ pub struct BranchBody<'a> {
|
|||
|
||||
type ExprPair<'a> = Box<(Expr<'a>, Expr<'a>)>;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum Expr<'a> {
|
||||
BinaryOp(BinaryOp, ExprPair<'a>),
|
||||
UnaryOp(UnaryOp, Box<Expr<'a>>),
|
||||
|
@ -81,7 +81,7 @@ pub enum Expr<'a> {
|
|||
If(IfExpr<'a>),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum BinaryOp {
|
||||
Add,
|
||||
Sub,
|
||||
|
@ -127,7 +127,7 @@ impl BinaryOp {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum UnaryOp {
|
||||
BoolNot,
|
||||
BitNot,
|
||||
|
@ -147,7 +147,7 @@ impl UnaryOp {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum Literal<'a> {
|
||||
BinaryInteger(&'a str),
|
||||
OctalInteger(&'a str),
|
||||
|
@ -158,7 +158,7 @@ pub enum Literal<'a> {
|
|||
Boolean(bool),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum Statement<'a> {
|
||||
Expr(Expr<'a>),
|
||||
If(IfStmt<'a>),
|
||||
|
@ -173,14 +173,14 @@ pub enum Statement<'a> {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct IfExpr<'a> {
|
||||
pub test_expr: Box<Expr<'a>>,
|
||||
pub then_body: BranchBody<'a>,
|
||||
pub else_body: BranchBody<'a>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct IfStmt<'a> {
|
||||
pub test_expr: Expr<'a>,
|
||||
pub then_body: BranchBody<'a>,
|
||||
|
|
Loading…
Reference in New Issue