| Crates.io | oak-sass |
| lib.rs | oak-sass |
| version | 0.0.1 |
| created_at | 2025-10-22 04:56:54.461668+00 |
| updated_at | 2026-01-23 05:18:25.03685+00 |
| description | High-performance incremental Sass parser for the oak ecosystem with flexible configuration, supporting CSS preprocessing and styling. |
| homepage | https://github.com/ygg-lang/oaks |
| repository | https://github.com/ygg-lang/oaks |
| max_upload_size | |
| id | 1894985 |
| size | 85,200 |
A high-performance Sass/SCSS parser for Rust, built with the Oak parser combinator framework. Parse stylesheets with comprehensive AST generation and error handling.
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.
use oak::{Parser, Language};
use oak_sass::SassLanguage;
fn main() {
let source = r#"
$primary-color: #3498db;
$secondary-color: #2ecc71;
$font-size: 16px;
.button {
background-color: $primary-color;
color: white;
padding: 10px 20px;
border-radius: 5px;
&:hover {
background-color: darken($primary-color, 10%);
}
&.large {
font-size: $font-size * 1.2;
padding: 15px 30px;
}
}
"#;
let mut parser = Parser::<SassLanguage>::new();
match parser.parse(&source) {
Ok(ast) => {
println!("Parsed AST: {:#?}", ast);
}
Err(error) => {
eprintln!("Parse error: {}", error);
}
}
}
use oak::{Parser, Language};
use oak_sass::SassLanguage;
fn main() {
let source = r#"
@mixin flex-center {
display: flex;
justify-content: center;
align-items: center;
}
@function rem($pixels, $base: 16px) {
@return $pixels / $base * 1rem;
}
@mixin responsive-font($min-size, $max-size, $min-width: 320px, $max-width: 1200px) {
font-size: $min-size;
@media screen and (min-width: $min-width) {
font-size: calc(#{$min-size} + #{strip-unit($max-size - $min-size)} *
((100vw - #{$min-width}) / #{strip-unit($max-width - $min-width)}));
}
@media screen and (min-width: $max-width) {
font-size: $max-size;
}
}
.container {
@include flex-center;
min-height: 100vh;
.content {
@include responsive-font(14px, 24px);
padding: rem(20px);
max-width: rem(800px);
}
}
"#;
let mut parser = Parser::<SassLanguage>::new();
match parser.parse(&source) {
Ok(ast) => {
println!("Advanced Sass parsed successfully!");
}
Err(error) => {
eprintln!("Parse error: {}", error);
}
}
}
Oak Sass supports parsing nested imports:
let source = r#"
@import 'variables';
@import 'mixins';
@import url('https://fonts.googleapis.com/css?family=Roboto');
"#;
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;
}
}
"#;
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, @warnOak Sass is designed for high performance:
Oak Sass integrates seamlessly with the Oak ecosystem:
use oak::{Parser, Language};
use oak_sass::SassLanguage;
// Use with other Oak parsers
let mut parser = Parser::<SassLanguage>::new();
let result = parser.parse(sass_source);
More examples can be found in the examples directory:
We welcome contributions! Please see our Contributing Guide for details.