smlang: A no_std State Machine Language DSL in Rust

Build Status

A state machine language DSL based on the syntax of Boost-SML.

Aim

The aim of this DSL is to facilitate the use of state machines, as they quite fast can become overly complicated to write and get an overview of.

Transition DSL

The DSL is defined as follows (from Boost-SML):

rust statemachine!{ SrcState + Event [ guard ] / action = DstState, *SrcState + Event [ guard ] / action = DstState, // * denotes starting state // ... }

Where guard and action are optional and can be left out. A guard is a function which returns true if the state transition should happen, and false if the transition should not happen, while action are functions that are run during the transition which are guaranteed to finish before entering the new state.

This implies that any state machine must be written as a list of transitions.

TODOs

Features missing:

Examples

Here are some examples of state machines converted from UML to the State Machine Language DSL.

Linear state machine

alt text

DSL implementation:

rust statemachine!{ *State1 + Event1 = State2, State2 + Event2 = State3, }

Looping state machine

alt text

DSL implementation:

rust statemachine!{ *State1 + Event1 = State2, State2 + Event2 = State3, State3 + Event3 = State2, }

Using guards and actions

alt text

DSL implementation:

rust statemachine!{ *State1 + Event1 [guard] / action = State2, }

Contributors

List of contributors in alphabetical order:


License

Licensed under either of

at your option.