use crate::diagnostic::{Span, Spanned};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Document {
pub version: Version,
pub diagram: Diagram,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Version {
pub major: u32,
pub minor: u32,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Diagram {
pub title: Spanned<String>,
pub members: Vec<DiagramMember>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DiagramMember {
Node(Node),
Group(Group),
Edge(Edge),
Theme(Theme),
Layout(Layout),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Theme {
pub identifier: Spanned<String>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Group {
pub identifier: Spanned<String>,
pub label: Spanned<String>,
pub members: Vec<GroupMember>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum GroupMember {
Node(Node),
Group(Group),
Layout(Layout),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Node {
pub identifier: Spanned<String>,
pub label: Spanned<String>,
pub properties: Vec<NodeProperty>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum NodeProperty {
Kind(Spanned<String>),
Icon(Spanned<String>),
Detail(Spanned<String>),
}
impl NodeProperty {
pub fn span(&self) -> Span {
match self {
Self::Kind(value) | Self::Icon(value) | Self::Detail(value) => value.span,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Edge {
pub from: Spanned<String>,
pub operator: Spanned<EdgeOperator>,
pub to: Spanned<String>,
pub label: Option<Spanned<String>>,
pub properties: Vec<EdgeProperty>,
pub span: Span,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum EdgeOperator {
Forward,
Bidirectional,
Association,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum EdgeProperty {
Kind(Spanned<String>),
}
impl EdgeProperty {
pub fn span(&self) -> Span {
match self {
Self::Kind(value) => value.span,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Layout {
pub statements: Vec<LayoutStatement>,
pub span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum LayoutStatement {
Direction(Spanned<String>),
RankSame(IdentifierList),
Order(IdentifierList),
}
impl LayoutStatement {
pub fn span(&self) -> Span {
match self {
Self::Direction(value) => value.span,
Self::RankSame(list) | Self::Order(list) => list.span,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct IdentifierList {
pub identifiers: Vec<Spanned<String>>,
pub span: Span,
}