1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use crate::{Expression, Type};

/// The main type of `Node` in Tonic. Every line in the source code will eventually be parsed into
/// a `Statement`, including arbitrary expressions.
/// 
/// This enum is used to describe the most common structures in the Tonic language. It does not hold any
/// information about the position of the node, that is the responsibility of `Node`.
#[derive(Debug, PartialEq)]
pub enum Statement {
    Let {
        identifier: String,
        r#type: Option<Type>,
        initial: Expression,
    },
    Function {
        identifier: String,
        parameters: Vec<Parameter>,
        return_type: Option<Type>,
        body: Vec<Statement>,
    },
    If {
        condition: Expression,
        then: Vec<Statement>,
        otherwise: Vec<Statement>,
    },
    While {
        condition: Expression,
        then: Vec<Statement>,
    },
    Expression {
        expression: Expression,
    }
}

/// The `Parameter` struct is used to represent a function parameter.
/// 
/// It stores information about the name of the parameter and the expected type of the parameter.
#[derive(Debug, PartialEq)]
pub struct Parameter {
    name: String,
    r#type: Option<Type>,
}

impl Parameter {
    pub fn new(name: impl Into<String>, r#type: Option<Type>) -> Self {
        Self { name: name.into(), r#type }
    }
}