1use super::common::{ConnectBody, DocComment, Identification, ParseErrorNode};
2use super::requirement::RequirementUsage;
3use super::structure::{Annotation, Bind, DefinitionBody, MetadataKeywordUsage, Perform, RefDecl};
4use crate::ast::core::{Expression, Node, Span};
5
6#[derive(Debug, Clone, PartialEq, Eq)]
8pub struct ActionDef {
9 pub identification: Identification,
10 pub specializes: Option<String>,
11 pub specializes_span: Option<Span>,
12 pub body: ActionDefBody,
13}
14
15#[derive(Debug, Clone, PartialEq, Eq)]
17pub enum ActionDefBody {
18 Semicolon,
19 Brace {
20 elements: Vec<Node<ActionDefBodyElement>>,
21 },
22}
23
24#[derive(Debug, Clone, PartialEq, Eq)]
26pub enum ActionDefBodyElement {
27 Error(Node<ParseErrorNode>),
28 InOutDecl(Node<InOutDecl>),
29 Doc(Node<DocComment>),
30 Annotation(Node<Annotation>),
31 RefDecl(Node<RefDecl>),
32 Perform(Node<Perform>),
33 Bind(Node<Bind>),
34 Flow(Node<Flow>),
35 FirstStmt(Node<FirstStmt>),
36 MergeStmt(Node<MergeStmt>),
37 StateUsage(Node<StateUsage>),
38 ActionUsage(Box<Node<ActionUsage>>),
39 Assign(Node<AssignStmt>),
40 ForLoop(Node<ForLoop>),
41 ThenAction(Node<ThenAction>),
42 Decl(Node<ActionBodyDecl>),
43}
44
45#[derive(Debug, Clone, PartialEq, Eq)]
51pub struct AssignStmt {
52 pub is_then: bool,
53 pub lhs: String,
54 pub rhs: String,
55}
56
57#[derive(Debug, Clone, PartialEq, Eq)]
59pub struct ForLoop {
60 pub var: String,
61 pub range: String,
62 pub body: ActionDefBody,
63}
64
65#[derive(Debug, Clone, PartialEq, Eq)]
67pub struct ThenAction {
68 pub action: Node<ActionUsage>,
69}
70
71#[derive(Debug, Clone, PartialEq, Eq)]
73pub struct InOutDecl {
74 pub direction: InOut,
75 pub name: String,
76 pub type_name: String,
77}
78
79#[derive(Debug, Clone, Copy, PartialEq, Eq)]
80pub enum InOut {
81 In,
82 Out,
83 InOut,
84}
85
86#[derive(Debug, Clone, PartialEq, Eq)]
88pub struct PayloadClause {
89 pub name: String,
90 pub type_name: Option<String>,
91 pub name_span: Span,
92 pub type_span: Option<Span>,
93}
94
95#[derive(Debug, Clone, PartialEq, Eq)]
97pub enum TransitionAccept {
98 Payload(PayloadClause),
99 Shorthand(Node<Expression>),
100}
101
102#[derive(Debug, Clone, PartialEq, Eq)]
104pub struct ActionUsage {
105 pub name: String,
106 pub type_name: String,
107 pub accept: Option<PayloadClause>,
109 pub send: Option<PayloadClause>,
111 pub body: ActionUsageBody,
112 pub name_span: Option<Span>,
114 pub type_ref_span: Option<Span>,
116}
117
118#[derive(Debug, Clone, PartialEq, Eq)]
120pub enum ActionUsageBody {
121 Semicolon,
122 Brace {
123 elements: Vec<Node<ActionUsageBodyElement>>,
124 },
125}
126
127#[derive(Debug, Clone, PartialEq, Eq)]
129pub enum ActionUsageBodyElement {
130 Error(Node<ParseErrorNode>),
131 Doc(Node<DocComment>),
132 Annotation(Node<Annotation>),
133 InOutDecl(Node<InOutDecl>),
134 RefDecl(Node<RefDecl>),
135 Bind(Node<Bind>),
136 Flow(Node<Flow>),
137 FirstStmt(Node<FirstStmt>),
138 MergeStmt(Node<MergeStmt>),
139 StateUsage(Node<StateUsage>),
140 ActionUsage(Box<Node<ActionUsage>>),
141 Assign(Node<AssignStmt>),
142 ForLoop(Node<ForLoop>),
143 ThenAction(Node<ThenAction>),
144 Decl(Node<ActionBodyDecl>),
145}
146
147#[derive(Debug, Clone, PartialEq, Eq)]
149pub struct ActionBodyDecl {
150 pub keyword: String,
151 pub text: String,
152}
153
154#[derive(Debug, Clone, PartialEq, Eq)]
156pub struct Flow {
157 pub from: Node<Expression>,
158 pub to: Node<Expression>,
159 pub body: ConnectBody,
160}
161
162#[derive(Debug, Clone, PartialEq, Eq)]
164pub struct FlowDef {
165 pub identification: Identification,
166 pub specializes: Option<String>,
167 pub specializes_span: Option<Span>,
168 pub body: DefinitionBody,
169}
170
171#[derive(Debug, Clone, PartialEq, Eq)]
173pub struct FlowUsage {
174 pub name: String,
175 pub type_name: Option<String>,
176 pub from: Option<Node<Expression>>,
177 pub to: Option<Node<Expression>>,
178 pub body: DefinitionBody,
179}
180
181#[derive(Debug, Clone, PartialEq, Eq)]
183pub struct FirstStmt {
184 pub first: Node<Expression>,
185 pub then: Node<Expression>,
186 pub body: FirstMergeBody,
187}
188
189#[derive(Debug, Clone, PartialEq, Eq)]
191pub struct MergeStmt {
192 pub merge: Node<Expression>,
193 pub body: FirstMergeBody,
194}
195
196#[derive(Debug, Clone, PartialEq, Eq)]
198pub enum FirstMergeBody {
199 Semicolon,
200 Brace,
201}
202
203#[derive(Debug, Clone, PartialEq, Eq)]
209pub struct Allocate {
210 pub source: Node<Expression>,
211 pub target: Node<Expression>,
212 pub body: ConnectBody,
213}
214
215#[derive(Debug, Clone, PartialEq, Eq)]
217pub struct AllocationDef {
218 pub identification: Identification,
219 pub specializes: Option<String>,
220 pub specializes_span: Option<Span>,
221 pub body: DefinitionBody,
222}
223
224#[derive(Debug, Clone, PartialEq, Eq)]
226pub struct AllocationUsage {
227 pub name: String,
228 pub type_name: Option<String>,
229 pub source: Option<Node<Expression>>,
230 pub target: Option<Node<Expression>>,
231 pub body: DefinitionBody,
232}
233
234#[derive(Debug, Clone, PartialEq, Eq)]
240pub struct StateDef {
241 pub identification: Identification,
242 pub specializes: Option<String>,
243 pub specializes_span: Option<Span>,
244 pub body: StateDefBody,
245}
246
247#[derive(Debug, Clone, PartialEq, Eq)]
248pub enum StateDefBody {
249 Semicolon,
250 Brace {
251 elements: Vec<Node<StateDefBodyElement>>,
252 },
253}
254
255#[derive(Debug, Clone, PartialEq, Eq)]
256pub enum StateDefBodyElement {
257 Error(Node<ParseErrorNode>),
258 Doc(Node<DocComment>),
259 Annotation(Node<Annotation>),
260 MetadataKeywordUsage(Node<MetadataKeywordUsage>),
261 Other(String),
262 Entry(Node<EntryAction>),
264 Then(Node<ThenStmt>),
266 FinalState(Node<FinalState>),
268 Ref(Node<RefDecl>),
270 RequirementUsage(Node<RequirementUsage>),
271 StateUsage(Node<StateUsage>),
272 Transition(Node<Transition>),
273}
274
275#[derive(Debug, Clone, PartialEq, Eq)]
277pub struct EntryAction {
278 pub action_name: Option<String>,
280 pub body: StateDefBody,
281}
282
283#[derive(Debug, Clone, PartialEq, Eq)]
285pub struct ThenStmt {
286 pub state_name: String,
287 pub name_span: Option<Span>,
288}
289
290#[derive(Debug, Clone, PartialEq, Eq)]
292pub struct FinalState {
293 pub state_name: String,
294 pub name_span: Span,
295}
296
297#[derive(Debug, Clone, PartialEq, Eq)]
299pub struct StateUsage {
300 pub name: String,
301 pub type_name: Option<String>,
302 pub body: StateDefBody,
303}
304
305#[derive(Debug, Clone, PartialEq, Eq)]
307pub struct Transition {
308 pub name: Option<String>,
309 pub source: Option<Node<Expression>>,
311 pub is_initial: bool,
313 pub accept: Option<TransitionAccept>,
315 pub guard: Option<Node<Expression>>,
316 pub effect: Option<Node<Expression>>,
317 pub target: Node<Expression>,
318 pub body: ConnectBody,
319}
320
321