lib/chant/src/lexer/cursor.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const std = @import("std");
2 const chant = @import("../root.zig");
3
4 const Kind = chant.token.Kind;
5 const Token = chant.token.Token;
6
7 pub fn make(self: anytype, kind: Kind, start: usize, column: u32) Token {
8 return .{
9 .kind = kind,
10 .text = self.source[start..self.index],
11 .file = self.file,
12 .line = self.line,
13 .column = column,
14 };
15 }
16
17 pub fn peekIsDigit(self: anytype, offset: usize) bool {
18 const at = self.index + offset;
19 return at < self.source.len and std.ascii.isDigit(self.source[at]);
20 }
21
22 pub fn take(self: anytype, kind: Kind, width: usize) Kind {
23 self.index += width;
24 return kind;
25 }