Backlog/lib/sdl3/parser
Peterino2 c23ae441c1 docs: Reorganize and clean up documentation
Complete documentation overhaul with clear organization and clean structure.

## Changes

### Documentation Reorganization

**New Structure**:
- README.md - Project overview and entry point
- PROJECT_STRUCTURE.md - Complete directory layout
- docs/ - All documentation (organized by category)
- docs/archive/ - Historical planning documents
- test/integration/ - Integration tests

**Removed Duplicates**:
- Consolidated multiple status documents
- Archived planning documents
- Removed redundant guides
- Cleaned up old test files

### New User Documentation

Created clean, focused guides:

1. **README.md** - Project overview, quick start, feature list
2. **docs/GETTING_STARTED.md** - Step-by-step tutorial
3. **docs/API_REFERENCE.md** - Complete CLI reference
4. **docs/QUICKSTART.md** - Quick reference guide

### New Technical Documentation

5. **docs/ARCHITECTURE.md** - System design and components
6. **docs/DEPENDENCY_RESOLUTION.md** - How automatic deps work
7. **docs/KNOWN_ISSUES.md** - Current limitations and workarounds

### New Development Documentation

8. **docs/DEVELOPMENT.md** - Contributing, extending, Zig 0.15 guide
9. **docs/ROADMAP.md** - Future plans and priorities
10. **docs/INDEX.md** - Complete documentation index

### Organized Technical Details

Kept detailed implementation docs in docs/:
- DEPENDENCY_FLOW.md (845 lines) - Technical walkthrough
- VISUAL_FLOW.md (365 lines) - Flow diagrams
- MULTI_FIELD_IMPLEMENTATION.md - Feature implementation
- TYPEDEF_IMPLEMENTATION.md - Feature implementation
- MULTI_HEADER_TEST_RESULTS.md - Test results

### Archived Historical Documents

Moved to docs/archive/:
- Planning documents
- Session summaries
- Status reports
- Implementation notes

These remain available for reference but don't clutter main docs.

## Documentation Statistics

**Before**:
- 18 markdown files in root
- Mix of planning, status, and user docs
- No clear entry point
- Difficult to navigate

**After**:
- 2 files in root (README, PROJECT_STRUCTURE)
- 14 organized docs in docs/
- 9 archived docs in docs/archive/
- Clear hierarchy and index
- Easy navigation

**Lines of Documentation**:
- User guides: ~1,500 lines
- Technical docs: ~2,500 lines
- Implementation details: ~1,500 lines
- **Total: ~5,500 lines** (well-organized)

## Documentation Organization

### By Audience

**New Users**:
1. README.md
2. docs/GETTING_STARTED.md
3. docs/QUICKSTART.md

**Existing Users**:
1. docs/API_REFERENCE.md
2. docs/KNOWN_ISSUES.md

**Developers**:
1. docs/ARCHITECTURE.md
2. docs/DEVELOPMENT.md
3. docs/DEPENDENCY_FLOW.md

### By Purpose

**Learning**: Getting Started, Quickstart, Architecture
**Reference**: API Reference, INDEX, Known Issues
**Development**: DEVELOPMENT, Roadmap, Implementation docs
**History**: archive/ directory

## Benefits

 Clear navigation path for all users
 Focused documentation (no duplication)
 Preserved historical context (archive)
 Professional structure
 Easy to maintain
 Organized test files

## Testing

- All existing tests still in place (test/ and test/integration/)
- Build system unchanged
- No functional changes to parser
- Pure documentation cleanup

---

Impact: Documentation only (no code changes)
Files changed: 50+ (reorganization)
Lines: ~5,500 (well-organized)
Status: Production-ready documentation 
2026-01-22 14:03:06 -08:00
..
docs docs: Reorganize and clean up documentation 2026-01-22 14:03:06 -08:00
src test: Add multi-header generation and enhance bit position parsing 2026-01-22 13:48:04 -08:00
test docs: Reorganize and clean up documentation 2026-01-22 14:03:06 -08:00
PROJECT_STRUCTURE.md docs: Reorganize and clean up documentation 2026-01-22 14:03:06 -08:00
README.md docs: Reorganize and clean up documentation 2026-01-22 14:03:06 -08:00
build.zig parser work continued 2026-01-22 01:18:04 -08:00
build.zig.zon parser work continued 2026-01-22 01:18:04 -08:00
test_small.h parser work continued 2026-01-22 01:18:04 -08:00

