feat: read user input

This commit is contained in:
Araozu 2024-11-16 06:02:56 -05:00
parent 9b43095f86
commit d8df211f46
2 changed files with 21 additions and 1 deletions

3
src/01_lexic/root.zig Normal file
View File

@ -0,0 +1,3 @@
pub fn stub() i32 {
return 322;
}

View File

@ -1,4 +1,6 @@
const std = @import("std"); const std = @import("std");
const lexic = @import("./01_lexic/root.zig");
const thp_version: []const u8 = "0.0.0"; const thp_version: []const u8 = "0.0.0";
pub fn main() !void { pub fn main() !void {
@ -13,8 +15,18 @@ fn repl() !void {
var bw = std.io.bufferedWriter(stdout_file); var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer(); const stdout = bw.writer();
try stdout.print("The THP REPL, v{s}\n", .{thp_version}); try stdout.print("The THP REPL, v{s}\n", .{thp_version});
try stdout.print("Enter expressions to evaluate. Enter CTRL-D to exit.\n", .{}); try stdout.print("Enter expressions to evaluate. Enter CTRL-D to exit.\n\n", .{});
try bw.flush();
const stdin = std.io.getStdIn().reader();
try stdout.print("thp => ", .{});
try bw.flush();
const user_input = try stdin.readUntilDelimiterAlloc(std.heap.page_allocator, '\n', 8192);
defer std.heap.page_allocator.free(user_input);
try stdout.print("got: `{s}`\n", .{user_input});
try bw.flush(); try bw.flush();
} }
@ -24,3 +36,8 @@ test "simple test" {
try list.append(42); try list.append(42);
try std.testing.expectEqual(@as(i32, 42), list.pop()); try std.testing.expectEqual(@as(i32, 42), list.pop());
} }
test "new test" {
const res = lexic.stub();
try std.testing.expectEqual(@as(i32, 322), res);
}