Skip to main content

xidl_parser/hir/
scoped_name.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Serialize, Deserialize)]
4pub struct ScopedName {
5    pub name: Vec<String>,
6    pub is_root: bool,
7}
8
9impl From<crate::typed_ast::ScopedName> for ScopedName {
10    fn from(value: crate::typed_ast::ScopedName) -> Self {
11        let is_root = value.node_text.starts_with("::");
12        let mut parts = Vec::new();
13        collect(&mut parts, &value);
14        Self {
15            name: parts.into_iter().map(ToOwned::to_owned).collect(),
16            is_root,
17        }
18    }
19}
20
21fn collect<'a>(parts: &mut Vec<&'a str>, value: &'a crate::typed_ast::ScopedName) {
22    if let Some(parent) = &value.scoped_name {
23        collect(parts, parent);
24    }
25    parts.push(&value.identifier.0);
26}