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
49
50
51
use derive_more::From;

use crate::code_point::CodePoint;
use crate::structure::Located;
use crate::structure::rlt::block_level::Body;
use crate::structure::rlt::new_types::*;
use crate::structure::rlt::types::{Parameter, Type, TypedParameter};

#[derive(Debug, Clone, PartialEq)]
pub struct BodiedFunction {
    pub keyword: Keyword,
    pub id: Identifier,
    pub params: Option<Enclosed<Box<[Parameter]>>>,
    pub return_type: Option<(Symbol, Type)>,
    pub body: Box<Body>,
}

#[derive(Clone, Debug, PartialEq)]
pub struct AbstractFunction {
    pub keyword: Keyword,
    pub id: Identifier,
    pub params: Option<Enclosed<Box<[TypedParameter]>>>,
    pub return_type: Option<(Symbol, Type)>,
}

#[derive(Clone, Debug, PartialEq, From)]
pub enum Function {
    Abstract(AbstractFunction),
    Bodied(BodiedFunction),
}

impl Located for BodiedFunction {
    fn location(&self) -> CodePoint {
        self.keyword.location()
    }
}

impl Located for AbstractFunction {
    fn location(&self) -> CodePoint {
        self.keyword.location()
    }
}

impl Located for Function {
    fn location(&self) -> CodePoint {
        match self {
            Function::Abstract(x) => x.location(),
            Function::Bodied(x) => x.location(),
        }
    }
}