diff options
| author | Gabriel Schneider <[email protected]> | 2026-08-18 12:09:12 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-08-18 23:45:25 -0300 |
| commit | c24a9e40215bc30c68c9db7675f1c6a07d9bbae3 (patch) | |
| tree | 9afdb1f3d128bda3f3cf4837c2893982b0a8f69c /src/syntax.zig | |
| parent | 31fece62f56aa2311e2325de83659edbc9e641db (diff) | |
| download | pardes-c24a9e40215bc30c68c9db7675f1c6a07d9bbae3.tar.gz pardes-c24a9e40215bc30c68c9db7675f1c6a07d9bbae3.zip | |
modal + file_pane: rework editing math and pane behavior, config/syntax additions, unit tests
Diffstat (limited to 'src/syntax.zig')
| -rw-r--r-- | src/syntax.zig | 26 |
1 files changed, 25 insertions, 1 deletions
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]))); +} |
