2.1 KiB
2.1 KiB
SDL3 Header Parser - Agent Documentation
Project Overview
This is an SDL3 header parser that converts C header files into Zig interfaces, JSON objects, and C mocks. Built specifically for SDL3 headers (developed against SDL 3.2.10), it focuses on generating Zig APIs.
Key Points:
- Not a real C parser - best-effort text transformation specifically for SDL3 headers
- Does not do proper AST elaboration or tokenization
- Simple to modify but brittle
- Requires Zig 0.15.2 and git
Architecture
The codebase consists of several modules:
parser.zig- Main entry point and orchestrationpatterns.zig- SDL3 pattern matching and declaration scanningcodegen.zig- Zig code generationmock_codegen.zig- C mock generationjson_serializer.zig- JSON output generationdependency_resolver.zig- Type dependency resolutionheader_cache.zig- Header caching for cross-file type resolutionio.zig- Error handling utilitiestypes.zig- Type mapping and conversionsnaming.zig- Naming conventions
Developing
Error Handling
CRITICAL: Whenever actual errors are encountered (parsing failures, invalid declarations, missing types, etc.), you MUST call io.emitError to report them properly. Do NOT use std.debug.print for actual errors.
// Good - proper error reporting
try io.emitError(allocator, "Failed to parse struct field: {s}", .{field_name});
// Bad - don't use for errors
std.debug.print("Error: Failed to parse...\n", .{});
Validation Process
After generating Zig code:
- Output written to
tmp/directory zig ast-checkruns on the temporary file- If passes:
zig fmtruns, then copied to final destination - If fails: debug output written to
debug/with_fmterror.zigsuffix
Memory Management
- Two cleanup functions exist with identical logic:
freeDecls()- frees a slice of declarationsfreeDeclDeep()- frees a single declaration
- Both free all nested allocations (names, types, doc comments, params/fields/values/flags)
Main APIs (Priority)
Focus areas: gpu, video, gamepad, joystick, input, event
Anything beyond these is not actively maintained.