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
- There is no
\0escape. Zig’s string escapes are\n,\r,\t,\\,\',\",\xNNand\u{…}(Zig language reference, “String Literals and Unicode Code Point Literals”). The sharedcrate::writer::escape_stringwrites\0, which no Zig compiler reads, sostring_textis this module’s own. - A documentation comment must be attached.
///with no declaration under it iserror: unattached documentation comment, and one above atestblock is refused as well. The file’s own comment is therefore//!— the container form, which is only legal at the top — andzerodds_lang_cst::zig::AnalyseAll’s is a plain//. - 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
;.