This commit is contained in:
agra
2026-02-11 14:07:43 +02:00
parent cdc6c59dda
commit 94b0296fd5
11 changed files with 406 additions and 674 deletions

View File

@@ -50,31 +50,25 @@ pub const Lexer = struct {
return self.lexString(start);
}
// Directives: #import, #insert, #run
// Directives: #import, #insert, #run, #builtin
if (c == '#') {
if (self.source.len >= start + 7 and std.mem.eql(u8, self.source[start .. start + 7], "#import") and
(start + 7 >= self.source.len or !isIdentContinue(self.source[start + 7])))
{
self.index = start + 7;
return self.makeToken(.hash_import, start, self.index);
}
if (self.source.len >= start + 7 and std.mem.eql(u8, self.source[start .. start + 7], "#insert") and
(start + 7 >= self.source.len or !isIdentContinue(self.source[start + 7])))
{
self.index = start + 7;
return self.makeToken(.hash_insert, start, self.index);
}
if (self.source.len >= start + 4 and std.mem.eql(u8, self.source[start .. start + 4], "#run") and
(start + 4 >= self.source.len or !isIdentContinue(self.source[start + 4])))
{
self.index = start + 4;
return self.makeToken(.hash_run, start, self.index);
}
if (self.source.len >= start + 8 and std.mem.eql(u8, self.source[start .. start + 8], "#builtin") and
(start + 8 >= self.source.len or !isIdentContinue(self.source[start + 8])))
{
self.index = start + 8;
return self.makeToken(.hash_builtin, start, self.index);
const directives = .{
.{ "#import", Tag.hash_import },
.{ "#insert", Tag.hash_insert },
.{ "#run", Tag.hash_run },
.{ "#builtin", Tag.hash_builtin },
};
inline for (directives) |d| {
const keyword = d[0];
const tag = d[1];
const len: u32 = keyword.len;
if (self.source.len >= start + len and
std.mem.eql(u8, self.source[start .. start + len], keyword) and
(start + len >= self.source.len or !isIdentContinue(self.source[start + len])))
{
self.index = start + len;
return self.makeToken(tag, start, self.index);
}
}
self.index += 1;
return self.makeToken(.invalid, start, self.index);