Backlog/lib/sdl3/parser/docs
Peterino2 9f4c2b6914 Add comprehensive documentation and reorganize project structure
Created human-readable documentation under docs/ directory:
- docs/README.md: Project overview, quick start, features, and status
- docs/architecture.md: Pipeline design, components, and implementation details
- docs/usage.md: Usage guide, integration examples, and troubleshooting
- docs/naming.md: Detailed explanation of C-to-Zig naming conventions

Removed obsolete documentation files:
- PARSER_FIX_PLAN.md: Content moved to architecture.md
- IMPLEMENTATION_COMPLETE.md: Content moved to README.md

The documentation provides:
- Complete architecture overview of the 4-stage pipeline
- Detailed explanation of the "first underscore" naming rule
- Integration examples and common usage patterns
- Troubleshooting guide and FAQ
- Extension points for adding new C patterns

Kept TEST_HARNESS_PLAN.md and TEST_HARNESS_PLAN_V2.md as they document
future implementation plans for testing infrastructure.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-21 20:20:07 -08:00
..
README.md Add comprehensive documentation and reorganize project structure 2026-01-21 20:20:07 -08:00
architecture.md Add comprehensive documentation and reorganize project structure 2026-01-21 20:20:07 -08:00
naming.md Add comprehensive documentation and reorganize project structure 2026-01-21 20:20:07 -08:00
usage.md Add comprehensive documentation and reorganize project structure 2026-01-21 20:20:07 -08:00

README.md

SDL3 Parser - C to Zig Binding Generator

A robust parser that automatically generates idiomatic Zig bindings from SDL3 C header files.

Overview

The SDL3 Parser analyzes C header files and generates type-safe Zig code with proper naming conventions, memory safety, and zero-cost abstractions. It handles opaque types, enums, structs, flags, and function declarations.

Features

  • Automatic binding generation - Parse C headers and output Zig code
  • Idiomatic naming - Converts C naming to Zig conventions
  • Type safety - Generates packed structs for flags, enums with backing types
  • Zero overhead - Inline function wrappers with proper casts
  • Memory safe - No memory leaks, validated with GPA
  • Well tested - 18+ unit tests, integration tested with SDL_gpu.h

Quick Start

Build

cd lib/sdl3/parser
zig build

Parse a Header

# Generate Zig bindings
zig build run -- ../SDL/include/SDL3/SDL_gpu.h > output/gpu.zig

# With C mocks (planned feature)
zig build run -- ../SDL/include/SDL3/SDL_gpu.h --mocks

Run Tests

# Unit tests
zig build test

# Test harness (planned)
cd test_project
zig build test

Output Example

Input (C):

typedef struct SDL_GPUDevice SDL_GPUDevice;

typedef enum SDL_GPUPrimitiveType {
    SDL_GPU_PRIMITIVETYPE_TRIANGLELIST,
    SDL_GPU_PRIMITIVETYPE_TRIANGLESTRIP,
} SDL_GPUPrimitiveType;

typedef Uint32 SDL_GPUTextureUsageFlags;
#define SDL_GPU_TEXTUREUSAGE_SAMPLER (1u << 0)
#define SDL_GPU_TEXTUREUSAGE_COLOR_TARGET (1u << 1)

extern SDL_DECLSPEC SDL_GPUDevice* SDLCALL SDL_CreateGPUDevice(bool debug_mode);

Output (Zig):

pub const GPUDevice = opaque {};

pub const GPUPrimitiveType = enum(c_int) {
    primitivetypeTrianglelist,
    primitivetypeTrianglestrip,
};

pub const GPUTextureUsageFlags = packed struct(u32) {
    textureusageSampler: bool = false,
    textureusageColorTarget: bool = false,
    pad0: u29 = 0,
    rsvd: bool = false,
};

pub inline fn createGPUDevice(debug_mode: bool) ?*GPUDevice {
    return @ptrCast(c.SDL_CreateGPUDevice(debug_mode));
}

Architecture

The parser consists of four main components:

  1. Scanner (patterns.zig) - Lexical analysis and pattern matching
  2. Naming (naming.zig) - C to Zig name conversion
  3. Types (types.zig) - C to Zig type mapping
  4. CodeGen (codegen.zig) - Zig code generation

See Architecture for details.

Documentation

Project Status

Completed

  • Core parser functionality
  • All C declaration types supported
  • Proper naming conventions
  • Memory leak free
  • Comprehensive unit tests
  • Integration tested with SDL_gpu.h

Planned 🚧

  • C mock generation (--mocks flag)
  • Complete test harness with linkage testing
  • Golden file regression testing
  • Multiple header support
  • Performance benchmarking

Requirements

  • Zig 0.14+ (tested with 0.15.2)
  • SDL3 headers (for input)
  • No runtime dependencies

Contributing

The parser is currently under active development. See the Test Harness Plan for upcoming features.

Recent Changes

Version 2024-01 (Current)

  • Fixed critical flag parsing bug (empty structs)
  • Fixed invalid identifier generation (numeric prefixes)
  • Implemented "first underscore" naming rule
  • Added 13 new unit tests
  • Memory leak fixes
  • Comprehensive documentation

See IMPLEMENTATION_COMPLETE.md for detailed changes.

License

Part of the Backlog game engine project.