diff options
| author | Gabriel Schneider <[email protected]> | 2026-07-10 17:32:43 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-08-01 15:02:07 -0300 |
| commit | 685b8c8e74c9edbdf701594f50ff1b70ac288ec9 (patch) | |
| tree | f303bd5e1f422030c2c645ea2d6c3a393990fb5e /src/syntax.zig | |
| parent | ddc2eefb1e7cdd402593efb1297c25fc7ae4b110 (diff) | |
| download | pardes-685b8c8e74c9edbdf701594f50ff1b70ac288ec9.tar.gz pardes-685b8c8e74c9edbdf701594f50ff1b70ac288ec9.zip | |
web snapshots: add switch for saving/loading exports, update web version, web snapshot tooling
Diffstat (limited to 'src/syntax.zig')
| -rw-r--r-- | src/syntax.zig | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/syntax.zig b/src/syntax.zig index 0d2fa291..bbab17fa 100644 --- a/src/syntax.zig +++ b/src/syntax.zig @@ -1,12 +1,13 @@ //! 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: `minimal` (c, cpp, zig) -//! compiles queries at startup; `full` adds ~23 languages lazily on first use. +//! ts_queries options module). Grammar set is tiered: `zig`; `minimal` (c, cpp, +//! zig); and `full`, which adds ~23 languages lazily on first use. const std = @import("std"); const config = @import("pardes_config"); const tracy = @import("tracy.zig"); pub const enabled = config.syntax_highlighting; +const zig_grammar = config.syntax_zig_grammar; const minimal_grammars = config.syntax_minimal_grammars; const full_grammars = config.syntax_full_grammars; @@ -52,10 +53,13 @@ const Spec = struct { compiled_query: ?*ts.Query = null, }; +var zig_specs = if (zig_grammar) [_]Spec{ + .{ .exts = &.{ ".zig", ".zon" }, .language = tree_sitter_zig, .query_src = ts_queries.zig_highlights }, +} else [_]Spec{}; + var minimal_specs = if (minimal_grammars) [_]Spec{ .{ .exts = &.{ ".c", ".h" }, .language = tree_sitter_c, .query_src = ts_queries.c_highlights }, .{ .exts = &.{ ".cpp", ".cc", ".cxx", ".hpp", ".hh", ".hxx" }, .language = tree_sitter_cpp, .query_src = ts_queries.cpp_highlights }, - .{ .exts = &.{ ".zig", ".zon" }, .language = tree_sitter_zig, .query_src = ts_queries.zig_highlights }, } else [_]Spec{}; var full_specs = if (full_grammars) [_]Spec{ @@ -98,6 +102,11 @@ fn ensure(spec: *Spec) !Selected { } fn forExt(ext: []const u8) !?Selected { + for (&zig_specs) |*spec| { + for (spec.exts) |choice| { + if (std.ascii.eqlIgnoreCase(ext, choice)) return try ensure(spec); + } + } for (&minimal_specs) |*spec| { for (spec.exts) |choice| { if (std.ascii.eqlIgnoreCase(ext, choice)) return try ensure(spec); @@ -111,9 +120,10 @@ fn forExt(ext: []const u8) !?Selected { return null; } -/// compile the minimal-tier queries eagerly so the first .zig/.c open is fast +/// Compile the compact-tier queries eagerly so the first source open is fast. pub fn compileStartupQueries() void { if (!enabled) return; + for (&zig_specs) |*spec| _ = ensure(spec) catch {}; for (&minimal_specs) |*spec| _ = ensure(spec) catch {}; } |
