The three-level node model for Zig source generation. Generators
produce declaration, statement, and expression nodes as plain data;
the single render function turns them into Zig source text. This is
the ONLY namespace that knows about braces, newlines, indentation, and
semicolons.
The node model is a pruned view of Zig's own AST decomposition. It
covers the subset clj-zig generates: function declarations, struct and
enum declarations, the common statement forms (const, assign, return,
if, for, defer), and a small expression vocabulary (ref, field, deref,
call, lit, as, slice). The :raw node at each level is the escape
hatch for user-written Zig body text and one-off complex expressions
the generators do not model.
Generators compose nodes with the constructor functions, never with
str. Type strings (like "i64" or "[]const f64") are the
exception: they are opaque tokens passed through from zig-type. The
four-space indent appears ONLY in the renderer's indent function.
The three-level node model for Zig source generation. Generators produce declaration, statement, and expression nodes as plain data; the single `render` function turns them into Zig source text. This is the ONLY namespace that knows about braces, newlines, indentation, and semicolons. The node model is a pruned view of Zig's own AST decomposition. It covers the subset clj-zig generates: function declarations, struct and enum declarations, the common statement forms (const, assign, return, if, for, defer), and a small expression vocabulary (ref, field, deref, call, lit, as, slice). The `:raw` node at each level is the escape hatch for user-written Zig body text and one-off complex expressions the generators do not model. Generators compose nodes with the constructor functions, never with `str`. Type strings (like `"i64"` or `"[]const f64"`) are the exception: they are opaque tokens passed through from `zig-type`. The four-space indent appears ONLY in the renderer's `indent` function.
(assign-stmt target value)An assignment statement: target = value;.
An assignment statement: `target = value;`.
(const-decl name init)A top-level const declaration node.
A top-level `const` declaration node.
(const-stmt name init)(const-stmt name type init)A local const statement: const name = init; or
const name: type = init;.
A local `const` statement: `const name = init;` or `const name: type = init;`.
(defer-stmt expr)A defer statement: defer expr;.
A defer statement: `defer expr;`.
(enum-decl name backing members)An enum(backing) declaration node.
An `enum(backing)` declaration node.
(export-fn-decl name params ret body)An exported function declaration node (C ABI entry point).
An exported function declaration node (C ABI entry point).
(expr-stmt value)An expression statement: expr;.
An expression statement: `expr;`.
(extern-struct-decl name fields)An extern struct declaration node (C ABI layout).
An `extern struct` declaration node (C ABI layout).
(field-data name type)One struct field as node data: {:name name :type type}.
One struct field as node data: `{:name name :type type}`.
(fn-decl name params ret body)A non-exported function declaration node.
A non-exported function declaration node.
(for-stmt header body)A for loop: for header { body }. The header is a raw string like
(__nice, 0..) |*__dst, __i| because the for-loop capture syntax is
too varied to model.
A for loop: `for header { body }`. The `header` is a raw string like
`(__nice, 0..) |*__dst, __i|` because the for-loop capture syntax is
too varied to model.(if-stmt cond body)(if-stmt cond body else)An if statement: if (cond) { body } with an optional else branch.
An if statement: `if (cond) { body }` with an optional else branch.
(lit value)A literal expression node. value is Zig source text rendered verbatim
(a number, a boolean, a string of source).
A literal expression node. `value` is Zig source text rendered verbatim (a number, a boolean, a string of source).
(packed-struct-decl name fields)A packed struct declaration node.
A `packed struct` declaration node.
(param name type)One function parameter as node data: {:name name :type type}.
One function parameter as node data: `{:name name :type type}`.
(raw-decl text)A raw declaration node (opaque Zig source text).
A raw declaration node (opaque Zig source text).
(raw-stmt text)A raw statement node (opaque Zig source, indented by the renderer at the enclosing level). Used for user body text and multi-line fragments whose indentation is relative to the function body.
A raw statement node (opaque Zig source, indented by the renderer at the enclosing level). Used for user body text and multi-line fragments whose indentation is relative to the function body.
(render decls)Render a vector of declaration nodes to Zig source text. Each declaration is separated by a blank line. The output carries no trailing newline.
Render a vector of declaration nodes to Zig source text. Each declaration is separated by a blank line. The output carries no trailing newline.
(return-stmt)(return-stmt value)A return statement. With no argument, a bare return;.
A return statement. With no argument, a bare `return;`.
(struct-decl name fields)A regular struct declaration node.
A regular `struct` declaration node.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |