| Crates.io | oak-scss |
| lib.rs | oak-scss |
| version | 0.0.1 |
| created_at | 2025-10-22 04:57:16.214052+00 |
| updated_at | 2026-01-23 05:18:51.51654+00 |
| description | SCSS CSS preprocessor language parser with support for modern CSS features and dynamic styling. |
| homepage | https://github.com/ygg-lang/oaks |
| repository | https://github.com/ygg-lang/oaks |
| max_upload_size | |
| id | 1894986 |
| size | 87,912 |
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.
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.
use oak::{Parser, Language};
use oak_scss::SCSSLanguage;
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::<SCSSLanguage>::new();
match parser.parse(&source) {
Ok(ast) => {
println!("Parsed AST: {:#?}", ast);
}
Err(error) => {
eprintln!("Parse error: {}", error);
}
}
}
use oak::{Parser, Language};
use oak_scss::SCSSLanguage;
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::<SCSSLanguage>::new();
match parser.parse(&source) {
Ok(ast) => {
println!("Advanced SCSS parsed successfully!");
}
Err(error) => {
eprintln!("Parse error: {}", error);
}
}
}
Oak SCSS 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:
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, @warnOak SCSS is designed for high performance:
Oak SCSS integrates seamlessly with the Oak ecosystem:
use oak::{Parser, Language};
use oak_scss::SCSSLanguage;
// Use with other Oak parsers
let mut parser = Parser::<SCSSLanguage>::new();
let result = parser.parse(scss_source);
More examples can be found in the examples directory:
We welcome contributions! Please see our Contributing Guide for details.