Module wgsl_parse::syntax
source · Expand description
A syntax tree for WGSL files. The root of the tree is a TranslationUnit (file).
Follwing the spec at this date: 2024-07-31. The syntax tree closely mirrors wgsl structure while allowing language extensions.
§Spanned
The following elements are Spanned to allow easy modification of the source code: Directives, Declarations, Statements, Expressions, Struct Members, Attributes, Idents, Template Arguments, Formal Parameters. … plus all language extensions, and maybe others.
Spans, if provided, are outer spans, meaning e.g. Statements include the ; and
Struct Members include the ,, but do not include the spaces between neighbor items.
Use the convenience methods to manipulate the spans as needed (TODO).
§Strictness
This syntax tree is rather strict, meaning it cannot represent most syntaxically incorrect programs. But it is only syntactic, meaning it doesn’t perform many contextual checks: for example, certain attributes can only appear in certain places, or declarations have different constraints depending on where they appear. stricter checking is TODO and will be optional.
§Extensions
TODO, the syntax tree can be mutated to allow well-defined language extensions with feature flags (wgsl-tooling-imports, wgsl-tooling-generics, …).
§Design considerations
The parsing is not designed to be primarily efficient, but flexible and correct. It is made with the ultimate goal to implement spec-compliant language extensions.