const std = @import("std"); const Loc = @import("loc.zig").Loc; const Formatter = @import("../formatter.zig").Formatter; pub const LitType = union(enum) { null: void, bool: bool, number: f64, string: []const u8, regex: Regex, bigint: []const u8, }; pub const Lit = struct { loc: Loc, data: LitType, pub fn fmt(self: @This(), f: *Formatter) void { switch (self.data) { .null => f.write("null"), .bool => |b| f.write(if (b) "true" else "false"), .number => |n| { var buf: [64]u8 = undefined; f.write(std.fmt.bufPrint(&buf, "{d}", .{n}) catch "0"); }, .string => |s| { f.writeChar('"'); f.write(s); f.writeChar('"'); }, .regex => |r| { f.writeChar('/'); f.write(r.pattern); f.writeChar('/'); f.write(r.flags); }, .bigint => |s| { f.write(s); f.writeChar('n'); }, } } }; pub const Regex = struct { pattern: []const u8, flags: []const u8, };