Design Principles
This chapter explains the core design principles behind Sipha.
Incremental-First Design
Sipha is designed from the ground up for incremental parsing:
- Node reuse: Unchanged subtrees are automatically reused
- Cache management: Parse results are cached for future reuse
- Affected regions: Only affected regions are re-parsed
- Performance: Optimized for interactive editing scenarios
Immutability
Sipha uses immutable data structures:
- Green trees: Immutable, shareable representation
- Safe sharing: Immutability enables safe sharing across threads
- Functional style: Operations create new trees rather than modifying existing ones
Modularity
Sipha is modular and extensible:
- Backend system: Multiple parsing backends via trait
- Feature flags: Optional features via feature flags
- Pluggable components: Lexers, parsers, and trees are pluggable
Performance
Performance is a key consideration:
- Efficient algorithms: Use efficient parsing algorithms
- Memory efficiency: Shared trees reduce memory usage
- Fast operations: Optimized for common operations
- Incremental updates: Fast updates for interactive applications
Type Safety
Sipha leverages Rust’s type system:
- Generic types: Generic over token and non-terminal types
- Trait bounds: Clear trait bounds for extensibility
- Type safety: Compile-time guarantees for correctness
Error Handling
Sipha provides comprehensive error handling:
- Result types: Use
Resultfor fallible operations - Error recovery: Configurable error recovery strategies
- Rich diagnostics: Detailed error messages with context
API Design
Sipha’s API is designed for:
- Ease of use: Simple, intuitive API
- Flexibility: Support for various use cases
- Extensibility: Easy to extend and customize
- Documentation: Well-documented with examples
Next Steps
- See Module Structure for codebase organization
- Check Data Structures for key types