const std = @import("std"); const TokenType = @import("token_type.zig").TokenType; const Token = @This(); type: TokenType, lexeme: []const u8, literal: ?Literal, line: u32, pub const Literal = union { string: []const u8, number: f64, }; pub fn init(@"type": TokenType, lexeme: []const u8, literal: ?Literal, line: u32) Token { return .{ .type = @"type", .lexeme = lexeme, .literal = literal, .line = line, }; } pub fn format(self: Token, writer: *std.io.Writer) !void { try writer.print("{} {s} {any}", .{ self.type, self.lexeme, self.literal }); }