feat: add Zig syntax highlighting

This commit is contained in:
Valdemar Lorenzen
2026-10-15 11:53:49 +02:00
parent 08db1801eb
commit 2fd240aca8
6 changed files with 69 additions and 5 deletions
+37
View File
@@ -1658,6 +1658,43 @@ mod tests {
);
}
#[test]
fn zig_highlights_literals_builtins_and_predicate_matched_identifiers() {
let source = r#"const std = @import("std");
const MAX_COUNT: u32 = 42;
pub fn main() void {
const local = @as(u32, 7);
const value = Point;
const text =
\\first é
\\second
;
// note
}"#;
let cache = self::cache(source, "main.zig");
for (row, token, kind) in [
(0, "const", SyntaxKind::Keyword),
(0, "@import", SyntaxKind::Keyword),
(0, "\"std\"", SyntaxKind::String),
(1, "MAX_COUNT", SyntaxKind::Keyword),
(1, "u32", SyntaxKind::Type),
(1, "42", SyntaxKind::Number),
(2, "pub", SyntaxKind::Keyword),
(2, "fn", SyntaxKind::Keyword),
(2, "main", SyntaxKind::Function),
(2, "void", SyntaxKind::Type),
(3, "@as", SyntaxKind::Function),
(4, "Point", SyntaxKind::Type),
(6, "first é", SyntaxKind::String),
(7, "second", SyntaxKind::String),
(9, "note", SyntaxKind::Comment),
] {
assert_token(&cache, source, row, token, kind);
}
let local = source.lines().nth(3).unwrap().find("local").unwrap();
assert_eq!(kind_at(&cache, 3, local), None);
}
#[test]
fn filenames_shebang_save_as_and_tsx_use_actual_grammar_identity() {
let source = lines("\u{feff}#!/usr/bin/env python3\nreturn 42");