xenon_codegen/
identifier.rs

1use crate::expression::Expression;
2
3#[derive(Clone, Default)]
4pub struct Identifier {
5    /// The name of the current identifier
6    pub name: String,
7    /// The next identifier after this one
8    pub child: Option<Box<Identifier>>,
9    /// If none, this is not a function call
10    pub arguments: Option<Vec<Expression>>
11}
12impl Identifier {
13    pub fn new(name: String) -> Identifier {
14        return Identifier {
15            name,
16            child: None,
17            arguments: None
18        };
19    }
20
21    pub fn is_valid(&self) -> bool {
22        if self.name.is_empty() {
23            return false;
24        }
25        match self.child.as_ref() {
26            Some(c) => {
27                if !c.is_valid() {
28                    return false;
29                }
30            }
31            None => ()
32        }
33        match self.arguments.as_ref() {
34            Some(a) => {
35                for i in 0..a.len() {
36                    if !a[i].is_valid() {
37                        return false;
38                    }
39                }
40                return true;
41            }
42            None => {
43                return true;
44            }
45        }
46    }
47}