]> Repositories - zlox.git/blob - src/Token.zig
Fix shadowing mistake
[zlox.git] / src / Token.zig
1 const std = @import("std");
2 const TokenType = @import("token_type.zig").TokenType;
3 const Token = @This();
4
5 type: TokenType,
6 lexeme: []const u8,
7 literal: ?Literal,
8 line: u32,
9
10 pub const Literal = union(enum) {
11     string: []const u8,
12     number: f64,
13     boolean: bool,
14     nil: void,
15 };
16
17 pub fn init(@"type": TokenType, lexeme: []const u8, literal: ?Literal, line: u32) Token {
18     return .{
19         .type = @"type",
20         .lexeme = lexeme,
21         .literal = literal,
22         .line = line,
23     };
24 }
25
26 pub fn format(self: Token, writer: *std.io.Writer) !void {
27     try writer.print("{} {s} {any}", .{ self.type, self.lexeme, self.literal });
28 }