lib/chant/src/lexer/scan.zig

daab053ee43316e1809a84551d573ddd1e5bf3d2

 1 const chant = @import("../root.zig");
 2 const identifier = @import("identifier.zig");
 3 const literal = @import("literal.zig");
 4 const number = @import("number.zig");
 5 const punctuator = @import("punctuator.zig");
 6 const trivia = @import("trivia.zig");
 7 
 8 const Token = chant.token.Token;
 9 const Error = @import("error.zig").Error;
10 
11 pub fn next(self: anytype) Error!Token {
12     try trivia.skip(self);
13     const start = self.index;
14     const column: u32 = @intCast(self.index - self.line_start + 1);
15 
16     if (self.index >= self.source.len) {
17         return .{
18             .kind = .eof,
19             .text = self.source[start..self.index],
20             .file = self.file,
21             .line = self.line,
22             .column = column,
23         };
24     }
25 
26     if (try literal.lex(self, start, column)) |tok| return tok;
27     if (identifier.lex(self, start, column)) |tok| return tok;
28     if (number.lex(self, start, column)) |tok| return tok;
29     return punctuator.lex(self, start, column);
30 }