Skip to content
This repository was archived by the owner on Sep 12, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 65 additions & 8 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ All parsed SCXML elements include precise source location information for valida

## Dependencies

- **`predicator`** (~> 2.0) - Safe condition (boolean predicate) evaluator
- **`saxy`** (~> 1.6) - Fast, memory-efficient SAX XML parser with position tracking support

## Development Dependencies
Expand Down Expand Up @@ -306,16 +307,72 @@ XML content within triple quotes uses 4-space base indentation.
- **Modular validator architecture** - refactored from 386-line monolith into focused modules
- **Full Credo compliance** - all code quality issues resolved

🚧 **Future Extensions:**
## SCXML Feature Implementation Roadmap

- History states (`<history>`) - missing from parser and interpreter
- Internal transitions (`type="internal"`) and targetless transitions
- Executable content elements (`<onentry>`, `<onexit>`, `<raise>`, `<assign>`, `<script>`, `<send>`)
- Enhanced datamodel support with more expression functions
- Enhanced validation for complex SCXML constructs
- Additional parser formats (JSON, YAML) leveraging same validation/optimization pipeline
📋 **Comprehensive Implementation Plan Available**: See `documentation/SCXML_IMPLEMENTATION_PLAN.md` for detailed 3-phase roadmap to achieve 98%+ test coverage across 444 SCION and W3C tests.

The implementation follows the W3C SCXML specification closely and includes comprehensive test coverage from both W3C and SCION test suites. The current interpreter provides a solid foundation for basic SCXML functionality with clear areas identified for future enhancement.
### Current Implementation Status (Phase 0 - Complete)

✅ **Structural SCXML Features** - Complete W3C compliance for basic state machine functionality:

- Core state machine elements (states, transitions, parallel, initial)
- SCXML-compliant processing model (microstep/macrostep, exit sets, LCCA)
- Conditional transitions with expression evaluation
- Eventless/automatic transitions (NULL transitions)
- Feature detection and test validation infrastructure

**Current Test Coverage**: 294/444 tests passing (66.2%)

### Planned Implementation Phases

🚧 **Phase 1: Basic Executable Content (2-3 weeks)**
**Target**: Unlock 80-100 additional tests (30% improvement)

- **`<onentry>` / `<onexit>` actions** - Execute actions during state entry/exit
- **`<raise event="name"/>` elements** - Generate internal events
- **`<log expr="message"/>` elements** - Debug logging support
- **Action execution framework** - Infrastructure for executable content

**Expected Outcome**: ~374 tests passing (84% coverage)

🚧 **Phase 2: Data Model & Expression Evaluation (4-6 weeks)**
**Target**: Unlock 50-70 additional tests (25% improvement)

- **`<datamodel>` / `<data>` elements** - Variable storage and initialization
- **`<assign location="var" expr="value"/>` elements** - Variable assignment
- **JavaScript expression engine** - Full ECMAScript expression support
- **Enhanced condition evaluation** - Access to datamodel variables

**Expected Outcome**: ~420 tests passing (95% coverage)

🚧 **Phase 3: Advanced Features (2-3 weeks)**
**Target**: Achieve comprehensive SCXML support (98%+ coverage)

- **`<history>` states** - Shallow and deep history state support
- **`<send>` elements** - External event sending with delays
- **`<script>` elements** - Inline JavaScript execution
- **Internal/targetless transitions** - Advanced transition behaviors

**Expected Outcome**: ~440+ tests passing (98%+ coverage)

### Implementation Architecture

The phased approach maintains backward compatibility while systematically adding SCXML features:

1. **Parser Extensions**: Add executable content parsing to existing SAX-based parser
2. **Interpreter Integration**: Extend microstep/macrostep processing with action execution
3. **Data Model Layer**: Add variable storage and JavaScript expression evaluation
4. **Feature Detection Updates**: Maintain comprehensive feature tracking
5. **Test Coverage Validation**: Ensure each phase improves test coverage without regressions

### Success Metrics

- **Phase 1**: 370+ tests passing, all basic executable content working
- **Phase 2**: 415+ tests passing, full datamodel and expression support
- **Phase 3**: 435+ tests passing, comprehensive SCXML implementation
- **Final Goal**: 98%+ test coverage, industry-leading SCXML compliance

The implementation plan transforms SC from a basic state machine library into a comprehensive, production-ready SCXML engine with industry-leading test coverage and W3C compliance.

- Always refer to state machines as state charts
- Always run 'mix format' after writing an Elixir file.
35 changes: 12 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ An Elixir implementation of SCXML (State Chart XML) state charts with a focus on

### **✅ SCXML-Compliant Processing Engine**

**COMPLETED** - Full W3C SCXML specification compliance with proper domain terminology:

- **`Microstep/Macrostep Execution`** - Implements SCXML event processing model with microstep (single transition set execution) and macrostep (series of microsteps until stable)
- **`Eventless Transitions`** - Transitions without event attributes (called NULL transitions in SCXML spec) that fire automatically upon state entry
- **`Exit Set Computation`** - Implements W3C SCXML exit set calculation algorithm for determining which states to exit during transitions
Expand All @@ -73,8 +71,6 @@ An Elixir implementation of SCXML (State Chart XML) state charts with a focus on

