Oak Sass Parser
A high-performance Sass/SCSS parser for Rust, built with the Oak parser combinator framework. Parse stylesheets with comprehensive AST generation and error handling.
Overview
Oak Sass provides robust parsing capabilities for Sass and SCSS stylesheet files, supporting variables, mixins, functions, nesting, and all major Sass constructs. Built on the Oak parser combinator framework, it delivers excellent performance and detailed error messages.
Features
- ✅ Complete Sass 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 Sass dialects
- ✅ Well Tested: Comprehensive test suite with real-world examples
Quick Start
Parsing Examples
Basic SCSS Parsing
use ;
use SassLanguage;
Advanced Mixins and Functions
use ;
use SassLanguage;
Advanced Features
Nested Imports
Oak Sass 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:
SassFile- 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- Sass expressions and operationsAtRule- At-rules like @extend, @debug, @warn
Performance
Oak Sass 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 Sass integrates seamlessly with the Oak ecosystem:
use ;
use SassLanguage;
// 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.