Statifier (statifier v1.5.0)

View Source

Main entry point for parsing and validating SCXML documents.

Provides a convenient API for parsing SCXML with automatic validation and optimization, including relaxed parsing mode for simplified tests.

Summary

Functions

Parse and validate an SCXML document in one step.

Parse an SCXML document without validation (not recommended).

Check if a document has been validated.

Functions

interpret(document)

See Statifier.Interpreter.initialize/1.

parse(xml_string, opts \\ [])

@spec parse(
  String.t(),
  keyword()
) ::
  {:ok, Statifier.Document.t(), [String.t()]}
  | {:error, term()}
  | {:error, {:warnings, [String.t()]}}

Parse and validate an SCXML document in one step.

This is the recommended way to parse SCXML documents as it ensures the document is validated and optimized for runtime use.

Options

  • :relaxed - Enable relaxed parsing mode (default: true)
    • Auto-adds xmlns and version attributes if missing
    • Preserves line numbers by skipping XML declaration by default
  • :xml_declaration - Add XML declaration in relaxed mode (default: false)
    • Set to true to add XML declaration (shifts line numbers by 1)
  • :validate - Enable validation and optimization (default: true)
  • :strict - Treat warnings as errors (default: false)

Examples

# Simple usage with relaxed parsing
iex> {:ok, doc, _warnings} = Statifier.parse(~s(<scxml initial="start"><state id="start"/></scxml>))
iex> doc.validated
true

# Skip validation for speed (not recommended)
iex> xml = ~s(<scxml initial="start"><state id="start"/></scxml>)
iex> {:ok, doc, []} = Statifier.parse(xml, validate: false)
iex> doc.validated
false

parse_only(xml_string, opts \\ [])

@spec parse_only(
  String.t(),
  keyword()
) :: {:ok, Statifier.Document.t()} | {:error, term()}

Parse an SCXML document without validation (not recommended).

This is a convenience function for cases where you need only parsing without validation. For most use cases, use parse/2 instead.

validate(document)

See Statifier.Validator.validate/1.

validated?(document)

@spec validated?(Statifier.Document.t()) :: boolean()

Check if a document has been validated.

Returns true if the document has been processed through the validator, regardless of whether it passed validation.