-
-
Save paulsmith/a725621af11f8700f7d291fc74bc19ac to your computer and use it in GitHub Desktop.
infinite semantic analysis loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const Node = union(enum) { | |
leaf: u8, | |
node: ?*Node, | |
pub fn format(self: Node, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) @TypeOf(writer).Error!void { | |
switch (self) { | |
.leaf => { | |
try writer.writeAll("leaf=\""); | |
try std.fmt.format(writer, "{}", .{self.leaf}); | |
try writer.writeAll("\""); | |
}, | |
.node => { | |
try writer.writeAll("node=["); | |
if (self.node) |n| try n.format("{}", options, writer); | |
try writer.writeAll("]"); | |
}, | |
} | |
} | |
}; | |
pub fn main() anyerror!void { | |
var leaf = Node{ .leaf = 127 }; | |
var node = Node{ .node = &leaf }; | |
var root = Node{ .node = &node }; | |
std.debug.print("{}\n", .{root}); | |
} |
Author
paulsmith
commented
Apr 14, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment