SC.Interpreter (sc v1.0.2)

View Source

Core interpreter for SCXML state charts.

Provides a synchronous, functional API for state chart execution. Documents are automatically validated before interpretation.

Summary

Functions

Check if a specific state is currently active (including ancestors).

Get all currently active states including ancestors.

Get all currently active leaf states (not including ancestors).

Initialize a state chart from a parsed document.

Send an event to the state chart and return the new state (macrostep execution).

Functions

active?(state_chart, state_id)

@spec active?(SC.StateChart.t(), String.t()) :: boolean()

Check if a specific state is currently active (including ancestors).

active_ancestors(state_chart)

@spec active_ancestors(SC.StateChart.t()) :: MapSet.t(String.t())

Get all currently active states including ancestors.

active_states(state_chart)

@spec active_states(SC.StateChart.t()) :: MapSet.t(String.t())

Get all currently active leaf states (not including ancestors).

initialize(document)

@spec initialize(SC.Document.t()) ::
  {:ok, SC.StateChart.t()} | {:error, [String.t()], [String.t()]}

Initialize a state chart from a parsed document.

Automatically validates the document and sets up the initial configuration.

send_event(state_chart, event)

@spec send_event(SC.StateChart.t(), SC.Event.t()) :: {:ok, SC.StateChart.t()}

Send an event to the state chart and return the new state (macrostep execution).

Processes the event according to SCXML semantics:

  1. Find enabled transitions for the current configuration
  2. Execute the optimal transition set as a microstep
  3. Execute any resulting eventless transitions (additional microsteps)
  4. Return stable configuration (end of macrostep)

Returns the updated state chart. If no transitions match, returns the state chart unchanged (silent handling as discussed).