lib/chant/src/lexer/identifier.zig
daab053ee43316e1809a84551d573ddd1e5bf3d2
1 const std = @import("std");
2 const chant = @import("../root.zig");
3 const cursor = @import("cursor.zig");
4
5 const Token = chant.token.Token;
6
7 pub fn lex(self: anytype, start: usize, column: u32) ?Token {
8 if (!starts(self.source[self.index])) return null;
9 while (self.index < self.source.len and continues(self.source[self.index])) {
10 self.index += 1;
11 }
12 const text = self.source[start..self.index];
13 const kind = chant.token.keywordKind(text) orelse .identifier;
14 return cursor.make(self, kind, start, column);
15 }
16
17 fn starts(c: u8) bool {
18 return std.ascii.isAlphabetic(c) or c == '_';
19 }
20
21 fn continues(c: u8) bool {
22 return std.ascii.isAlphanumeric(c) or c == '_';
23 }