diff options
Diffstat (limited to 'src/lexer/Lexer.zig')
| -rw-r--r-- | src/lexer/Lexer.zig | 7 |
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; |
