diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2025-01-05 19:02:58 +0100 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2025-01-05 19:03:52 +0100 |
commit | 255e702c0240ecb2ae85304c757013c654598c67 (patch) | |
tree | 5383d3b8a852c1800832e96290433795a6443286 /src/main.zig | |
parent | Initial commit (diff) | |
download | interpreter-255e702c0240ecb2ae85304c757013c654598c67.tar.gz interpreter-255e702c0240ecb2ae85304c757013c654598c67.tar.bz2 interpreter-255e702c0240ecb2ae85304c757013c654598c67.zip |
File reading
Diffstat (limited to 'src/main.zig')
-rw-r--r-- | src/main.zig | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main.zig b/src/main.zig index f92e181..e90f453 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,5 +1,23 @@ const std = @import("std"); +const tokenizer = @import("tokenizer.zig"); pub fn main() !void { - std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); + const pathLen = std.mem.len(std.os.argv[1]); + const path = std.os.argv[1][0..pathLen]; + std.debug.print("Tokenizing! {s}\n", .{path}); + + const file = try std.fs.cwd().openFile(path, .{}); + + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + const allocator = gpa.allocator(); + defer { + const deinit_status = gpa.deinit(); + if (deinit_status == .leak) @panic("Memory leak detected!"); + } + + const buf = try file.readToEndAlloc(allocator, 1 * 1024 * 1024); + defer allocator.free(buf); + + var tknizer = try tokenizer.Tokenizer.init(buf); + std.debug.print("Next: {any}\n", .{tknizer.next()}); } |