1use super::common::{ConnectBody, DocComment, Identification, ParseErrorNode};
2use super::requirement::RequirementUsage;
3use super::structure::{
4 Annotation, Bind, DefinitionBody, MetadataAnnotation, MetadataKeywordUsage, Perform, RefDecl,
5};
6use crate::ast::core::{Expression, Node, Span};
7
8#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct ActionDef {
11 pub identification: Identification,
12 pub specializes: Option<String>,
13 pub specializes_span: Option<Span>,
14 pub body: ActionDefBody,
15}
16
17#[derive(Debug, Clone, PartialEq, Eq)]
19pub enum ActionDefBody {
20 Semicolon,
21 Brace {
22 elements: Vec<Node<ActionDefBodyElement>>,
23 },
24}
25
26#[derive(Debug, Clone, PartialEq, Eq)]
28pub enum ActionDefBodyElement {
29 Error(Node<ParseErrorNode>),
30 InOutDecl(Node<InOutDecl>),
31 Doc(Node<DocComment>),
32 Annotation(Node<Annotation>),
33 MetadataAnnotation(Node<MetadataAnnotation>),
34 RefDecl(Node<RefDecl>),
35 Perform(Node<Perform>),
36 Bind(Node<Bind>),
37 Flow(Node<Flow>),
38 FirstStmt(Node<FirstStmt>),
39 MergeStmt(Node<MergeStmt>),
40 StateUsage(Node<StateUsage>),
41 ActionUsage(Box<Node<ActionUsage>>),
42 Assign(Node<AssignStmt>),
43 ForLoop(Node<ForLoop>),
44 ThenAction(Node<ThenAction>),
45 Decl(Node<ActionBodyDecl>),
46}
47
48#[derive(Debug, Clone, PartialEq, Eq)]
54pub struct AssignStmt {
55 pub is_then: bool,
56 pub lhs: String,
57 pub rhs: String,
58}
59
60#[derive(Debug, Clone, PartialEq, Eq)]
62pub struct ForLoop {
63 pub var: String,
64 pub range: String,
65 pub body: ActionDefBody,
66}
67
68#[derive(Debug, Clone, PartialEq, Eq)]
70pub struct ThenAction {
71 pub action: Node<ActionUsage>,
72}
73
74#[derive(Debug, Clone, PartialEq, Eq)]
76pub struct InOutDecl {
77 pub direction: InOut,
78 pub name: String,
79 pub type_name: String,
80}
81
82#[derive(Debug, Clone, Copy, PartialEq, Eq)]
83pub enum InOut {
84 In,
85 Out,
86 InOut,
87}
88
89#[derive(Debug, Clone, PartialEq, Eq)]
91pub struct PayloadClause {
92 pub name: String,
93 pub type_name: Option<String>,
94 pub name_span: Span,
95 pub type_span: Option<Span>,
96}
97
98#[derive(Debug, Clone, PartialEq, Eq)]
100pub enum TransitionAccept {
101 Payload(PayloadClause),
102 Shorthand(Node<Expression>),
103}
104
105#[derive(Debug, Clone, PartialEq, Eq)]
107pub struct ActionUsage {
108 pub name: String,
109 pub type_name: String,
110 pub accept: Option<PayloadClause>,
112 pub send: Option<PayloadClause>,
114 pub body: ActionUsageBody,
115 pub name_span: Option<Span>,
117 pub type_ref_span: Option<Span>,
119}
120
121#[derive(Debug, Clone, PartialEq, Eq)]
123pub enum ActionUsageBody {
124 Semicolon,
125 Brace {
126 elements: Vec<Node<ActionUsageBodyElement>>,
127 },
128}
129
130#[derive(Debug, Clone, PartialEq, Eq)]
132pub enum ActionUsageBodyElement {
133 Error(Node<ParseErrorNode>),
134 Doc(Node<DocComment>),
135 Annotation(Node<Annotation>),
136 MetadataAnnotation(Node<MetadataAnnotation>),
137 InOutDecl(Node<InOutDecl>),
138 RefDecl(Node<RefDecl>),
139 Bind(Node<Bind>),
140 Flow(Node<Flow>),
141 FirstStmt(Node<FirstStmt>),
142 MergeStmt(Node<MergeStmt>),
143 StateUsage(Node<StateUsage>),
144 ActionUsage(Box<Node<ActionUsage>>),
145 Assign(Node<AssignStmt>),
146 ForLoop(Node<ForLoop>),
147 ThenAction(Node<ThenAction>),
148 Decl(Node<ActionBodyDecl>),
149}
150
151#[derive(Debug, Clone, PartialEq, Eq)]
153pub struct ActionBodyDecl {
154 pub keyword: String,
155 pub text: String,
156}
157
158#[derive(Debug, Clone, PartialEq, Eq)]
160pub struct Flow {
161 pub from: Node<Expression>,
162 pub to: Node<Expression>,
163 pub body: ConnectBody,
164}
165
166#[derive(Debug, Clone, PartialEq, Eq)]
168pub struct FlowDef {
169 pub identification: Identification,
170 pub specializes: Option<String>,
171 pub specializes_span: Option<Span>,
172 pub body: DefinitionBody,
173}
174
175#[derive(Debug, Clone, PartialEq, Eq)]
177pub struct FlowUsage {
178 pub name: String,
179 pub type_name: Option<String>,
180 pub from: Option<Node<Expression>>,
181 pub to: Option<Node<Expression>>,
182 pub body: DefinitionBody,
183}
184
185#[derive(Debug, Clone, PartialEq, Eq)]
187pub struct FirstStmt {
188 pub first: Node<Expression>,
189 pub then: Node<Expression>,
190 pub body: FirstMergeBody,
191}
192
193#[derive(Debug, Clone, PartialEq, Eq)]
195pub struct MergeStmt {
196 pub merge: Node<Expression>,
197 pub body: FirstMergeBody,
198}
199
200#[derive(Debug, Clone, PartialEq, Eq)]
202pub enum FirstMergeBody {
203 Semicolon,
204 Brace,
205}
206
207#[derive(Debug, Clone, PartialEq, Eq)]
213pub struct Allocate {
214 pub source: Node<Expression>,
215 pub target: Node<Expression>,
216 pub body: ConnectBody,
217}
218
219#[derive(Debug, Clone, PartialEq, Eq)]
221pub struct AllocationDef {
222 pub identification: Identification,
223 pub specializes: Option<String>,
224 pub specializes_span: Option<Span>,
225 pub body: DefinitionBody,
226}
227
228#[derive(Debug, Clone, PartialEq, Eq)]
230pub struct AllocationUsage {
231 pub name: String,
232 pub type_name: Option<String>,
233 pub source: Option<Node<Expression>>,
234 pub target: Option<Node<Expression>>,
235 pub body: DefinitionBody,
236}
237
238#[derive(Debug, Clone, PartialEq, Eq)]
244pub struct StateDef {
245 pub identification: Identification,
246 pub specializes: Option<String>,
247 pub specializes_span: Option<Span>,
248 pub body: StateDefBody,
249}
250
251#[derive(Debug, Clone, PartialEq, Eq)]
252pub enum StateDefBody {
253 Semicolon,
254 Brace {
255 elements: Vec<Node<StateDefBodyElement>>,
256 },
257}
258
259#[derive(Debug, Clone, PartialEq, Eq)]
260pub enum StateDefBodyElement {
261 Error(Node<ParseErrorNode>),
262 Doc(Node<DocComment>),
263 Annotation(Node<Annotation>),
264 MetadataKeywordUsage(Node<MetadataKeywordUsage>),
265 Other(String),
266 Entry(Node<EntryAction>),
268 Then(Node<ThenStmt>),
270 FinalState(Node<FinalState>),
272 Ref(Node<RefDecl>),
274 RequirementUsage(Node<RequirementUsage>),
275 StateUsage(Node<StateUsage>),
276 Transition(Node<Transition>),
277}
278
279#[derive(Debug, Clone, PartialEq, Eq)]
281pub struct EntryAction {
282 pub action_name: Option<String>,
284 pub body: StateDefBody,
285}
286
287#[derive(Debug, Clone, PartialEq, Eq)]
289pub struct ThenStmt {
290 pub state_name: String,
291 pub name_span: Option<Span>,
292}
293
294#[derive(Debug, Clone, PartialEq, Eq)]
296pub struct FinalState {
297 pub state_name: String,
298 pub name_span: Span,
299}
300
301#[derive(Debug, Clone, PartialEq, Eq)]
303pub struct StateUsage {
304 pub name: String,
305 pub type_name: Option<String>,
306 pub body: StateDefBody,
307}
308
309#[derive(Debug, Clone, PartialEq, Eq)]
311pub struct Transition {
312 pub name: Option<String>,
313 pub source: Option<Node<Expression>>,
315 pub is_initial: bool,
317 pub accept: Option<TransitionAccept>,
319 pub guard: Option<Node<Expression>>,
320 pub effect: Option<Node<Expression>>,
321 pub target: Node<Expression>,
322 pub body: ConnectBody,
323}
324
325