Skip to content

Latest commit

 

History

History
121 lines (95 loc) · 5.93 KB

desugar.md

File metadata and controls

121 lines (95 loc) · 5.93 KB

De-sugaring state machines

State machine cat supports the choice, fork, join and junction pseudo states from the UML state chart specification. They make some state charts more readable, but in themselves don't add to the expressive power of state charts. Each of these pseudo elements can be expressed in states and transitions.

As from version 5.2.0 state-machine-cat's command line interface, api and website have a switch for de-sugaring fork, junction and choice pseudo states as described below.

  • Command line: pass the --desugar flag
  • state-machine-cat.js.org: flick the desugar (experimental!) switch to on
  • API: pass the desugar flag ({desugar: true})

The feature is experimental, which means the feature can get a breaking change without state-machine-cat getting a major bump.

How, though?

De-sugaring consists of

  • connecting all states that transition into that pseudo state to all states the pseudo state transitions into one transition
  • combining any events, conditions and actions that exist on the incoming and outgoing transtions of the pseudo state.

Combining is straightforward when the attribute is only on the incoming or only on the outgoing transition. When they're defined on both, though, we need conflict resolution (for samples - see below). State-machine-cat curently does that like this:

  • for events and conditions the one on the outgoing transition wins. Typically events and conditions are allowed on one side of a pseudo state only (see below), so this should work out just fine for all situations.
  • actions are allowed on most sides of pseudo states, so these get combined - in the order incoming action > outgoing action.

De-sugaring fork

A fork is a pseudo-state that forks a transition into more than one parallel ones.

fork – fork Pseudostates serve to split an incoming Transition into two or more Transitions terminating on Vertices in orthogonal Regions of a composite State. The Transitions outgoing from a fork Pseudostate cannot have a guard or a trigger.

--- OMG Unified Modeling Language (OMG UML) Version 2.5.1 - p 315

pics/desugar-02-fork.png => pics/desugar-02-fork-desugared.png

De-sugaring junctions

A junction is a pseudo-state that (typically) connects multiple states with multiple other states.

junction – This type of Pseudostate is used to connect multiple Transitions into compound paths between States. For example, a junction Pseudostate can be used to merge multiple incoming Transitions into a single outgoing Transition representing a shared continuation path. Or, it can be used to split an incoming Transition into multiple outgoing Transition segments with different guard Constraints.

--- OMG Unified Modeling Language (OMG UML) Version 2.5.1 - p 315

pics/desugar-03-junction.png => pics/desugar-03-junction-desugared.png

De-sugaring choice

choice – This type of Pseudostate is similar to a junction Pseudostate (see above) and serves similar purposes, with the difference that the guard Constraints on all outgoing Transitions are evaluated dynamically, when the compound transition traversal reaches this Pseudostate. Consequently, choice is used to realize a dynamic conditional branch. It allows splitting of compound transitions into multiple alternative paths such that the decision on which path to take may depend on the results of Behavior executions performed in the same compound transition prior to reaching the choice point. If more than one guard evaluates to true, one of the corresponding Transitions is selected. The algorithm for making this selection is not defined. If none of the guards evaluates to true, then the model is considered ill formed. To avoid this, it is recommended to define one outgoing Transition with the predefined “else” guard for every choice Pseudostate.

--- OMG Unified Modeling Language (OMG UML) Version 2.5.1 - p 315

pics/desugar-04-choice.png => pics/desugar-04-choice-desugared.png

De-sugaring join => nope!

A join is a pseudo-state that joins two or more parallel transitions into one. It also waits until all incoming transitions are done.

join – This type of Pseudostate serves as a common target Vertex for two or more Transitions originating from Vertices in different orthogonal Regions. Transitions terminating on a join Pseudostate cannot have a guard or a trigger. Similar to junction points in Petri nets, join Pseudostates perform a synchronization function, whereby all incoming Transitions have to complete before execution can continue through an outgoing Transition.

--- OMG Unified Modeling Language (OMG UML) Version 2.5.1 - p 315

This means that it's not possible to replace a join pseudo state with its incoming and outgoing transitions without losing information. When state-machine-cat desugars, it will leave join states alone. In the future this behavior might become overrideable. When implemented the desugaring would have looked like this:

pics/desugar-01-join.png => pics/desugar-01-join-desugared.png

The semantics of initial

The initial pseudo state is actually a trick to show what the actual initial state is.

pics/desugar-05-initial.png