use serde::{Serialize, Deserialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Property {
pub sign: PropertySign,
pub name: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PropertySign {
Plus,
Minus,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Transition {
pub from: String,
pub to: String,
pub properties: Vec<Property>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Graph {
pub name: String,
pub transitions: Vec<Transition>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct GraphState {
pub graph_name: String,
pub current_nodes: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Model {
pub name: String,
pub graphs: Vec<Graph>,
pub state: Option<Vec<GraphState>>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Formula {
pub name: String,
pub expression: FormulaExpr,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum FormulaExpr {
True,
False,
And(Box<FormulaExpr>, Box<FormulaExpr>),
Or(Box<FormulaExpr>, Box<FormulaExpr>),
Not(Box<FormulaExpr>),
Paren(Box<FormulaExpr>),
Diamond(Vec<Property>, Box<FormulaExpr>),
Box(Vec<Property>, Box<FormulaExpr>),
}
impl Model {
pub fn new(name: String) -> Self {
Self {
name,
graphs: Vec::new(),
state: None,
}
}
pub fn add_graph(&mut self, graph: Graph) {
self.graphs.push(graph);
}
pub fn set_state(&mut self, state: Vec<GraphState>) {
self.state = Some(state);
}
}
impl Graph {
pub fn new(name: String) -> Self {
Self {
name,
transitions: Vec::new(),
}
}
pub fn add_transition(&mut self, transition: Transition) {
self.transitions.push(transition);
}
}
impl Transition {
pub fn new(from: String, to: String) -> Self {
Self {
from,
to,
properties: Vec::new(),
}
}
pub fn add_property(&mut self, property: Property) {
self.properties.push(property);
}
}
impl Property {
pub fn new(sign: PropertySign, name: String) -> Self {
Self { sign, name }
}
}
impl GraphState {
pub fn new(graph_name: String, current_nodes: Vec<String>) -> Self {
Self {
graph_name,
current_nodes,
}
}
}
impl Formula {
pub fn new(name: String, expression: FormulaExpr) -> Self {
Self { name, expression }
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum TopLevelItem {
Model(Model),
Formula(Formula),
}