### **✅ Enhanced Parallel State Support**

**COMPLETED** - Fixed critical regression and enhanced parallel state semantics:

- **`Cross-Parallel Boundaries`** - Proper exit semantics when transitions leave parallel regions
- **`Sibling State Management`** - Automatic exit of parallel siblings when transitions exit their shared parent
- **`Self-Transitions`** - Transitions within parallel regions preserve unaffected parallel regions
Expand All @@ -83,17 +79,13 @@ An Elixir implementation of SCXML (State Chart XML) state charts with a focus on

### **✅ Feature-Based Test Validation System**

**COMPLETED** - Improves test accuracy by validating that tests actually exercise intended SCXML functionality:

- **`SC.FeatureDetector`** - Analyzes SCXML documents to detect used features
- **Feature validation** - Tests fail when they depend on unsupported features
- **False positive prevention** - No more "passing" tests that silently ignore unsupported features
- **Capability tracking** - Clear visibility into which SCXML features are supported

### **✅ Modular Validator Architecture**

**COMPLETED** - Refactored monolithic validator into focused, maintainable modules:

- **`SC.Validator`** - Main orchestrator (from 386-line monolith)
- **`SC.Validator.StateValidator`** - State ID validation
- **`SC.Validator.TransitionValidator`** - Transition target validation
Expand All @@ -103,8 +95,6 @@ An Elixir implementation of SCXML (State Chart XML) state charts with a focus on

### **✅ Initial State Elements**

**COMPLETED** - Full W3C-compliant support for `<initial>` elements:

- **Parser support** - `<initial>` elements with `<transition>` children
- **Interpreter logic** - Proper initial state entry via initial elements
- **Comprehensive validation** - Conflict detection, target validation, structure validation
Expand All @@ -116,7 +106,6 @@ The next major areas for development focus on expanding SCXML feature support:

### **High Priority Features**

- **Conditional Transitions** - `cond` attribute evaluation for dynamic transitions
- **Executable Content** - `<onentry>`, `<onexit>`, `<assign>`, `<script>` elements
- **Datamodel Support** - `<data>` elements with expression evaluation
- **History States** - Shallow and deep history state support
Expand Down Expand Up @@ -156,10 +145,10 @@ xml = """
</scxml>
"""

{:ok, document} = SC.Parser.SCXML.parse(xml)
{:ok, document} = SC.parse(xml)

# Initialize state chart
{:ok, state_chart} = SC.Interpreter.initialize(document)
{:ok, state_chart} = SC.interpret(document)

# Check active states
active_states = SC.Interpreter.active_states(state_chart)
Expand Down Expand Up @@ -191,8 +180,8 @@ xml = """
</scxml>
"""

{:ok, document} = SC.Parser.SCXML.parse(xml)
{:ok, state_chart} = SC.Interpreter.initialize(document)
{:ok, document} = SC.parse(xml)
{:ok, state_chart} = SC.interpret(document)

# Eventless transitions processed automatically during initialization
active_states = SC.Interpreter.active_states(state_chart)
Expand Down Expand Up @@ -224,8 +213,8 @@ xml = """
</scxml>
"""

{:ok, document} = SC.Parser.SCXML.parse(xml)
{:ok, state_chart} = SC.Interpreter.initialize(document)
{:ok, document} = SC.parse(xml)
{:ok, state_chart} = SC.interpret(document)

# Both parallel regions active simultaneously
active_states = SC.Interpreter.active_states(state_chart)
Expand All @@ -235,9 +224,9 @@ active_states = SC.Interpreter.active_states(state_chart)
### Document Validation

```elixir
{:ok, document} = SC.Parser.SCXML.parse(xml)
{:ok, document} = SC.parse(xml)

case SC.Validator.validate(document) do
case SC..validate(document) do
{:ok, optimized_document, warnings} ->
# Document is valid and optimized, warnings are non-fatal
IO.puts("Valid document with #{length(warnings)} warnings")
Expand Down Expand Up @@ -338,13 +327,13 @@ mix test test/sc/parser/scxml_test.exs

```elixir
# 1. Parse: XML → Document structure
{:ok, document} = SC.Parser.SCXML.parse(xml)
{:ok, document} = SC.parse(xml)

# 2. Validate: Check semantics + optimize with lookup maps
{:ok, optimized_document, warnings} = SC.Validator.validate(document)
{:ok, optimized_document, warnings} = SC..validate(document)

# 3. Interpret: Run state chart with optimized lookups
{:ok, state_chart} = SC.Interpreter.initialize(optimized_document)
{:ok, state_chart} = SC.interpret(optimized_document)
```

## Performance Optimizations
Expand All @@ -362,7 +351,7 @@ The implementation includes several key optimizations for production use:

```elixir
# Automatic hierarchical entry
{:ok, state_chart} = SC.Interpreter.initialize(document)
{:ok, state_chart} = SC.interpret(document)
active_states = SC.Interpreter.active_states(state_chart)
# Returns only leaf states (compound/parallel states entered automatically)

Expand Down
Loading