| Crates.io | oak-wgsl |
| lib.rs | oak-wgsl |
| version | 0.0.1 |
| created_at | 2025-10-21 19:32:29.77415+00 |
| updated_at | 2026-01-23 05:22:35.577541+00 |
| description | WGSL language parser with support for modern shader programming and WebGPU features. |
| homepage | https://github.com/ygg-lang/oaks |
| repository | https://github.com/ygg-lang/oaks |
| max_upload_size | |
| id | 1894328 |
| size | 63,113 |
High-performance incremental WGSL parser for the oak ecosystem with flexible configuration, optimized for WebGPU graphics programming and shader development.
Oak WGSL is a robust parser for WebGPU Shading Language (WGSL), designed to handle complete WGSL syntax including modern shader features and compute capabilities. Built on the solid foundation of oak-core, it provides both high-level convenience and detailed AST generation for WGSL analysis and tooling.
Basic example:
use oak_wgsl::{Parser, WgslLanguage, SourceText};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let parser = Parser::new();
let source = SourceText::new(r#"
@vertex
fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> @builtin(position) vec4<f32> {
let x = f32(i32(in_vertex_index) - 1);
let y = f32(i32(in_vertex_index & 1u) * 2 - 1);
return vec4<f32>(x, y, 0.0, 1.0);
}
"#);
let result = parser.parse(&source);
println!("Parsed WGSL shader successfully.");
Ok(())
}
use oak_wgsl::{Parser, WgslLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
@fragment
fn fs_main(@location(0) frag_color: vec4<f32>) -> @location(0) vec4<f32> {
return frag_color;
}
"#);
let result = parser.parse(&source);
println!("Parsed WGSL fragment shader successfully.");
use oak_wgsl::{Parser, WgslLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
@group(0) @binding(0)
var<storage, read_write> data: array<f32>;
@compute @workgroup_size(64)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
let index = global_id.x;
if (index >= arrayLength(&data)) {
return;
}
data[index] = data[index] * 2.0;
}
"#);
let result = parser.parse(&source);
println!("Parsed WGSL compute shader successfully.");
use oak_wgsl::{Parser, WgslLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new("@vertex fn main() -> @builtin(position) vec4<f32> { return vec4<f32>(0.0); }");
let result = parser.parse(&source);
// Token information is available in the parse result
use oak_wgsl::{Parser, WgslLanguage, SourceText};
let parser = Parser::new();
let source = SourceText::new(r#"
@vertex
fn broken_shader() -> vec4<f32> {
let x: f32 = "not a number"; // Type mismatch
return x; // Missing vector construction
}
"#);
let result = parser.parse(&source);
if let Err(e) = result.result {
println!("Parse error: {:?}", e);
}
The parser generates a comprehensive AST with the following main structures:
Oak-wgsl 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.