Donner SVG 0.8.0
0.8.0 ยท ebf353960.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
Parser.h File Reference

C++20 constexpr parser and validator for Donner's bounded WGSL frontend profile. More...

#include <bit>
#include <cstdint>
#include <limits>
#include <optional>
#include <string_view>
#include "donner/gpu/GpuLimits.h"
#include "donner/gpu/shader/wgsl/Module.h"
#include "donner/gpu/shader/wgsl/Number.h"
#include "donner/gpu/shader/wgsl/Uniformity.h"
Include dependency graph for Parser.h:

Classes

struct  donner::gpu::shader::wgsl::Diagnostic
 A fail-closed parser diagnostic. More...
struct  donner::gpu::shader::wgsl::ParseResult
 Result of parsing a bounded WGSL source string. More...
struct  donner::gpu::shader::wgsl::detail::Token
 Lexical token retaining its source spelling and location. More...
struct  donner::gpu::shader::wgsl::detail::PunctuationEntry
 Mapping from one punctuation character to its token category. More...
class  donner::gpu::shader::wgsl::detail::Parser
 Private parser state. All storage is fixed-size and constexpr-compatible. More...

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.

Enumerations

enum class  donner::gpu::shader::wgsl::ErrorCode : uint8_t {
  None ,
  SourceTooLarge ,
  NonAsciiSource ,
  TokenLimit ,
  IdentifierLimit ,
  StructLimit ,
  StructMemberLimit ,
  BindingLimit ,
  SymbolLimit ,
  ExpressionLimit ,
  StatementLimit ,
  FunctionLimit ,
  NestingLimit ,
  UnexpectedToken ,
  UnsupportedConstruct ,
  InvalidLiteral ,
  InvalidIdentifier ,
  InvalidConstantExpression ,
  DuplicateName ,
  DuplicateBinding ,
  UnknownName ,
  UnknownType ,
  TypeMismatch ,
  InvalidAttribute ,
  InvalidBinding ,
  InvalidLayout ,
  ImmutableAssignment ,
  InvalidCall ,
  InvalidReturn ,
  InvalidCondition ,
  InvalidLoop ,
  MissingReturn ,
  UnreachableStatement ,
  InvalidSwitch ,
  NonUniformControl ,
  UniformityLimit ,
  InvalidStage ,
  InvalidPointer
}
 Reason parsing or validation rejected a WGSL module.
enum class  donner::gpu::shader::wgsl::detail::TokenKind : uint8_t {
  BitAnd ,
  End ,
  Identifier ,
  Number ,
  At ,
  LeftParen ,
  RightParen ,
  LeftBrace ,
  RightBrace ,
  LeftBracket ,
  RightBracket ,
  LeftAngle ,
  RightAngle ,
  Comma ,
  Colon ,
  Semicolon ,
  Dot ,
  Plus ,
  Minus ,
  Star ,
  Slash ,
  Percent ,
  Assign ,
  Equal ,
  NotEqual ,
  Less ,
  LessEqual ,
  Greater ,
  GreaterEqual ,
  Not ,
  And ,
  Or ,
  Arrow ,
  PlusAssign ,
  MinusAssign ,
  ShiftLeft ,
  ShiftRight ,
  ShiftLeftAssign ,
  ShiftRightAssign
}
 Lexical token categories recognized by the WGSL parser.

Functions

constexpr ParseResult donner::gpu::shader::wgsl::Parse (std::string_view source)
 Parses and validates WGSL in the supported frontend profile.

Variables

constexpr PunctuationEntry donner::gpu::shader::wgsl::detail::kSingleCharacterPunctuation []
 Single-character punctuation spellings and their token kinds.
constexpr std::string_view donner::gpu::shader::wgsl::detail::kReservedDeclarationNames []
 Names disallowed for declarations by the supported WGSL grammar.

Detailed Description

C++20 constexpr parser and validator for Donner's bounded WGSL frontend profile.

Function Documentation

◆ Parse()

ParseResult donner::gpu::shader::wgsl::Parse ( std::string_view source)
constexpr

Parses and validates WGSL in the supported frontend profile.

The profile accepts flat numeric buffer structures, group-zero resources, helper functions before their callers, compute/vertex/fragment entries, scalar/vector/matrix expressions, structured conditionals and positive-increment for loops, and the builtins represented by Builtin. Break/continue require a loop; discard and derivatives require a fragment entry. Derivatives are restricted to straight-line entry code before any conditional/loop and outside short-circuit RHS. Helpers are pure numeric functions over read-only globals and by-value parameters. Numeric literals include bounded decimal/hexadecimal forms, abstract scalars and scalar module constants. Abstract scalar arithmetic and constant f32 scalar/vector +, -, * and / over literals, their negations and vector constructions of them are evaluated at shader creation, and a result that is not finite fails. Constant f32 arithmetic over other operands, constant matrix arithmetic, constant builtin calls and cross-scalar constant conversions remain unsupported. Static f32 clamp bounds support literals, unary negation and vector construction, with low <= high required in every lane. Floor and sign accept runtime f32 scalars/vectors in this profile. Other unsupported constructs fail explicitly.

Parameters
sourceASCII WGSL bytes to parse.
Returns
A fully validated fixed-arena module or a diagnostic with its offending byte range.

Variable Documentation

◆ kSingleCharacterPunctuation

PunctuationEntry donner::gpu::shader::wgsl::detail::kSingleCharacterPunctuation[]
inlineconstexpr
Initial value:
= {
{'@', TokenKind::At}, {'(', TokenKind::LeftParen}, {')', TokenKind::RightParen},
{'{', TokenKind::LeftBrace}, {'}', TokenKind::RightBrace}, {'[', TokenKind::LeftBracket},
{']', TokenKind::RightBracket}, {',', TokenKind::Comma}, {':', TokenKind::Colon},
{';', TokenKind::Semicolon}, {'.', TokenKind::Dot}, {'*', TokenKind::Star},
{'/', TokenKind::Slash}, {'%', TokenKind::Percent},
}

Single-character punctuation spellings and their token kinds.