SC.ConditionEvaluator (sc v1.0.2)

View Source

Handles compilation and evaluation of SCXML conditional expressions using Predicator.

Supports SCXML-specific built-in functions:

  • In(state_id) - Check if state machine is in a given state
  • _event.name - Access current event name
  • _event.data - Access event data

Summary

Functions

Build SCXML evaluation context from interpreter state.

Build SCXML-specific functions for Predicator v2.0.

Compile a conditional expression string into predicator instructions.

Evaluate a compiled condition with SCXML context.

Check if the current configuration contains a specific state (In function). This is used for SCXML In() predicate support.

Functions

build_scxml_context(context)

@spec build_scxml_context(map()) :: map()

Build SCXML evaluation context from interpreter state.

build_scxml_functions(context)

@spec build_scxml_functions(map()) :: %{
  required(String.t()) => {integer(), function()}
}

Build SCXML-specific functions for Predicator v2.0.

Returns a map of function names to {arity, function} tuples for use with the functions option in Predicator.evaluate/3.

compile_condition(expression)

@spec compile_condition(String.t() | nil) ::
  {:ok, term()} | {:error, term()} | {:ok, nil}

Compile a conditional expression string into predicator instructions.

Returns {:ok, compiled} on success, {:error, reason} on failure.

evaluate_condition(compiled_cond, context)

@spec evaluate_condition(term() | nil, map()) :: boolean()

Evaluate a compiled condition with SCXML context.

Context includes:

  • Current state configuration
  • Current event
  • Data model variables

Returns boolean result. On error, returns false per SCXML spec.

in_state?(state_id, arg2)

@spec in_state?(String.t(), map()) :: boolean()

Check if the current configuration contains a specific state (In function). This is used for SCXML In() predicate support.