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 library itself.

parseLabeledStatement

Parse.parseLabeledStatement
fn parseLabeledStatement(p: *Parse) !?Node.Index

File

lib/std/zig/Parse.zig:1208

Code

fn parseLabeledStatement(p: *Parse) !?Node.Index {
    const opt_label_token = p.parseBlockLabel();

    if (try p.parseBlock()) |block| return block;
    if (try p.parseLoopStatement()) |loop_stmt| return loop_stmt;
    if (try p.parseSwitchExpr(opt_label_token != null)) |switch_expr| return switch_expr;

    const label_token = opt_label_token orelse return null;

    const after_colon = p.tok_i;
    // Don't bother trying to give a better error message if recovery is disabled.
    // This avoids a possible stack overflow in e.g. parseTypeExpr() when fuzzing.
    if (p.recover) {
        if (try p.parseTypeExpr()) |_| {
            const a = try p.parseByteAlign();
            const b = try p.parseAddrSpace();
            const c = try p.parseLinkSection();
            const d = if (p.eatToken(.equal) == null) null else try p.expectExpr();
            if (a != null or b != null or c != null or d != null) {
                return p.failMsg(.{ .tag = .expected_var_const, .token = label_token });
            }
        }
    }
    return p.failMsg(.{ .tag = .expected_labelable, .token = after_colon });
}