Zig 0.17.0-dev (Split by item) 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 standard library.
std › zon › parse › Parser › parseString Private Function parseString Doc Source Private Function std.zon.parse.Parser.parseString
fn parseString (self : *@This (), T : type , node : Zoir .Node .Index ) ParseExprInnerError !T Params self : *@This () T : type node : Zoir .Node .Index File zon/parse.zig: 696
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729 fn parseString (self : *@This (), T : type , node : Zoir .Node .Index ) ParseExprInnerError !T {
const ast_node = node .getAstNode (self .zoir );
const pointer = @typeInfo (T ).pointer ;
var size_hint = ZonGen .strLitSizeHint (self .ast , ast_node );
if (pointer .sentinel () != null ) size_hint += 1 ;
var aw : std .Io .Writer .Allocating = .init (self .gpa );
try aw .ensureUnusedCapacity (size_hint );
defer aw .deinit ();
const result = ZonGen .parseStrLit (self .ast , ast_node , &aw .writer ) catch return error .OutOfMemory ;
switch (result ) {
.success => {},
.failure => |err | {
const token = self .ast .nodeMainToken (ast_node );
const raw_string = self .ast .tokenSlice (token );
return self .failTokenFmt (token , @intCast (err .offset ()), "{f}" , .{err .fmt (raw_string )});
},
}
if (pointer .child != u8 or
pointer .size != .slice or
!pointer .attrs .@"const" or
(pointer .sentinel () != null and pointer .sentinel () != 0 ) or
(pointer .attrs .@"align" != null and pointer .attrs .@"align" != 1 ))
{
return error .WrongType ;
}
if (pointer .sentinel () != null ) {
return aw .toOwnedSliceSentinel (0 );
} else {
return aw .toOwnedSlice ();
}
}