Module parse

Module parse 

Source
Expand description

HLSL recursive-descent parser.

Consumes the Token stream from crate::lex::tokenize and produces a TranslationUnit AST. Pratt-style operator precedence for expressions, straightforward recursive descent for statements and top-level items.

The parser is pragmatic, not exhaustive: it handles the HLSL subset that MilkDrop 2 user comp shaders actually use. Constructs outside that subset (templates, attributes, geometry-shader semantics, etc.) produce a ParseError — the caller falls back to the existing regex pipeline.

This parser is not yet wired into crate::translate_shader. The AST sits available for a future WGSL emitter, while the existing regex passes continue to drive the current comp-shader pass-rate on test-presets-200/.

Structs§

ParseError
Parse error: human-readable message plus the offending source span.
Parser 🔒
Hand-written recursive-descent parser. Holds a borrow on the token slice and source string; produces AST nodes that own their data (so the parser’s lifetime doesn’t leak into downstream consumers).

Functions§

is_swizzle 🔒
A .<chars> member access is a swizzle iff every char is one of the component letters (xyzw / rgba), with length 1–4. HLSL doesn’t allow mixed xyzw+rgba in one swizzle, but we accept it here — the emitter is stricter than the parser.
parse_hlsl
Top-level entry point: lex then parse a full HLSL source string.
stmt_span 🔒