use super::common::{ConnectBody, DocComment, Identification, ParseErrorNode};
use super::requirement::RequirementUsage;
use super::structure::{
Annotation, Bind, DefinitionBody, MetadataAnnotation, MetadataKeywordUsage, Perform, RefDecl,
};
use crate::ast::core::{Expression, Node, Span};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ActionDef {
pub identification: Identification,
pub specializes: Option<String>,
pub specializes_span: Option<Span>,
pub body: ActionDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ActionDefBody {
Semicolon,
Brace {
elements: Vec<Node<ActionDefBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ActionDefBodyElement {
Error(Node<ParseErrorNode>),
InOutDecl(Node<InOutDecl>),
Doc(Node<DocComment>),
Annotation(Node<Annotation>),
MetadataAnnotation(Node<MetadataAnnotation>),
RefDecl(Node<RefDecl>),
Perform(Node<Perform>),
Bind(Node<Bind>),
Flow(Node<Flow>),
FirstStmt(Node<FirstStmt>),
MergeStmt(Node<MergeStmt>),
StateUsage(Node<StateUsage>),
ActionUsage(Box<Node<ActionUsage>>),
Assign(Node<AssignStmt>),
ForLoop(Node<ForLoop>),
ThenAction(Node<ThenAction>),
Decl(Node<ActionBodyDecl>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AssignStmt {
pub is_then: bool,
pub lhs: String,
pub rhs: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ForLoop {
pub var: String,
pub range: String,
pub body: ActionDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ThenAction {
pub action: Node<ActionUsage>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InOutDecl {
pub direction: InOut,
pub name: String,
pub type_name: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InOut {
In,
Out,
InOut,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PayloadClause {
pub name: String,
pub type_name: Option<String>,
pub name_span: Span,
pub type_span: Option<Span>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TransitionAccept {
Payload(PayloadClause),
Shorthand(Node<Expression>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ActionUsage {
pub name: String,
pub type_name: String,
pub accept: Option<PayloadClause>,
pub send: Option<PayloadClause>,
pub body: ActionUsageBody,
pub name_span: Option<Span>,
pub type_ref_span: Option<Span>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ActionUsageBody {
Semicolon,
Brace {
elements: Vec<Node<ActionUsageBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ActionUsageBodyElement {
Error(Node<ParseErrorNode>),
Doc(Node<DocComment>),
Annotation(Node<Annotation>),
MetadataAnnotation(Node<MetadataAnnotation>),
InOutDecl(Node<InOutDecl>),
RefDecl(Node<RefDecl>),
Bind(Node<Bind>),
Flow(Node<Flow>),
FirstStmt(Node<FirstStmt>),
MergeStmt(Node<MergeStmt>),
StateUsage(Node<StateUsage>),
ActionUsage(Box<Node<ActionUsage>>),
Assign(Node<AssignStmt>),
ForLoop(Node<ForLoop>),
ThenAction(Node<ThenAction>),
Decl(Node<ActionBodyDecl>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ActionBodyDecl {
pub keyword: String,
pub text: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Flow {
pub from: Node<Expression>,
pub to: Node<Expression>,
pub body: ConnectBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FlowDef {
pub identification: Identification,
pub specializes: Option<String>,
pub specializes_span: Option<Span>,
pub body: DefinitionBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FlowUsage {
pub name: String,
pub type_name: Option<String>,
pub from: Option<Node<Expression>>,
pub to: Option<Node<Expression>>,
pub body: DefinitionBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FirstStmt {
pub first: Node<Expression>,
pub then: Node<Expression>,
pub body: FirstMergeBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MergeStmt {
pub merge: Node<Expression>,
pub body: FirstMergeBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FirstMergeBody {
Semicolon,
Brace,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Allocate {
pub source: Node<Expression>,
pub target: Node<Expression>,
pub body: ConnectBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AllocationDef {
pub identification: Identification,
pub specializes: Option<String>,
pub specializes_span: Option<Span>,
pub body: DefinitionBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AllocationUsage {
pub name: String,
pub type_name: Option<String>,
pub source: Option<Node<Expression>>,
pub target: Option<Node<Expression>>,
pub body: DefinitionBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StateDef {
pub identification: Identification,
pub specializes: Option<String>,
pub specializes_span: Option<Span>,
pub body: StateDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum StateDefBody {
Semicolon,
Brace {
elements: Vec<Node<StateDefBodyElement>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum StateDefBodyElement {
Error(Node<ParseErrorNode>),
Doc(Node<DocComment>),
Annotation(Node<Annotation>),
MetadataKeywordUsage(Node<MetadataKeywordUsage>),
Other(String),
Entry(Node<EntryAction>),
Then(Node<ThenStmt>),
FinalState(Node<FinalState>),
Ref(Node<RefDecl>),
RequirementUsage(Node<RequirementUsage>),
StateUsage(Node<StateUsage>),
Transition(Node<Transition>),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EntryAction {
pub action_name: Option<String>,
pub body: StateDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ThenStmt {
pub state_name: String,
pub name_span: Option<Span>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FinalState {
pub state_name: String,
pub name_span: Span,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StateUsage {
pub name: String,
pub type_name: Option<String>,
pub body: StateDefBody,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Transition {
pub name: Option<String>,
pub source: Option<Node<Expression>>,
pub is_initial: bool,
pub accept: Option<TransitionAccept>,
pub guard: Option<Node<Expression>>,
pub effect: Option<Node<Expression>>,
pub target: Node<Expression>,
pub body: ConnectBody,
}