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.

../../../_images/states_with_transitions.svg

States with transitions#

The following figure shows the classes hierarchy when one uses states without transitions and separate transition declaration syntax.

../../../_images/states_and_transitions.svg

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.

get_full_path() str#

Full path of Swan construct.

static set_owner(owner: Self, children: Self | Iterable[Self])#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem]]

Items to set owner.

property is_equation: bool#

True when the object is an equation.

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 model: Model#

Return model containing the Swan item.

property module: ModuleBase#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface

property name: Luid | None#

Return name or None if no name.

property owner: Self#

Owner of current Swan construct.

class ansys.scadeone.core.swan.StateMachineItem#

Bases: SwanItem, ABC

Base class for state machine items (states and transitions).

get_full_path() str#

Full path of Swan construct.

static set_owner(owner: Self, children: Self | Iterable[Self])#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem]]

Items to set owner.

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 model: Model#

Return model containing the Swan item.

property module: ModuleBase#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface

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.

get_full_path() str#

Full path of Swan construct.

pragma_str() str#

Return a string with all pragmas.

static set_owner(owner: Self, children: Self | Iterable[Self])#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem]]

Items to set owner.

property has_body: bool#

True when state has a body, namely scope sections.

property has_strong_transition: bool#

True when state has strong transitions.

property has_weak_transition: bool#

True when state has weak transitions.

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 model: Model#

Return model containing the Swan item.

property module: ModuleBase#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface

property owner: Self#

Owner of current Swan construct.

property pragmas: List[Pragma]#

List of pragmas.

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.

get_full_path() str#

Full path of Swan construct.

static set_owner(owner: Self, children: Self | Iterable[Self])#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem]]

Items to set owner.

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 lunum: Luid | None#

Lunum part, possible None.

property model: Model#

Return model containing the Swan item.

property module: ModuleBase#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface

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 )) transition
priority ::= : [[ INTEGER ]] :
get_full_path() str#

Full path of Swan construct.

static set_owner(owner: Self, children: Self | Iterable[Self])#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem]]

Items to set owner.

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_strong: bool#

True when strong transition, else weak transition.

property model: Model#

Return model containing the Swan item.

property module: ModuleBase#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface

property owner: Self#

Owner of current Swan construct.

property priority: Literal | None#

Transition priority.

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 ;
get_full_path() str#

Full path of Swan construct.

pragma_str() str#

Return a string with all pragmas.

static set_owner(owner: Self, children: Self | Iterable[Self])#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem]]

Items to set owner.

property arrow: Arrow#

Transition arrow.

property is_guarded: bool#

True when arrow is guarded.

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 model: Model#

Return model containing the Swan item.

property module: ModuleBase#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface

property owner: Self#

Owner of current Swan construct.

property pragmas: List[Pragma]#

List of pragmas.

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 ) arrow
arrow ::= [[ scope ]] (( target | fork ))
get_full_path() str#

Full path of Swan construct.

static set_owner(owner: Self, children: Self | Iterable[Self])#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem]]

Items to set owner.

property action: Scope | None#

Arrow action or None.

property fork: Fork | None#

Arrow fork.

property guard: Scope | None#

Arrow guard or 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 is_valid#

Check whether the arrow has a target or a fork.

property model: Model#

Return model containing the Swan item.

property module: ModuleBase#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface

property owner: Self#

Owner of current Swan construct.

property target: Target | None#

Arrow target.

class ansys.scadeone.core.swan.Target(target: StateRef, is_resume: bool | None = False)#

Bases: SwanItem

Arrow target as a state reference and kind.

get_full_path() str#

Full path of Swan construct.

static set_owner(owner: Self, children: Self | Iterable[Self])#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem]]

Items to set owner.

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_restart: bool#

True when is restart, else resume.

property is_resume: bool#

True when is resume, else restart.

property model: Model#

Return model containing the Swan item.

property module: ModuleBase#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface

property owner: Self#

Owner of current Swan construct.

property target: StateRef#

Target reference

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
get_full_path() str#

Full path of Swan construct.

static set_owner(owner: Self, children: Self | Iterable[Self])#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem]]

Items to set owner.

property else_arrow: Arrow | None#

Else arrow.

property elsif_arrows: List[Arrow]#

Elsif arrows list.

property if_arrow: Arrow#

Start 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 model: Model#

Return model containing the Swan item.

property module: ModuleBase#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface

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
get_full_path() str#

Full path of Swan construct.

static set_owner(owner: Self, children: Self | Iterable[Self])#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem]]

Items to set owner.

property arrow: Arrow#

For arrow.

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 model: Model#

Return model containing the Swan item.

property module: ModuleBase#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface

property owner: Self#

Owner of current Swan construct.

property priority: Literal | None#

Fork priority.

class ansys.scadeone.core.swan.ForkPriorityList(prio_forks: List[ForkWithPriority])#

Bases: Fork

List of ForkWithPriority.

fork ::= {{ fork_priority }} end

get_full_path() str#

Full path of Swan construct.

static set_owner(owner: Self, children: Self | Iterable[Self])#

Helper to set owner as the owner of each item in the Iterable items.

Parameters:
ownerSwanItem

Owner of the items.

childrenUnion[SwanItem, Iterable[SwanItem]]

Items to set owner.

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 model: Model#

Return model containing the Swan item.

property module: ModuleBase#

Module containing the item.

Returns:

ModuleBase: module container, see ModuleBody and ModuleInterface

property owner: Self#

Owner of current Swan construct.

property prio_forks: List[ForkWithPriority]#

List of fork with priority.