Expand description
§wgsl-parse
A parser and syntax tree for WGSL files, written directly from the specification with lalrpop.
It supports WESL language extensions guarded by feature flags.
§WESL Features
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 |
§Parsing and Stringification
TranslationUnit
implements FromStr
.
Other syntax nodes also implement FromStr
: GlobalDirective
, GlobalDeclaration
, Statement
and Expression
.
The syntax tree elements implement Display
.
The display is always pretty-printed.
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}");
Re-exports§
pub use error::Error;
Modules§
- error
- span
- syntax
- A syntax tree for WGSL and WESL files. The root of the tree is
TranslationUnit
.
Traits§
- Decorated
- A trait implemented on all types that can be prefixed by attributes.
Functions§
- parse_
str - Parse a string into a syntax tree (
TranslationUnit
). - recognize_
str - Test whether a string represent a valid WGSL module (
TranslationUnit
).