thp-zig/src/main.zig

35 lines
977 B
Zig
Raw Normal View History

2024-11-16 01:00:15 +00:00
const std = @import("std");
2024-11-16 11:02:56 +00:00
const lexic = @import("./01_lexic/root.zig");
2024-11-16 10:46:19 +00:00
const thp_version: []const u8 = "0.0.0";
2024-11-16 01:00:15 +00:00
pub fn main() !void {
2024-11-16 10:46:19 +00:00
try repl();
}
2024-11-16 01:00:15 +00:00
2024-11-16 10:46:19 +00:00
fn repl() !void {
2024-11-16 01:00:15 +00:00
const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
2024-11-16 10:46:19 +00:00
try stdout.print("The THP REPL, v{s}\n", .{thp_version});
2024-11-16 11:42:26 +00:00
try stdout.print("Enter expressions to evaluate. Enter CTRL-D to exit.\n", .{});
2024-11-16 11:02:56 +00:00
try bw.flush();
const stdin = std.io.getStdIn().reader();
2024-11-16 11:42:26 +00:00
try stdout.print("\nthp => ", .{});
2024-11-16 11:02:56 +00:00
try bw.flush();
2024-11-16 11:42:26 +00:00
const bare_line = try stdin.readUntilDelimiterAlloc(std.heap.page_allocator, '\n', 8192);
defer std.heap.page_allocator.free(bare_line);
const line = std.mem.trim(u8, bare_line, "\r");
2024-11-19 01:08:42 +00:00
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const alloc = gpa.allocator();
2024-11-29 11:13:02 +00:00
const tokens = try lexic.tokenize(line, alloc);
defer tokens.deinit();
2024-11-16 01:00:15 +00:00
2024-11-16 10:46:19 +00:00
try bw.flush();
2024-11-16 01:00:15 +00:00
}