4 releases

new 0.1.1 Feb 26, 2025
0.1.0 Feb 19, 2025
0.0.2 Aug 29, 2024
0.0.1 Aug 20, 2024

#139 in Template engine

39 downloads per month
Used in 2 crates

MIT/Apache

180KB
4.5K SLoC

Rust 3K SLoC // 0.0% comments LALRPOP 1.5K SLoC // 0.1% comments

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.

# use crate::syntax::TranslationUnit;
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}");

Dependencies

~6–8.5MB
~110K SLoC