# Zig Code builder

**URL:** <https://ziggit.dev/t/zig-code-builder/4556>\
**Category:** Help\
**Tags:** language, standard-library\
**Created:** [June 3, 2024, 1:49am UTC](https://ziggit.dev/t/zig-code-builder/4556 "2024-06-03T01:49:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![whisper-bye](https://ziggit.dev/user_avatar/ziggit.dev/whisper-bye/32/2452_2.png) [@whisper-bye](https://ziggit.dev/u/whisper-bye)\
**Post date:** [June 3, 2024, 1:49am UTC](https://ziggit.dev/t/zig-code-builder/4556/1 "2024-06-03T01:49:25Z")

</div>

In some programming languages, there are built-in code builders, which can be very useful for generating boilerplate code.

Does Zig have something similar?

References:

In Golang with go/ast

> **[ast package - go/ast - Go Packages](https://pkg.go.dev/go/ast)**
>
> Package ast declares the types used to represent syntax trees for Go packages.

In Java with sun.codemodel

> **[Use CodeModel to generate Java Source Code](https://namanmehta.blogspot.com/2010/01/use-codemodel-to-generate-java-source.html)**
>
> CodeModel is a library that allows you to generate Java source code in a type-safe fashion. When to use CodeModel: If you have huge chunk o...

---

<div class="post-metadata">

**Author:** ![whisper-bye](https://ziggit.dev/user_avatar/ziggit.dev/whisper-bye/32/2452_2.png) [@whisper-bye](https://ziggit.dev/u/whisper-bye)\
**Post date:** [June 3, 2024, 1:54am UTC](https://ziggit.dev/t/zig-code-builder/4556/2 "2024-06-03T01:54:21Z")

</div>

It would be better if the API could be simpler and more user-friendly, similar to [GitHub - square/javapoet: A Java API for generating .java source files.](https://github.com/square/javapoet).

---

<div class="post-metadata">

**Author:** ![Calder-Ty](https://ziggit.dev/user_avatar/ziggit.dev/calder-ty/32/10237_2.png) [@Calder-Ty](https://ziggit.dev/u/Calder-Ty)\
**Post date:** [June 3, 2024, 2:10am UTC](https://ziggit.dev/t/zig-code-builder/4556/3 "2024-06-03T02:10:40Z")

</div>

Hi @whisper-bye !

It sounds like you are asking about metaprograming, like how Rust macros are used to generate/Expand to correct rust code by manipulating the AST.

In zig that is one of the roles of comptime code. rather than having to learn a different sub language, you just write in zig, asserting values and expressions to be comptime as needed. I’m no expert in comptime so i’m not sure if it covers all the usecases that you might be thinking of. What are you wanting to do that you are trying to reach for an AST manipulator?

---

<div class="post-metadata">

**Author:** ![whisper-bye](https://ziggit.dev/user_avatar/ziggit.dev/whisper-bye/32/2452_2.png) [@whisper-bye](https://ziggit.dev/u/whisper-bye)\
**Post date:** [June 3, 2024, 6:56am UTC](https://ziggit.dev/t/zig-code-builder/4556/4 "2024-06-03T06:56:12Z")

</div>

Hi, My question is not related to metaprogramming. I just want to know if Zig has built-in support for generating boilerplate code, similar to what is mentioned in the reference links.

---

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [June 3, 2024, 7:38am UTC](https://ziggit.dev/t/zig-code-builder/4556/5 "2024-06-03T07:38:56Z")

</div>

The relative package is [std.zig](https://ziglang.org/documentation/master/std/#std.zig)  
Start with [Ast.parse](https://ziglang.org/documentation/master/std/#std.zig.Ast.parse) and [Ast.render](https://ziglang.org/documentation/master/std/#std.zig.Ast.render).
