From db2f49115713c47b48587022511b3654a7042493 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Sun, 19 Apr 2026 22:28:56 +0200 Subject: feat(lib): support input from file and from reader --- src/lexer/Lexer.zig | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/lexer') diff --git a/src/lexer/Lexer.zig b/src/lexer/Lexer.zig index 318e422..8b3893d 100644 --- a/src/lexer/Lexer.zig +++ b/src/lexer/Lexer.zig @@ -18,6 +18,13 @@ pub fn init(content: []const u8) error{InvalidUtf8}!Self { return .{ .iter = view.iterator() }; } +// Must free bytes in iter. +pub fn initReader(alloc: Allocator, r: *std.io.Reader) !Self { + var acc = try std.ArrayList(u8).initCapacity(alloc, 2); + try r.appendRemainingUnlimited(alloc, &acc); + return init(try acc.toOwnedSlice(alloc)); +} + pub fn nextKind(self: *Self) ?Lexed.Kind { const next_rune = self.iter.peek(1); if (next_rune.len == 0) return null; -- cgit v1.2.3