This commit is contained in:
agra
2026-02-11 20:41:43 +02:00
parent 94b0296fd5
commit 9d96f05d3b
13 changed files with 460 additions and 70 deletions

View File

@@ -50,13 +50,15 @@ pub const Lexer = struct {
return self.lexString(start);
}
// Directives: #import, #insert, #run, #builtin
// Directives: #import, #insert, #run, #builtin, #foreign, #library
if (c == '#') {
const directives = .{
.{ "#import", Tag.hash_import },
.{ "#insert", Tag.hash_insert },
.{ "#run", Tag.hash_run },
.{ "#builtin", Tag.hash_builtin },
.{ "#foreign", Tag.hash_foreign },
.{ "#library", Tag.hash_library },
};
inline for (directives) |d| {
const keyword = d[0];
@@ -370,6 +372,25 @@ test "lex hash_insert" {
try std.testing.expectEqual(Tag.invalid, lex2.next().tag);
}
test "lex hash_foreign" {
var lex = Lexer.init("#foreign");
try std.testing.expectEqual(Tag.hash_foreign, lex.next().tag);
try std.testing.expectEqual(Tag.eof, lex.next().tag);
var lex2 = Lexer.init("#foreignx");
try std.testing.expectEqual(Tag.invalid, lex2.next().tag);
}
test "lex hash_library" {
var lex = Lexer.init("#library \"raylib\"");
try std.testing.expectEqual(Tag.hash_library, lex.next().tag);
try std.testing.expectEqual(Tag.string_literal, lex.next().tag);
try std.testing.expectEqual(Tag.eof, lex.next().tag);
var lex2 = Lexer.init("#librarypath");
try std.testing.expectEqual(Tag.invalid, lex2.next().tag);
}
test "lex string" {
var lex = Lexer.init("\"Hello\"");
const tok = lex.next();