Oak WGSL Parser
High-performance incremental WGSL parser for the oak ecosystem with flexible configuration, optimized for WebGPU graphics programming and shader development.
🎯 Overview
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.
✨ Features
- Complete WGSL Syntax: Supports all WGSL features including modern specifications
- Shader Stage Support: Handles vertex, fragment, and compute shader stages
- Full AST Generation: Generates comprehensive Abstract Syntax Trees
- Lexer Support: Built-in tokenization with proper span information
- Error Recovery: Graceful handling of syntax errors with detailed diagnostics
🚀 Quick Start
Basic example:
use ;
📋 Parsing Examples
Fragment Shader Parsing
use ;
let parser = new;
let source = new;
let result = parser.parse;
println!;
Compute Shader Parsing
use ;
let parser = new;
let source = new;
let result = parser.parse;
println!;
🔧 Advanced Features
Token-Level Parsing
use ;
let parser = new;
let source = new;
let result = parser.parse;
// Token information is available in the parse result
Error Handling
use ;
let parser = new;
let source = new;
let result = parser.parse;
if let Err = result.result
🏗️ AST Structure
The parser generates a comprehensive AST with the following main structures:
- Shader: Root container for WGSL shaders
- Function: Shader functions with attributes
- Variable: Variable declarations with bindings
- Statements: Assignment, if, loop, return statements
- Expressions: Binary, unary, function call expressions
- Types: Vector, matrix, array, and custom types
📊 Performance
- Streaming: Parse large WGSL files without loading entirely into memory
- Incremental: Re-parse only changed sections
- Memory Efficient: Smart AST node allocation
- Fast Recovery: Quick error recovery for better IDE integration
🔗 Integration
Oak-wgsl integrates seamlessly with:
- Static Analysis: Code quality and security analysis
- Shader Transpilation: Converting between shading languages
- IDE Support: Language server protocol compatibility
- Shader Validation: Checking shader correctness before compilation
- Documentation: Generating documentation from WGSL code
📚 Examples
Check out the examples directory for comprehensive examples:
- Complete WGSL shader parsing
- Vertex and fragment shader analysis
- Compute shader processing
- Integration with graphics pipelines
🤝 Contributing
Contributions are welcome!
Please feel free to submit pull requests at the project repository or open issues.