This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.
constPattern = struct {
slicer: MacroSlicer,
impl: Impl,
fninit(pl: *Pattern, allocator: mem.Allocator, template: Template) Error!void {
constsource = template[0];
constimpl = template[1];
vartok_list: std.ArrayList(CToken) = .empty;
defertok_list.deinit(allocator);
pl.* = .{
.slicer = trytokenizeMacro(allocator, source, &tok_list),
.impl = impl,
};
}
fndeinit(pl: *Pattern, allocator: mem.Allocator) void {
allocator.free(pl.slicer.tokens);
pl.* = undefined;
}
/// This function assumes that `ms` has already been validated to contain a function-like/// macro, and that the parsed template macro in `pl` also contains a function-like/// macro. Please review this logic carefully if changing that assumption. Two/// function-like macros are considered equivalent if and only if they contain the same/// list of tokens, modulo parameter names.fnmatches(pat: Pattern, ms: MacroSlicer) bool {
if (ms.params != pat.slicer.params) returnfalse;
if (ms.tokens.len != pat.slicer.tokens.len) returnfalse;
for (ms.tokens, pat.slicer.tokens) |macro_tok, pat_tok| {
if (macro_tok.id != pat_tok.id) returnfalse;
switch (macro_tok.id) {
.macro_param, .macro_param_no_expand => {
// `.end` is the parameter index.if (macro_tok.end != pat_tok.end) returnfalse;
},
.identifier, .extended_identifier, .string_literal, .char_literal, .pp_num => {
constmacro_bytes = ms.slice(macro_tok);
constpattern_bytes = pat.slicer.slice(pat_tok);
if (!mem.eql(u8, pattern_bytes, macro_bytes)) returnfalse;
},
else => {
// other tags correspond to keywords and operators that do not contain a "payload"
// that can vary
},
}
}
returntrue;
}
}