const std = @import("std"); pub const Character = union(enum) { const Self = @This(); pub const EPSILON: u9 = std.math.maxInt(u8) + 1; pub const END: u9 = std.math.maxInt(u8) + 2; epsilon: void, terminal: u8, non_terminal: usize, pub fn format( self: *const Self, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype, ) !void { _ = fmt; _ = options; switch (self.*) { .epsilon => _ = try writer.writeAll("ε"), .terminal => |c| { if (c == END) { try writer.writeAll("$"); } else { try writer.print("'{c}'", .{c}); } }, .non_terminal => |index| try writer.print("<{}>", .{index}), } } };