Crates.io | wgsl-parse |
lib.rs | wgsl-parse |
version | 0.2.0 |
created_at | 2024-08-20 22:53:58.866081+00 |
updated_at | 2025-07-28 09:27:47.668033+00 |
description | Parse a wgsl source file to a syntax tree |
homepage | |
repository | https://github.com/wgsl-tooling-wg/wesl-rs |
max_upload_size | |
id | 1345850 |
size | 230,487 |
A parser and syntax tree for WGSL files, written directly from the specification with lalrpop.
It supports WESL language extensions guarded by feature flags.
name | description | WESL Specification |
---|---|---|
wesl |
enable all WESL extensions below | |
imports |
import statements and inline qualified paths |
complete |
attributes |
extra attributes locations on statements | complete |
condcomp |
@if attributes |
complete |
generics |
@type attributes |
experimental |
name | description |
---|---|
naga_ext |
enable all Naga/WGPU extensions (experimental) |
serde |
derive Serialize and Deserialize for syntax tree nodes |
tokrepr |
derive TokRepr for syntax tree nodes |
[TranslationUnit
][syntax::TranslationUnit] implements [FromStr
][std::str::FromStr].
Other syntax nodes also implement FromStr
: GlobalDirective
, GlobalDeclaration
, Statement
, Expression
and ImportStatement
.
The syntax tree elements implement [Display
][std::fmt::Display].
The display is always pretty-printed.
# use wgsl_parse::syntax::TranslationUnit;
# use std::str::FromStr;
let source = "@fragment fn frag_main() -> @location(0) vec4f { return vec4(1); }";
let mut module = TranslationUnit::from_str(source).unwrap();
// modify the module as needed...
println!("{module}");