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
use crate::expressions::Expression;

#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub enum Identifier {
    Scalar(String),
    State {
        name: String,
        pkgname: String,
        compname: String,
    },
    Params {
        name: String,
        pkgname: String,
        compname: String,
    },
    Local(String),
    //    Bracket(Box<Identifier>, Expression),
}

impl Identifier {
    pub fn new_scalar(name: &str) -> Identifier {
        Identifier::Scalar(name.to_string())
    }

    // TODO implement correct converter trait to identifier expression
    pub fn to_expression(&self) -> Expression {
        Expression::Identifier(self.clone())
    }

    pub fn ident(&self) -> String {
        match self {
            Identifier::Scalar(ident) => ident.clone(),
            Identifier::Local(ident) => ident.clone(),
            Identifier::State { name, .. } => name.clone(),
            Identifier::Params { name, .. } => name.clone(),
        }
    }
}