const std = @import("std"); const ParserError = error{ InvalidCharacter, EndOfString }; str: []const u8, pos: u32 = 0, const Self = @This(); pub fn peek(self: Self) ?u8 { if (self.pos > self.str.len) return null; return self.str[self.pos]; } pub fn consume(self: *Self, c: u8) ParserError!void { if (self.peek()) |pk| { if (pk == c) { self.pos += 1; return c; } return .InvalidCharacter; } return .EndOfString; } pub fn skip(self: *Self) void { self.pos += 1; } pub fn takeUntil(self: *Self, c: u8) ParserError![]const u8 { const i = self.pos; while (if (self.peek()) |pk| pk != c else { self.pos = i; return .EndOfString; }) { self.skip(); } return self.str[i..self.pos]; }