added let, about to add types
This commit is contained in:
38
src/ast.rs
38
src/ast.rs
@@ -1,23 +1,27 @@
|
||||
use crate::types;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Span {
|
||||
pub left: usize,
|
||||
pub right: usize
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Spanned<T> {
|
||||
pub span: Span,
|
||||
pub value: T,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct TypeUsage {
|
||||
pub name: Spanned<Identifier>
|
||||
pub name: Spanned<Identifier>,
|
||||
pub ty: types::SpecifiedType,
|
||||
//TODO: Generics go here
|
||||
// mut, weak here
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub enum Operator {
|
||||
Mul,
|
||||
Div,
|
||||
@@ -25,30 +29,30 @@ pub enum Operator {
|
||||
Minus,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct LiteralInt {
|
||||
pub value: i64,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Identifier {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct FunctionCall {
|
||||
pub name: Spanned<Identifier>,
|
||||
pub arguments: Vec<Spanned<Box<Expression>>>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Operation {
|
||||
pub left: Spanned<Box<Expression>>,
|
||||
pub op: Operator,
|
||||
pub right: Spanned<Box<Expression>>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub enum Expression {
|
||||
LiteralInt(Spanned<LiteralInt>),
|
||||
FunctionCall(Spanned<FunctionCall>),
|
||||
@@ -56,32 +60,32 @@ pub enum Expression {
|
||||
Op(Operation),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Assignment {
|
||||
pub name: Spanned<Identifier>,
|
||||
pub type_usage: Option<Spanned<TypeUsage>>,
|
||||
// mut, weak here
|
||||
// mut, weak here if type not used
|
||||
pub expression: Spanned<Box<Expression>>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub enum Statement {
|
||||
Assignment(Spanned<Assignment>),
|
||||
Expression(Spanned<Box<Expression>>),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Block {
|
||||
pub statements: Vec<Spanned<Statement>>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct VariableDeclaration {
|
||||
pub name: Spanned<Identifier>,
|
||||
pub type_usage: Spanned<TypeUsage>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Function {
|
||||
pub name: Spanned<Identifier>,
|
||||
pub arguments: Vec<VariableDeclaration>,
|
||||
@@ -90,7 +94,7 @@ pub struct Function {
|
||||
}
|
||||
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Module {
|
||||
pub functions: Vec<Function>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user