Crate wgsl_parse

Source
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

namedescriptionWESL Specification
weslenable all WESL extensions below
importsimport statements and inline qualified pathscomplete
attributesextra attributes locations on statementscomplete
condcomp@if attributescomplete
generics@type attributesexperimental

§Other Features

namedescription
naga_extenable all Naga/WGPU extensions (experimental)
serdederive Serialize and Deserialize for syntax tree nodes
tokreprderive TokRepr for syntax tree nodes

§Parsing and Stringification

TranslationUnit implements FromStr. Other syntax nodes also implement FromStr: GlobalDirective, GlobalDeclaration, Statement, Expression and ImportStatement.

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;
pub use parser::parse_str;
pub use parser::recognize_str;

Modules§

error
lexer
Prefer using crate::parse_str. You shouldn’t need to manipulate the lexer.
parser
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.