Module glsl::syntax

source ·
Expand description

GLSL abstract syntax tree and grammar.

This module exports all the grammar syntax that defines GLSL. You’ll be handling ASTs representing your GLSL source.

The most external form of a GLSL parsed AST is TranslationUnit (a shader). Some part of the tree are boxed. This is due to two facts

  • Recursion is used, hence we need a way to give our types a static size.
  • Because of some very deep variants, runtime size would explode if no indirection weren’t in place.

The types are commented so feel free to inspect each of theme. As a starter, you should read the documentation of Expr, FunctionDefinition, Statement and TranslationUnit.

Structs

An identifier with an optional array specifier.
A general purpose block, containing fields and possibly a list of declared identifiers. Semantic is given with the storage qualifier.
Compound statement (with no new scope).
For init statement.
Fully specified type.
Function definition.
Function parameter declarator.
Function prototype.
Init declarator list.
Layout qualifier.
An #extension preprocessor command.
A #version preprocessor command.
Selection statement.
Single declaration.
A single declaration with implicit, already-defined type.
Struct field specifier. Used to add fields to struct specifiers.
Struct specifier. Used to create new, user-defined types.
Switch statement.
Type qualifier.
Type specifier.

Enums

Dimensionality of an arary.
All possible operators for assigning expressions.
All binary operators that exist in GLSL.
Case label statement.
Condition.
A declaration.
The most general form of an expression. As you can see if you read the variant list, in GLSL, an assignment is an expression. This is a bit silly but think of an assignment as a statement first then an expression which evaluates to what the statement “returns”.
External declaration.
For init statement.
Function identifier.
Function parameter declaration.
Initializer.
Interpolation qualifier.
Iteration statement.
Jump statement.
Layout qualifier spec.
Precision qualifier.
Some basic preprocessor commands.
An #extension behavior annotation.
An #extension name annotation.
A #version profile annotation.
Selection rest statement.
Simple statement.
Statement.
Storage qualifier.
Type qualifier spec.
Type specifier (non-array).
All unary operators that exist in GLSL.

Type Definitions

Expression statement.
A generic identifier.
A non-empty Vec. It has at least one element.
Starting rule.
Any type name.