Skip to main content

Module zig

Module zig 

Source
Expand description

Rendering the Zig CST. Spec §5.

One style, zig fmt’s: four spaces, the opening brace on the same line, a trailing comma on every member of a multi-line container, // and /// comments. Not a preference — zig fmt ships with the compiler and every reader of a generated file runs it, so a file that moves under it is a diff nobody asked for. The layout here is checked against the real formatter by zerodds-lang-rules/tests/zig_end_to_end.rs.

Nothing is decided here. A Zig type reads left to right and carries its own length, optionality and pointer depth, so unlike crate::c there is no declarator to split around a name: a field is the name, a colon, and the type.

§Three places Zig’s lexical rules differ from the C family

  1. There is no \0 escape. Zig’s string escapes are \n, \r, \t, \\, \', \", \xNN and \u{…} (Zig language reference, “String Literals and Unicode Code Point Literals”). The shared crate::writer::escape_string writes \0, which no Zig compiler reads, so string_text is this module’s own.
  2. A documentation comment must be attached. /// with no declaration under it is error: unattached documentation comment, and one above a test block is refused as well. The file’s own comment is therefore //! — the container form, which is only legal at the top — and zerodds_lang_cst::zig::AnalyseAll’s is a plain //.
  3. A container’s members end in a comma, not a semicolon. A struct field, an enum variant and a function parameter are all comma-separated; only a declaration ends in ;.

Functions§

char_text
The same, for a character literal.
decl
Render one declaration, for a caller that has only one.
file
Render a whole file.
ident
The identifier a name renders as, for a caller assembling one.
string_text
Escape a string for a Zig string literal.
type_
Render one type, for a caller that has only one.