use alloc::string::{String, ToString};
pub(crate) struct PortDecl {
pub(crate) default: Option<bool>,
pub(crate) source: String,
pub(crate) line: u32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub(crate) struct PortRef {
pub(crate) domain: Option<String>,
pub(crate) subject: String,
pub(crate) predicate: Option<String>,
pub(crate) object: Option<String>,
}
impl PortRef {
pub(crate) fn label(&self) -> String {
let mut s = String::new();
if let Some(d) = &self.domain {
s.push_str(d);
s.push('.');
}
s.push_str(&self.subject);
if let Some(p) = &self.predicate {
s.push(' ');
s.push_str(p);
}
if let Some(o) = &self.object {
s.push(' ');
s.push_str(o);
}
s
}
}
pub(crate) fn parse_port_ref(key: &str) -> PortRef {
let mut words = key.split_whitespace();
let first = words.next().unwrap_or("");
let (domain, subject) = match first.split_once('.') {
Some((d, s)) => (Some(d.to_string()), s.to_string()),
None => (None, first.to_string()),
};
PortRef {
domain,
subject,
predicate: words.next().map(str::to_string),
object: words.next().map(str::to_string),
}
}