Module syntax

Source
Expand description

A syntax tree for WGSL files. The root of the tree is a TranslationUnit.

Follwing the spec at this date: 2024-07-31. The syntax tree closely mirrors wgsl structure while allowing language extensions.

§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. This is why this parser doesn’t borrow strings.

Structs§

AssignmentStatement
Attribute
BinaryExpression
CompoundStatement
ConstAssert
ContinuingStatement
Declaration
DiagnosticDirective
EnableDirective
ForStatement
FormalParameter
Function
FunctionCallExpression
IfStatement
IndexingExpression
LoopStatement
NamedComponentExpression
RequiresDirective
Struct
StructMember
SwitchClause
SwitchStatement
TranslationUnit
TypeAlias
TypeExpression
UnaryExpression
WhileStatement

Enums§

AssignmentOperator
BinaryOperator
CaseSelector
DeclarationKind
DiagnosticSeverity
Expression
GlobalDeclaration
GlobalDirective
LiteralExpression
Statement
UnaryOperator

Type Aliases§

BreakIfStatement
ConstAssertStatement
DeclarationStatement
DecrementStatement
FunctionCallStatement
IdentifierExpression
IncrementStatement
ParenthesizedExpression
ReturnStatement
TemplateArg