Oak SCSS Parser
A high-performance SCSS parser for Rust, built with the Oak parser combinator framework. Parse Sassy CSS stylesheets with comprehensive AST generation and error handling.
Overview
Oak SCSS provides robust parsing capabilities for SCSS stylesheet files, supporting variables, mixins, functions, nesting, and all major SCSS constructs. Built on the Oak parser combinator framework, it delivers excellent performance and detailed error messages.
Features
- ✅ Complete SCSS Support: Parse variables, mixins, functions, nesting, and imports
- ✅ Modern Rust API: Type-safe parsing with comprehensive error handling
- ✅ High Performance: Built on the efficient Oak parser combinator framework
- ✅ Rich AST: Detailed Abstract Syntax Tree with source location tracking
- ✅ Extensible: Easy to extend for custom SCSS dialects
- ✅ Well Tested: Comprehensive test suite with real-world examples
Quick Start
Parsing Examples
Basic SCSS Parsing
use ;
use SCSSLanguage;
Advanced Mixins and Functions
use ;
use SCSSLanguage;
Advanced Features
Nested Imports
Oak SCSS supports parsing nested imports:
let source = r#"
@import 'variables';
@import 'mixins';
@import url('https://fonts.googleapis.com/css?family=Roboto');
"#;
Control Directives
Parse control directives like @if, @for, @each, and @while:
let source = r#"
@for $i from 1 through 12 {
.col-#{$i} {
width: percentage($i / 12);
}
}
@each $color in red, green, blue {
.bg-#{$color} {
background-color: $color;
}
}
"#;
AST Structure
The parser generates a rich AST with the following main node types:
SCSSFile- Root node containing the entire fileVariable- Variable declarations and referencesRule- CSS rules with selectors and declarationsMixin- Mixin definitions and includesFunction- Function definitions and callsImport- Import statementsMedia- Media queries and blocksExpression- SCSS expressions and operationsAtRule- At-rules like @extend, @debug, @warn
Performance
Oak SCSS is designed for high performance:
- Zero-copy parsing where possible
- Streaming support for large stylesheet files
- Efficient memory usage with minimal allocations
- Fast error recovery for better developer experience
Integration
Oak SCSS integrates seamlessly with the Oak ecosystem:
use ;
use SCSSLanguage;
// Use with other Oak parsers
let mut parser = new;
let result = parser.parse;
Examples
More examples can be found in the examples directory:
Contributing
We welcome contributions! Please see our Contributing Guide for details.