Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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. Private Function

renderContainerField

Private Function
std.zig.Ast.Render.renderContainerField
fn renderContainerField(
    r: *Render,
    container: Container,
    field_param: Ast.full.ContainerField,
    space: Space,
) Error!void

Params

Errors

OutOfMemory

Ran out of memory allocating call stack frames to complete rendering.

WriteFailed

Transitive failure from

File

zig/Ast/Render.zig:1554
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
fn renderContainerField(
    r: *Render,
    container: Container,
    field_param: Ast.full.ContainerField,
    space: Space,
) Error!void {
    const tree = r.tree;
    const ais = r.ais;
    var field = field_param;
    if (container != .tuple) field.convertToNonTupleLike(&tree);
    const quote: QuoteBehavior = switch (container) {
        .@"enum" => .eagerly_unquote_except_underscore,
        .tuple, .other => .eagerly_unquote,
    };

    if (field.comptime_token) |t| {
        try renderToken(r, t, .maybe_space); // comptime
    }

    const last_component: enum {
        value,
        @"align",
        type,
        identifier,
    } = if (field.ast.value_expr != .none)
        .value
    else if (field.ast.align_expr != .none)
        .@"align"
    else if (field.ast.type_expr != .none)
        .type
    else if (!field.ast.tuple_like)
        .identifier
    else
        unreachable;

    if (!field.ast.tuple_like) {
        if (last_component == .identifier) {
            return renderIdentifierComma(r, field.ast.main_token, space, quote); // name
        }
        const this_space: Space = if (field.ast.type_expr != .none) .none else .space;
        try renderIdentifier(r, field.ast.main_token, this_space, quote); // name
    }

    if (field.ast.type_expr.unwrap()) |type_expr| {
        if (!field.ast.tuple_like) {
            try renderToken(r, field.ast.main_token + 1, .maybe_space); // :
        }

        if (last_component == .type) {
            return renderExpressionComma(r, type_expr, space); // type
        }
        try renderExpression(r, type_expr, .space); // type
    }

    if (field.ast.align_expr.unwrap()) |align_expr| {
        const align_token = tree.firstToken(align_expr) - 2;
        try renderToken(r, align_token, .none); // align
        try renderToken(r, align_token + 1, .none); // (
        try renderExpression(r, align_expr, .none); // alignment
        const rparen = tree.lastToken(align_expr) + 1;
        if (last_component == .@"align") {
            return renderTokenComma(r, rparen, space); // )
        }
        try renderToken(r, rparen, .space);
    }

    if (field.ast.value_expr.unwrap()) |value_expr| {
        assert(last_component == .value);
        const eq_token = tree.firstToken(value_expr) - 1;
        const seperate_line = !tree.tokensOnSameLine(eq_token, eq_token + 1) or
            tree.tokenTag(eq_token + 1) == .multiline_string_literal_line;
        const eq_space: Space = if (seperate_line) .newline else .space;

        try ais.pushIndent(.after_equals);
        try renderToken(r, eq_token, eq_space); // =
        if (eq_space == .space) {
            ais.popIndent();
            return renderExpressionComma(r, value_expr, space); // value
        }

        const maybe_comma = tree.lastToken(value_expr) + 1;
        if (tree.tokenTag(maybe_comma) == .comma) {
            try renderExpression(r, value_expr, .none); // value
            ais.popIndent();
            try renderToken(r, maybe_comma, .newline);
        } else {
            try renderExpression(r, value_expr, space); // value
            ais.popIndent();
        }
    } else unreachable;
}