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
use crate::ns::*;
use serde::{Serialize, Deserialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QualifiedIdentifier {
    pub location: Location,
    pub attribute: bool,
    pub qualifier: Option<Rc<Expression>>,
    pub id: QualifiedIdentifierIdentifier,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum QualifiedIdentifierIdentifier {
    Id((String, Location)),
    Brackets(Rc<Expression>),
}

impl QualifiedIdentifier {
    pub fn to_identifier_name_or_asterisk(&self) -> Option<(String, Location)> {
        if self.attribute || self.qualifier.is_some() {
            None
        } else {
            if let QualifiedIdentifierIdentifier::Id(id) = &self.id {
                Some(id.clone())
            } else {
                None
            }
        }
    }

    pub fn to_identifier_name(&self) -> Option<(String, Location)> {
        if self.attribute || self.qualifier.is_some() {
            None
        } else {
            if let QualifiedIdentifierIdentifier::Id(id) = &self.id {
                if id.0 == "*" { None } else { Some(id.clone()) }
            } else {
                None
            }
        }
    }

    pub fn is_identifier_token(&self) -> bool {
        self.qualifier.is_none() && !self.attribute && match &self.id {
            QualifiedIdentifierIdentifier::Id((id, _)) => id != "*",
            _ => false,
        }
    }
}