aboutsummaryrefslogtreecommitdiff
path: root/src/lexer
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-04-19 22:28:56 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2026-04-19 22:28:56 +0200
commitdb2f49115713c47b48587022511b3654a7042493 (patch)
tree159535d22691f2d1287e568e44fe3a90dc8443c7 /src/lexer
parentb9d58fbbd94dc8f97f9f4c6c333039386bbbeaa1 (diff)
feat(lib): support input from file and from reader
Diffstat (limited to 'src/lexer')
-rw-r--r--src/lexer/Lexer.zig7
1 files changed, 7 insertions, 0 deletions
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;