momba_explore/model/
actions.rs

1use serde::{Deserialize, Serialize};
2
3use super::expressions::*;
4
5/// Represents an *action pattern*.
6///
7/// Action patterns enable value passing.
8/// A pattern is either *silent* or *labeled*.
9/// Analogously to labeled actions, labeled patterns have a sequence of arguments
10/// represented by [PatternArgument].
11/// A pattern argument has a *direction* which is either *read* or *write*.
12/// A read argument means that the pattern is able to receive a value via the
13/// corresponding argument of an action.
14/// A write argument means that the pattern will send a value via the corresponding
15/// argument of an action.
16#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug)]
17#[serde(rename_all = "SCREAMING_SNAKE_CASE", tag = "kind")]
18pub enum ActionPattern {
19    /// The silent pattern.
20    Silent,
21    /// A labeled pattern.
22    Labeled(LabeledPattern),
23}
24
25/// Represents a labeled pattern.
26#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug)]
27pub struct LabeledPattern {
28    /// The label of the pattern.
29    pub label: String,
30    /// The pattern arguments.
31    pub arguments: Vec<PatternArgument>,
32}
33
34/// Represents a pattern argument.
35#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug)]
36#[serde(rename_all = "SCREAMING_SNAKE_CASE", tag = "direction")]
37pub enum PatternArgument {
38    Write { value: Expression },
39    Read { identifier: String },
40}
41
42#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug)]
43pub struct WriteArgument {
44    pub value: Expression,
45}
46
47#[derive(Serialize, Deserialize, Eq, PartialEq, Clone, Debug)]
48pub struct ReadArgument {
49    pub identifier: String,
50}