From c24a9e40215bc30c68c9db7675f1c6a07d9bbae3 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 18 Aug 2026 12:09:12 -0300 Subject: modal + file_pane: rework editing math and pane behavior, config/syntax additions, unit tests --- src/syntax.zig | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/syntax.zig') diff --git a/src/syntax.zig b/src/syntax.zig index b7b9f32f..def11420 100644 --- a/src/syntax.zig +++ b/src/syntax.zig @@ -1,7 +1,7 @@ //! Tree-sitter syntax highlighting: one style byte per content byte, filled by //! running each grammar's highlights.scm query (slurped at build time into the //! ts_queries options module). Grammar set is tiered: `zig`; `minimal` (c, cpp, -//! zig); and `full`, which adds ~23 languages lazily on first use. +//! zig); and `full`, which adds ~24 languages lazily on first use. const std = @import("std"); const config = @import("pardes_config"); const tracy = @import("tracy.zig"); @@ -173,6 +173,7 @@ fn synFor(name: []const u8) Syn { .{ "string", .string }, .{ "character", .string }, .{ "number", .number }, + .{ "numeric", .number }, .{ "float", .number }, .{ "boolean", .number }, .{ "keyword", .keyword }, @@ -239,3 +240,26 @@ test "tree-sitter allocator callbacks preserve and free exact allocations" { try std.testing.expect(syntaxRealloc(live, 0) == null); live = null; } + +test "default full grammar set highlights Typst source" { + if (!enabled or !full_grammars) return; + start(std.testing.allocator); + defer stop(); + + const source = "// note\n#let answer = 42\n#let text = \"hello\"\n"; + const styles = try highlightFileRange(std.testing.allocator, "paper.typst", source, 0, source.len); + defer std.testing.allocator.free(styles); + + const comment_at = std.mem.indexOf(u8, source, "// note").?; + const keyword_at = std.mem.indexOf(u8, source, "let").?; + const number_at = std.mem.indexOf(u8, source, "42").?; + const string_at = std.mem.indexOf(u8, source, "\"hello\"").?; + try std.testing.expectEqual(Syn.comment, @as(Syn, @enumFromInt(styles[comment_at]))); + try std.testing.expectEqual(Syn.keyword, @as(Syn, @enumFromInt(styles[keyword_at]))); + try std.testing.expectEqual(Syn.number, @as(Syn, @enumFromInt(styles[number_at]))); + try std.testing.expectEqual(Syn.string, @as(Syn, @enumFromInt(styles[string_at]))); + + const short_ext = try highlightFileRange(std.testing.allocator, "paper.typ", source, 0, source.len); + defer std.testing.allocator.free(short_ext); + try std.testing.expectEqual(Syn.keyword, @as(Syn, @enumFromInt(short_ext[keyword_at]))); +} -- cgit v1.3