1use crate::diagnostic::{Span, Spanned};
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct Document {
8 pub version: Version,
10 pub diagram: Diagram,
12 pub span: Span,
14}
15
16#[derive(Debug, Clone, PartialEq, Eq)]
18pub struct Version {
19 pub major: u32,
21 pub minor: u32,
23 pub span: Span,
25}
26
27#[derive(Debug, Clone, PartialEq, Eq)]
29pub struct Diagram {
30 pub title: Spanned<String>,
32 pub members: Vec<DiagramMember>,
34 pub span: Span,
36}
37
38#[derive(Debug, Clone, PartialEq, Eq)]
40pub enum DiagramMember {
41 Node(Node),
43 Group(Group),
45 Edge(Edge),
47 Theme(Theme),
49 Layout(Layout),
51}
52
53#[derive(Debug, Clone, PartialEq, Eq)]
55pub struct Theme {
56 pub identifier: Spanned<String>,
58 pub span: Span,
60}
61
62#[derive(Debug, Clone, PartialEq, Eq)]
64pub struct Group {
65 pub identifier: Spanned<String>,
67 pub label: Spanned<String>,
69 pub members: Vec<GroupMember>,
71 pub span: Span,
73}
74
75#[derive(Debug, Clone, PartialEq, Eq)]
77pub enum GroupMember {
78 Node(Node),
80 Group(Group),
82 Layout(Layout),
84}
85
86#[derive(Debug, Clone, PartialEq, Eq)]
88pub struct Node {
89 pub identifier: Spanned<String>,
91 pub label: Spanned<String>,
93 pub properties: Vec<NodeProperty>,
95 pub span: Span,
97}
98
99#[derive(Debug, Clone, PartialEq, Eq)]
101pub enum NodeProperty {
102 Kind(Spanned<String>),
104 Icon(Spanned<String>),
106 Detail(Spanned<String>),
108}
109
110impl NodeProperty {
111 pub fn span(&self) -> Span {
113 match self {
114 Self::Kind(value) | Self::Icon(value) | Self::Detail(value) => value.span,
115 }
116 }
117}
118
119#[derive(Debug, Clone, PartialEq, Eq)]
121pub struct Edge {
122 pub from: Spanned<String>,
124 pub operator: Spanned<EdgeOperator>,
126 pub to: Spanned<String>,
128 pub label: Option<Spanned<String>>,
130 pub properties: Vec<EdgeProperty>,
132 pub span: Span,
134}
135
136#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
138pub enum EdgeOperator {
139 Forward,
141 Bidirectional,
143 Association,
145}
146
147#[derive(Debug, Clone, PartialEq, Eq)]
149pub enum EdgeProperty {
150 Kind(Spanned<String>),
152}
153
154impl EdgeProperty {
155 pub fn span(&self) -> Span {
157 match self {
158 Self::Kind(value) => value.span,
159 }
160 }
161}
162
163#[derive(Debug, Clone, PartialEq, Eq)]
165pub struct Layout {
166 pub statements: Vec<LayoutStatement>,
168 pub span: Span,
170}
171
172#[derive(Debug, Clone, PartialEq, Eq)]
174pub enum LayoutStatement {
175 Direction(Spanned<String>),
177 RankSame(IdentifierList),
179 Order(IdentifierList),
181}
182
183impl LayoutStatement {
184 pub fn span(&self) -> Span {
186 match self {
187 Self::Direction(value) => value.span,
188 Self::RankSame(list) | Self::Order(list) => list.span,
189 }
190 }
191}
192
193#[derive(Debug, Clone, PartialEq, Eq)]
195pub struct IdentifierList {
196 pub identifiers: Vec<Spanned<String>>,
198 pub span: Span,
200}