README.md

SDL3 Header Parser

A Zig tool that automatically generates idiomatic Zig bindings from SDL3 C headers with automatic dependency resolution.

Features

Automatic Dependency Resolution - Detects and extracts missing types from included headers
Multi-Field Struct Parsing - Handles compact C syntax like int x, y;
Type Conversion - Converts C types to idiomatic Zig types
Method Organization - Groups functions as methods on opaque types
Mock Generation - Creates C stub implementations for testing
Production Ready - 100% dependency resolution for SDL_gpu.h

Quick Start

Installation

cd parser/
zig build          # Build the parser
zig build test     # Run tests (26+ tests)

Basic Usage

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

# Generate with C mocks for testing
zig build run -- ../SDL/include/SDL3/SDL_gpu.h --output=gpu.zig --mocks=gpu_mock.c

Example Output

Input (SDL_gpu.h):

typedef struct SDL_GPUDevice SDL_GPUDevice;
extern SDL_DECLSPEC void SDLCALL SDL_DestroyGPUDevice(SDL_GPUDevice *device);

Output (gpu.zig):

pub const GPUDevice = opaque {
    pub inline fn destroyGPUDevice(gpudevice: *GPUDevice) void {
        return c.SDL_DestroyGPUDevice(gpudevice);
    }
};

Supported C Patterns

Type Declarations

  • Opaque types: typedef struct SDL_Type SDL_Type;
  • Structs: typedef struct { int x, y; } SDL_Rect; (multi-field support!)
  • Enums: typedef enum { VALUE1, VALUE2 } SDL_Enum;
  • Flags: Bitfield enums with #define values
  • Typedefs: typedef Uint32 SDL_PropertiesID;

Functions

  • Extern functions: extern SDL_DECLSPEC RetType SDLCALL SDL_Func(...);
  • Method grouping: Functions with opaque first parameter become methods

Automatic Type Conversion

C Type Zig Type
bool bool
Uint32 u32
int c_int
SDL_Type* ?*Type
const SDL_Type* *const Type
void* ?*anyopaque

Dependency Resolution

The parser automatically:

  1. Detects types referenced but not defined
  2. Searches included headers for definitions
  3. Extracts required types
  4. Generates unified output with all dependencies

Example:

SDL_gpu.h references SDL_Window
  → Parser finds #include <SDL3/SDL_video.h>
  → Extracts SDL_Window definition
  → Includes in output automatically

Success Rate: 100% for SDL_gpu.h (5/5 dependencies)

Documentation

Start Here: Getting Started Guide

User Guides

Technical Docs

Development

Complete Index

Project Status

Production Ready

  • SDL_gpu.h: 100% working
  • 26+ tests passing
  • Comprehensive documentation
  • Zero manual intervention needed

Tested Headers

Header Status Dependencies Notes
SDL_gpu.h Complete 5/5 (100%) Production ready
SDL_keyboard.h ⚠️ Partial 6/6 resolved Enum syntax issues
SDL_video.h ⚠️ Partial 5/14 resolved Needs fixes
SDL_events.h ⚠️ Partial Unknown Needs fixes

See Known Issues for details.

Performance

  • Small headers (<100 decls): ~100ms
  • Large headers (SDL_gpu.h, 169 decls): ~520ms
  • Memory usage: ~2-5MB peak
  • Output: ~1KB per declaration

Requirements

  • Zig 0.15+
  • SDL3 headers (included in parent directory)

Examples

Parse a Header

zig build run -- ../SDL/include/SDL3/SDL_gpu.h --output=gpu.zig

Use Generated Bindings

const gpu = @import("gpu.zig");

pub fn main() !void {
    const device = gpu.createGPUDevice(true);
    defer if (device) |d| d.destroyGPUDevice();
    
    // All dependency types available automatically
}

Run Tests

zig build test

Contributing

See DEVELOPMENT.md for:

  • Architecture overview
  • Adding new patterns
  • Testing guidelines
  • Code style

License

Part of the Backlog game engine project.

Acknowledgments

Developed for automatic SDL3 binding generation in the Backlog engine.


Version: 2.1
Status: Production ready for SDL_gpu.h
Last Updated: 2026-01-22