tiny.chant.ast.stmt
Defined in ast.
API (5)
Types and contracts
Public types and contracts.
Source
Source: lib/chant/src/ast/root.zig:3
zig
pub const stmt = @import("stmt.zig");Source: lib/chant/src/ast/stmt.zig
zig
const std = @import("std");const expr = @import("expr.zig");const variable = @import("variable.zig");pub const Stmt = union(enum) { expression: *expr.Expr, declaration: []variable.Variable, compound: []*Stmt, if_stmt: If, for_stmt: For, while_stmt: While, do_stmt: While, label: Label, return_stmt: ?*expr.Expr, break_stmt, continue_stmt, empty, pub const If = struct { condition: *expr.Expr, then_body: *Stmt, else_body: ?*Stmt, }; pub const For = struct { init: ?*Stmt, condition: ?*expr.Expr, step: ?*expr.Expr, body: *Stmt, }; pub const While = struct { condition: *expr.Expr, body: *Stmt, }; pub const Label = struct { name: []const u8, body: *Stmt, };};test "statements nest" { var arena = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena.deinit(); const allocator = arena.allocator(); const body = try allocator.create(Stmt); body.* = .empty; const loop = try allocator.create(Stmt); loop.* = .{ .for_stmt = .{ .init = null, .condition = null, .step = null, .body = body } }; try std.testing.expect(loop.for_stmt.body.* == .empty); const label = try allocator.create(Stmt); label.* = .{ .label = .{ .name = "again", .body = loop } }; try std.testing.expectEqualStrings("again", label.label.name); try std.testing.expect(label.label.body.* == .for_stmt);}Audit
| Definitions | 6 |
|---|---|
| Public names | 11 |
| Members | 23 |
| Version | 26.7.0 |
| Revision | daab053ee433 |