Statifier.Interpreter (statifier v1.9.0)
View SourceCore interpreter for SCXML state charts.
Provides a synchronous, functional API for state chart execution. Documents from Statifier.parse are used as-is (already validated). Unvalidated documents are automatically validated for backward compatibility.
Summary
Functions
Check if a specific state is currently active (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
@spec active?(Statifier.StateChart.t(), String.t()) :: boolean()
Check if a specific state is currently active (including ancestors).
@spec initialize(Statifier.Document.t()) :: {:ok, Statifier.StateChart.t()} | {:error, [String.t()], [String.t()]}
Initialize a state chart from a parsed document.
Documents from Statifier.parse are used directly (already validated). Unvalidated documents are validated automatically for backward compatibility.
Options
:log_adapter- Logging adapter configuration. Can be:- An adapter struct (e.g.,
%TestAdapter{max_entries: 100}) - A tuple
{AdapterModule, opts}(e.g.,{TestAdapter, [max_entries: 50]}) - If not provided, uses environment-specific defaults
- An adapter struct (e.g.,
:log_level- Minimum log level (:trace,:debug,:info,:warn,:error)- Defaults to
:debugin test environment,:infootherwise
- Defaults to
Examples
# Use default configuration
{:ok, state_chart} = Interpreter.initialize(document)
# Configure logging explicitly
{:ok, state_chart} = Interpreter.initialize(document, [
log_adapter: {TestAdapter, [max_entries: 100]},
log_level: :debug
])
@spec initialize( Statifier.Document.t(), keyword() ) :: {:ok, Statifier.StateChart.t()} | {:error, [String.t()], [String.t()]}
@spec send_event(Statifier.StateChart.t(), Statifier.Event.t()) :: {:ok, Statifier.StateChart.t()}
Send an event to the state chart and return the new state (macrostep execution).
Processes the event according to SCXML semantics:
- Find enabled transitions for the current configuration
- Execute the optimal transition set as a microstep
- Execute any resulting eventless transitions (additional microsteps)
- Return stable configuration (end of macrostep)
Returns the updated state chart. If no transitions match, returns the state chart unchanged (silent handling as discussed).