Skip to content

Add Zig language support module (rewrite-zig)#7339

Draft
zieka wants to merge 1 commit intomainfrom
add-zig-support
Draft

Add Zig language support module (rewrite-zig)#7339
zieka wants to merge 1 commit intomainfrom
add-zig-support

Conversation

@zieka
Copy link
Copy Markdown
Member

@zieka zieka commented Apr 10, 2026

Summary

Adds Zig language support to OpenRewrite following the rewrite-go module architecture:

  • Java side: AST model (Zig.java with 9 node types), ZigVisitor, ZigParser, RPC codecs, formatting visitors, services
  • Zig subprocess: RPC server using std.zig.Ast for parsing, cursor-based whitespace extraction, LST serialization, and source printer
  • Rich AST mapping: Functions, const/var declarations, identifiers, literals, binary/unary ops, if/else, while loops, switch expressions, blocks, return, defer, test decls, comptime, error unions, slices, field access, method calls, assignments, array access, try/catch/orelse
  • 36 integration tests with structural assertions verifying real AST types (not just round-trip)
  • 13 Zig-side unit tests wired into ./gradlew check via zigTest task

Known gaps

  • for loops map to J.Unknown (Zig's multi-input/payload syntax doesn't fit J.ForEachLoop.Control)
  • Container declarations (struct/enum/union bodies) map to J.Unknown
  • No type attribution (Zig stdlib doesn't expose a type-checker API)
  • allowNonWhitespaceInWhitespace validation escape hatch (same as rewrite-go)
  • Import management returns no-op visitor (gracefully skips Zig files)

Test plan

  • ./gradlew :rewrite-zig:zigTest — 13 Zig-side native tests
  • ./gradlew :rewrite-zig:integTest — 36 Java integration tests (round-trip + structural)
  • ./gradlew :rewrite-zig:check — full verification including license headers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants