| Crates.io | oak-css |
| lib.rs | oak-css |
| version | 0.0.1 |
| created_at | 2025-10-20 12:22:09.070732+00 |
| updated_at | 2026-01-23 04:18:57.3361+00 |
| description | CSS stylesheet language parser with support for web styling and layout processing. |
| homepage | https://github.com/ygg-lang/oaks |
| repository | https://github.com/ygg-lang/oaks |
| max_upload_size | |
| id | 1891846 |
| size | 49,058 |
High-performance incremental CSS parser for the oak ecosystem with flexible configuration, optimized for web development and styling analysis.
Oak-css is a robust parser for CSS, designed to handle complete CSS syntax including modern features. Built on the solid foundation of oak-core, it provides both high-level convenience and detailed AST generation for web development and styling analysis.
Basic example:
use oak_css::CssParser;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let parser = CssParser::new();
let css_content = r#"
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
"#;
let stylesheet = parser.parse_stylesheet(css_content)?;
println!("Parsed CSS stylesheet successfully.");
Ok(())
}
use oak_css::{CssParser, ast::Rule};
let parser = CssParser::new();
let css_content = "h1 { color: red; font-size: 2em; font-weight: bold; }";
let rule = parser.parse_rule(css_content)?;
println!("Selector: {}", rule.selector);
println!("Declarations: {}", rule.declarations.len());
use oak_css::{CssParser, ast::Selector};
let parser = CssParser::new();
let selector = parser.parse_selector(".container .item:hover > .child")?;
println!("Selector complexity: {}", selector.complexity());
println!("Specificity: {:?}", selector.specificity());
use oak_css::{CssParser, ast::Declaration};
let parser = CssParser::new();
let declaration = parser.parse_declaration("margin: 10px 5px 20px 15px")?;
println!("Property: {}", declaration.property);
println!("Value tokens: {}", declaration.value.len());
use oak_css::{CssParser, lexer::Token};
let parser = CssParser::new();
let tokens = parser.tokenize(".class { color: #ff0000; }")?;
for token in tokens {
println!("{:?}", token.kind);
}
use oak_css::CssParser;
let parser = CssParser::new();
let invalid_css = r#"
body {
color: red
font-size: 16px; // Missing semicolon
margin: 10px
}
"#;
match parser.parse_stylesheet(invalid_css) {
Ok(stylesheet) => println!("Parsed CSS stylesheet successfully."),
Err(e) => {
println!("Parse error at line {} column {}: {}",
e.line(), e.column(), e.message());
if let Some(context) = e.context() {
println!("Error context: {}", context);
}
}
}
The parser generates a comprehensive AST with the following main structures:
rgb(), calc(), etc.@media, @import, etc.Oak-css integrates seamlessly with:
Check out the examples directory for comprehensive examples:
Contributions are welcome!
Please feel free to submit pull requests at the project repository or open issues.