State machines#
The Swan language has two syntax to express state machines:
a state machine is a collection of states, each state having strong and weak transitions;
a state machine is a collection of:
states, where states do not have transitions;
transition declarations, which describe the transitions as separate items.
A StateMachine
contains therefore a list of states and possibly transition declarations, all
as instances of StateMachineItem
.
The following figure shows the classes hierarchy when one uses states with transitions syntax.
States with transitions#
The following figure shows the classes hierarchy when one uses states without transitions and separate transition declaration syntax.
States and transition declarations#
Note
Both representations are not exclusive, though it is not expected to have a mixed definition of a state machine with states and their transitions, and separate transitions.
- class ansys.scadeone.core.swan.StateMachine(lhs: EquationLHS | None = None, items: List[StateMachineItem] | None = None, name: Luid | None = None, is_equation: bool = False)#
Bases:
DefByCase
State machine definition.
- static set_owner(owner: Self, children: Self | Iterable[Self])#
Helper to set owner as the owner of each item in the Iterable items.
- property is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
- property items: List[StateMachineItem]#
Transitions and states of the state machine.
- property lhs: EquationLHS | None#
Left-hand side of the equation, may be None.
- property module: ModuleBase#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
- property owner: Self#
Owner of current Swan construct.
- class ansys.scadeone.core.swan.StateMachineItem#
-
Base class for state machine items (states and transitions).
- static set_owner(owner: Self, children: Self | Iterable[Self])#
Helper to set owner as the owner of each item in the Iterable items.
- property is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
- property module: ModuleBase#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
- property owner: Self#
Owner of current Swan construct.
States#
- class ansys.scadeone.core.swan.State(id: Identifier | None = None, lunum: Lunum | None = None, strong_transitions: List[Transition] | None = None, sections: List[ScopeSection] | None = None, weak_transitions: List[Transition] | None = None, is_initial: bool | None = False, pragmas: List[Pragma] | None = None)#
Bases:
StateMachineItem
,PragmaBase
State definition.
- static set_owner(owner: Self, children: Self | Iterable[Self])#
Helper to set owner as the owner of each item in the Iterable items.
- property is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
- property module: ModuleBase#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
- property owner: Self#
Owner of current Swan construct.
- class ansys.scadeone.core.swan.StateRef(lunum: Lunum | None = None, id: Identifier | None = None)#
Bases:
SwanItem
State identification:
state_ref ::= ID | LUNUM
The class is also used for transition declaration or target (restart/resume) where one has either an ID or a LUNUM.
- static set_owner(owner: Self, children: Self | Iterable[Self])#
Helper to set owner as the owner of each item in the Iterable items.
- property id: Identifier | None#
Id part, possible None.
- property is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
- property module: ModuleBase#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
- property owner: Self#
Owner of current Swan construct.
Transitions#
- class ansys.scadeone.core.swan.TransitionDecl(priority: Literal | None, transition: Transition, is_strong: bool, state_ref: StateRef)#
Bases:
StateMachineItem
Declaration of state machine transition:
transition_decl ::= priority [[ state_ref ]](( unless | until )) transitionpriority ::= : [[ INTEGER ]] :- static set_owner(owner: Self, children: Self | Iterable[Self])#
Helper to set owner as the owner of each item in the Iterable items.
- property is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
- property module: ModuleBase#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
- property owner: Self#
Owner of current Swan construct.
- property transition: Transition#
Transition data.
- class ansys.scadeone.core.swan.Transition(arrow: Arrow, pragmas: List[Pragma] | None = None)#
Bases:
SwanItem
,PragmaBase
State machine transition:
transition ::= if guarded_arrow ;| [[ scope ]] target ;- static set_owner(owner: Self, children: Self | Iterable[Self])#
Helper to set owner as the owner of each item in the Iterable items.
- property is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
- property module: ModuleBase#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
- property owner: Self#
Owner of current Swan construct.
- class ansys.scadeone.core.swan.Arrow(guard: Expression | None, action: Scope | None, target: Target | None = None, fork: Fork | None = None)#
Bases:
SwanItem
Encode an arrow, with or without guard:
guarded_arrow ::= ( expr ) arrowarrow ::= [[ scope ]] (( target | fork ))- static set_owner(owner: Self, children: Self | Iterable[Self])#
Helper to set owner as the owner of each item in the Iterable items.
- property is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
- property is_valid#
Check whether the arrow has a target or a fork.
- property module: ModuleBase#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
- property owner: Self#
Owner of current Swan construct.
- class ansys.scadeone.core.swan.Target(target: StateRef, is_resume: bool | None = False)#
Bases:
SwanItem
Arrow target as a state reference and kind.
- static set_owner(owner: Self, children: Self | Iterable[Self])#
Helper to set owner as the owner of each item in the Iterable items.
- property is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
- property module: ModuleBase#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
- property owner: Self#
Owner of current Swan construct.
Forks#
Forks are transitions which split into several branches.
State with transitions#
A fork a succession of if then else with Arrow
.
- class ansys.scadeone.core.swan.ForkTree(if_arrow: Arrow, elsif_arrows: List[Arrow] | None = None, else_arrow: Arrow | None = None)#
Bases:
Fork
Fork as a tree of arrows:
fork ::= if guarded_arrow{{ elsif guarded_arrow }}[[ else arrow ]]end- static set_owner(owner: Self, children: Self | Iterable[Self])#
Helper to set owner as the owner of each item in the Iterable items.
- property is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
- property module: ModuleBase#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
- property owner: Self#
Owner of current Swan construct.
Separate transitions#
Fork is a list of if and one else arrows with priorities.
- class ansys.scadeone.core.swan.ForkWithPriority(priority: Literal | None, arrow: Arrow, is_if_arrow: bool)#
Bases:
SwanItem
Fork as a priority fork declaration:
fork_priority ::= priority if guarded_arrow| priority **else* arrow- static set_owner(owner: Self, children: Self | Iterable[Self])#
Helper to set owner as the owner of each item in the Iterable items.
- property is_if_arrow: bool#
True when fork is priority if guarded_arrow, False if fork is priority else arrow.
- property is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
- property is_valid: bool#
Check if fork is either an if with a guarded_arrow, or an else with an arrow.
- property module: ModuleBase#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
- property owner: Self#
Owner of current Swan construct.
- class ansys.scadeone.core.swan.ForkPriorityList(prio_forks: List[ForkWithPriority])#
Bases:
Fork
List of
ForkWithPriority
.fork ::= {{ fork_priority }} end
- static set_owner(owner: Self, children: Self | Iterable[Self])#
Helper to set owner as the owner of each item in the Iterable items.
- property is_protected: bool#
Tell if a construct item is syntactically protected with some markup and is stored as a string (without the markup).
- property module: ModuleBase#
Module containing the item.
- Returns:
ModuleBase: module container, see
ModuleBody
andModuleInterface
- property owner: Self#
Owner of current Swan construct.
- property prio_forks: List[ForkWithPriority]#
List of fork with priority.