Choreo.Lab.DSL.FSM (Choreo v0.12.0)

Copy Markdown View Source

Experimental Livebook-friendly DSL for sketching finite-state machines.

This Lab DSL compiles to the stable, pipe-first Choreo.FSM builders and returns an ordinary %Choreo.FSM{}. It follows the same identity rule as the infrastructure Lab DSL: in assignment form, the variable name becomes the node id and the string becomes the display label; in inline form, the string is slugged into an id and also used as the label.

Examples

iex> import Choreo.Lab.DSL.FSM
...> machine = fsm do
...>   idle = initial("Idle")
...>   authorized = state("Authorized")
...>   denied = final("Denied")
...>
...>   idle ~> authorized |> on("token valid")
...>   edge idle ~> denied, with: "token invalid"
...> end
iex> Choreo.FSM.initial_state(machine)
:idle
iex> Choreo.FSM.final_states(machine)
[:denied]
iex> Choreo.FSM.transitions(machine) |> Enum.sort()
[{:idle, :authorized, "token valid"}, {:idle, :denied, "token invalid"}]

Transition labels can use pipe modifiers or the explicit edge form:

idle ~> authorized |> on("token valid")
idle ~> authorized |> label("token valid")
idle ~> authorized |> guard("claims.tenant == request.tenant")
edge idle ~> denied, "token invalid"
edge idle ~> denied, with: "token invalid"
edge idle ~> denied, label: "token invalid"

Summary

Types

state_decl()

@type state_decl() :: %{id: Yog.node_id(), builder: atom(), opts: keyword()}

transition_decl()

@type transition_decl() :: %{from: Yog.node_id(), to: Yog.node_id(), opts: keyword()}

Functions

done(arg1 \\ nil, arg2 \\ nil, opts \\ [])

final(arg1 \\ nil, arg2 \\ nil, opts \\ [])

fsm(list)

(macro)

Builds a %Choreo.FSM{} from a compact Lab DSL block.

fsm(opts, list)

(macro)

init(arg1 \\ nil, arg2 \\ nil, opts \\ [])

initial(arg1 \\ nil, arg2 \\ nil, opts \\ [])

start(arg1 \\ nil, arg2 \\ nil, opts \\ [])

state(arg1 \\ nil, arg2 \\ nil, opts \\ [])

taxonomy()

@spec taxonomy() :: %{
  states: [atom()],
  edges: [atom()],
  modifiers: [atom()],
  options: [atom()]
}

Returns the vocabulary supported by the FSM DSL.

This is meant as a lightweight Livebook discovery helper when autocomplete is not enough.

iex> taxonomy = Choreo.Lab.DSL.FSM.taxonomy()
iex> :initial in taxonomy.states
true
iex> :~> in taxonomy.edges
true
iex> :guard in taxonomy.modifiers
true

verbs()

@spec verbs() :: %{
  states: [atom()],
  edges: [atom()],
  modifiers: [atom()],
  options: [atom()]
}

Compatibility alias for taxonomy/0.