Compare commits
22 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 272a2d0b01 | |||
| 2b6cd9fe39 | |||
| 2d2d8dd88d | |||
| 505427ee32 | |||
| b56a7847d0 | |||
| b8240ffc25 | |||
| 68f0f7d26a | |||
| 9cf6617fd2 | |||
| e95f1ad049 | |||
| 43fc008c58 | |||
|
|
8a3f9deb2d | ||
| f769544eed | |||
| 851789d5d6 | |||
| 621a31024a | |||
| 02c26ba48f | |||
| 7f18430932 | |||
| f7af9e1c0f | |||
| ad07bfe4f9 | |||
| 880eac1a7e | |||
| 5c8b804def | |||
| 740fe75707 | |||
| 837844220c |
8 changed files with 440 additions and 47 deletions
44
build.zig
44
build.zig
|
|
@ -2,6 +2,7 @@ const std = @import("std");
|
||||||
|
|
||||||
pub fn build(b: *std.Build) void {
|
pub fn build(b: *std.Build) void {
|
||||||
const use_tree_sitter = b.option(bool, "use_tree_sitter", "Enable tree-sitter (default: yes)") orelse true;
|
const use_tree_sitter = b.option(bool, "use_tree_sitter", "Enable tree-sitter (default: yes)") orelse true;
|
||||||
|
const use_llvm = b.option(bool, "use_llvm", "Enable llvm backend (default: none)");
|
||||||
const options = b.addOptions();
|
const options = b.addOptions();
|
||||||
options.addOption(bool, "use_tree_sitter", use_tree_sitter);
|
options.addOption(bool, "use_tree_sitter", use_tree_sitter);
|
||||||
const options_mod = options.createModule();
|
const options_mod = options.createModule();
|
||||||
|
|
@ -29,6 +30,10 @@ pub fn build(b: *std.Build) void {
|
||||||
.optimize = .Debug,
|
.optimize = .Debug,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
if (use_llvm) |value| {
|
||||||
|
ts_bin_query_gen.use_llvm = value;
|
||||||
|
ts_bin_query_gen.use_lld = value;
|
||||||
|
}
|
||||||
ts_bin_query_gen.linkLibC();
|
ts_bin_query_gen.linkLibC();
|
||||||
ts_bin_query_gen.root_module.addImport("cbor", cbor_dep.module("cbor"));
|
ts_bin_query_gen.root_module.addImport("cbor", cbor_dep.module("cbor"));
|
||||||
ts_bin_query_gen.root_module.addImport("treez", tree_sitter_host_dep.module("treez"));
|
ts_bin_query_gen.root_module.addImport("treez", tree_sitter_host_dep.module("treez"));
|
||||||
|
|
@ -36,6 +41,7 @@ pub fn build(b: *std.Build) void {
|
||||||
|
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "queries/cmake/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "queries/cmake/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-agda/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-agda/queries/highlights.scm");
|
||||||
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-asm/queries/asm/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-astro/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-astro/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-awk/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-awk/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-bash/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-bash/queries/highlights.scm");
|
||||||
|
|
@ -43,6 +49,7 @@ pub fn build(b: *std.Build) void {
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-c/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-c/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-cpp/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-cpp/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-css/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-css/queries/highlights.scm");
|
||||||
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "queries/d/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-diff/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-diff/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-dockerfile/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-dockerfile/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-elixir/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-elixir/queries/highlights.scm");
|
||||||
|
|
@ -64,7 +71,7 @@ pub fn build(b: *std.Build) void {
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-julia/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-julia/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-kdl/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-kdl/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-lua/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-lua/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-mail/queries/mail/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-mail/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-make/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-make/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-markdown/tree-sitter-markdown/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-markdown/tree-sitter-markdown/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-markdown/tree-sitter-markdown-inline/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-markdown/tree-sitter-markdown-inline/queries/highlights.scm");
|
||||||
|
|
@ -74,6 +81,7 @@ pub fn build(b: *std.Build) void {
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-ninja/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-ninja/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-nix/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-nix/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-nu/queries/nu/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-nu/queries/nu/highlights.scm");
|
||||||
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-objc/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-ocaml/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-ocaml/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-odin/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-odin/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-openscad/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-openscad/queries/highlights.scm");
|
||||||
|
|
@ -85,8 +93,10 @@ pub fn build(b: *std.Build) void {
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-proto/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-proto/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-python/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-python/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-purescript/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-purescript/queries/highlights.scm");
|
||||||
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-query/queries/query/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-regex/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-regex/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-rpmspec/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-rpmspec/rpmbash/queries/highlights.scm");
|
||||||
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-rpmspec/rpmspec/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-ruby/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-ruby/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-rust/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-rust/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-ssh-config/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-ssh-config/queries/highlights.scm");
|
||||||
|
|
@ -106,15 +116,20 @@ pub fn build(b: *std.Build) void {
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-zig/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-zig/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-ziggy/tree-sitter-ziggy/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-ziggy/tree-sitter-ziggy/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-ziggy/tree-sitter-ziggy-schema/queries/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-ziggy/tree-sitter-ziggy-schema/queries/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/queries/verilog/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/runtime/queries/systemverilog/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/queries/commonlisp/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/runtime/queries/comment/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/queries/latex/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/runtime/queries/commonlisp/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/queries/hcl/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/runtime/queries/latex/highlights.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/queries/rst/highlights.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/runtime/queries/llvm/highlights.scm");
|
||||||
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/runtime/queries/hcl/highlights.scm");
|
||||||
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/runtime/queries/hurl/highlights.scm");
|
||||||
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/runtime/queries/rst/highlights.scm");
|
||||||
|
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "queries/cmake/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "queries/cmake/injections.scm");
|
||||||
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-asm/queries/asm/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-astro/queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-astro/queries/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-cpp/queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-cpp/queries/injections.scm");
|
||||||
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "queries/d/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-elixir/queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-elixir/queries/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-elm/queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-elm/queries/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-fsharp/queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-fsharp/queries/injections.scm");
|
||||||
|
|
@ -131,6 +146,7 @@ pub fn build(b: *std.Build) void {
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-nickel/queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-nickel/queries/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-nix/queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-nix/queries/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-nu/queries/nu/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-nu/queries/nu/injections.scm");
|
||||||
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-objc/queries/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-odin/queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-odin/queries/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-openscad/queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-openscad/queries/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-perl/queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-perl/queries/injections.scm");
|
||||||
|
|
@ -138,6 +154,8 @@ pub fn build(b: *std.Build) void {
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-po/queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-po/queries/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-purescript/queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-purescript/queries/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-purescript/vim_queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-purescript/vim_queries/injections.scm");
|
||||||
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-query/queries/query/injections.scm");
|
||||||
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-rpmspec/rpmspec/queries/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-rust/queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-rust/queries/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-superhtml/tree-sitter-superhtml/queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-superhtml/tree-sitter-superhtml/queries/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-swift/queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-swift/queries/injections.scm");
|
||||||
|
|
@ -145,11 +163,13 @@ pub fn build(b: *std.Build) void {
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-uxntal/queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-uxntal/queries/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-vim/queries/vim/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-vim/queries/vim/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-zig/queries/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "tree-sitter-zig/queries/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/queries/verilog/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/runtime/queries/systemverilog/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/queries/commonlisp/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/runtime/queries/commonlisp/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/queries/latex/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/runtime/queries/latex/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/queries/hcl/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/runtime/queries/llvm/injections.scm");
|
||||||
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/queries/rst/injections.scm");
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/runtime/queries/hcl/injections.scm");
|
||||||
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/runtime/queries/hurl/injections.scm");
|
||||||
|
ts_queryfile(b, tree_sitter_dep, ts_bin_query_gen, "nvim-treesitter/runtime/queries/rst/injections.scm");
|
||||||
|
|
||||||
const syntax_mod = b.addModule("syntax", .{
|
const syntax_mod = b.addModule("syntax", .{
|
||||||
.root_source_file = b.path("src/syntax.zig"),
|
.root_source_file = b.path("src/syntax.zig"),
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
.{
|
.{
|
||||||
.name = .flow_syntax,
|
.name = .flow_syntax,
|
||||||
.version = "0.6.0",
|
.version = "0.7.2",
|
||||||
.fingerprint = 0x3ba2584ea1cec85f,
|
.fingerprint = 0x3ba2584ea1cec85f,
|
||||||
.minimum_zig_version = "0.15.2",
|
.minimum_zig_version = "0.15.2",
|
||||||
|
|
||||||
.dependencies = .{
|
.dependencies = .{
|
||||||
.tree_sitter = .{
|
.tree_sitter = .{
|
||||||
.url = "https://github.com/neurocyte/tree-sitter/releases/download/master-6e2827ee231e220467bf04d2a2746faff5cb204a/source.tar.gz",
|
.url = "https://github.com/neurocyte/tree-sitter/releases/download/master-8019244129e071aaefc4d2eeccd94abbc8858319/source.tar.gz",
|
||||||
.hash = "tree_sitter-0.22.4-150-g7e3f5726-z0LhyGeG1y67PeOltaplVkxRNT2jMMexQhbUlrh0vdxM",
|
.hash = "tree_sitter-0.26.7-z0LhyJlMmjAIlq51UWa5D5S-xDgnlqcDBLLt6UURMhtm",
|
||||||
},
|
},
|
||||||
.cbor = .{
|
.cbor = .{
|
||||||
.url = "git+https://github.com/neurocyte/cbor?ref=master#7d2eeb68c8a2fb3f4d6baad6cc04c521b92974c0",
|
.url = "git+https://github.com/neurocyte/cbor?ref=master#7d2eeb68c8a2fb3f4d6baad6cc04c521b92974c0",
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,6 @@ fn deserialize_query(query_bin: []const u8, language: ?*const treez.Language, al
|
||||||
var ts_query_out, const arena = try tss.fromCbor(query_bin, allocator);
|
var ts_query_out, const arena = try tss.fromCbor(query_bin, allocator);
|
||||||
ts_query_out.language = @intFromPtr(language);
|
ts_query_out.language = @intFromPtr(language);
|
||||||
|
|
||||||
const query_out: *Query = @alignCast(@ptrCast(ts_query_out));
|
const query_out: *Query = @ptrCast(@alignCast(ts_query_out));
|
||||||
return .{ query_out, arena };
|
return .{ query_out, arena };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,15 @@ pub const agda = .{
|
||||||
.comment = "--",
|
.comment = "--",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const @"asm" = .{
|
||||||
|
.description = "Assembly (asm)",
|
||||||
|
.icon = "",
|
||||||
|
.extensions = .{ "s", "asm", "assembly" },
|
||||||
|
.comment = "#",
|
||||||
|
.highlights = "tree-sitter-asm/queries/asm/highlights.scm",
|
||||||
|
.injections = "tree-sitter-asm/queries/asm/injections.scm",
|
||||||
|
};
|
||||||
|
|
||||||
pub const astro = .{
|
pub const astro = .{
|
||||||
.description = "Astro",
|
.description = "Astro",
|
||||||
.icon = "",
|
.icon = "",
|
||||||
|
|
@ -17,7 +26,7 @@ pub const astro = .{
|
||||||
pub const awk = .{
|
pub const awk = .{
|
||||||
.description = "Awk",
|
.description = "Awk",
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"awk", "gawk"},
|
.extensions = .{ "awk", "gawk" },
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -45,6 +54,14 @@ pub const @"c-sharp" = .{
|
||||||
.comment = "//",
|
.comment = "//",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const comment = .{
|
||||||
|
.description = "Comment tags",
|
||||||
|
.icon = "#",
|
||||||
|
.extensions = .{},
|
||||||
|
.comment = "#",
|
||||||
|
.highlights = "nvim-treesitter/runtime/queries/comment/highlights.scm",
|
||||||
|
};
|
||||||
|
|
||||||
pub const conf = .{
|
pub const conf = .{
|
||||||
.description = "Config",
|
.description = "Config",
|
||||||
.color = 0x000000,
|
.color = 0x000000,
|
||||||
|
|
@ -96,6 +113,16 @@ pub const css = .{
|
||||||
.comment = "//",
|
.comment = "//",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const d = .{
|
||||||
|
.description = "D",
|
||||||
|
.color = 0xF54927,
|
||||||
|
.icon = "",
|
||||||
|
.extensions = .{ "d", "di" },
|
||||||
|
.comment = "//",
|
||||||
|
.highlights = "queries/d/highlights.scm",
|
||||||
|
.injections = "queries/d/injections.scm",
|
||||||
|
};
|
||||||
|
|
||||||
pub const diff = .{
|
pub const diff = .{
|
||||||
.description = "Diff",
|
.description = "Diff",
|
||||||
.extensions = .{ "diff", "patch", "rej" },
|
.extensions = .{ "diff", "patch", "rej" },
|
||||||
|
|
@ -131,7 +158,7 @@ pub const elm = .{
|
||||||
.description = "Elm",
|
.description = "Elm",
|
||||||
.color = 0x0e76ad,
|
.color = 0x0e76ad,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "elm" },
|
.extensions = .{"elm"},
|
||||||
.comment = "--",
|
.comment = "--",
|
||||||
.injections = "tree-sitter-elm/queries/injections.scm",
|
.injections = "tree-sitter-elm/queries/injections.scm",
|
||||||
};
|
};
|
||||||
|
|
@ -205,8 +232,8 @@ pub const hcl = .{
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "hcl", "tf", "tfvars" },
|
.extensions = .{ "hcl", "tf", "tfvars" },
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
.highlights = "nvim-treesitter/queries/hcl/highlights.scm",
|
.highlights = "nvim-treesitter/runtime/queries/hcl/highlights.scm",
|
||||||
.injections = "nvim-treesitter/queries/hcl/injections.scm",
|
.injections = "nvim-treesitter/runtime/queries/hcl/injections.scm",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const html = .{
|
pub const html = .{
|
||||||
|
|
@ -234,7 +261,8 @@ pub const hurl = .{
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"hurl"},
|
.extensions = .{"hurl"},
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
.injections = "tree-sitter-hurl/queries/injections.scm",
|
.highlights = "nvim-treesitter/runtime/queries/hurl/highlights.scm",
|
||||||
|
.injections = "nvim-treesitter/runtime/queries/hurl/injections.scm",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const java = .{
|
pub const java = .{
|
||||||
|
|
@ -254,6 +282,14 @@ pub const javascript = .{
|
||||||
.injections = "tree-sitter-javascript/queries/injections.scm",
|
.injections = "tree-sitter-javascript/queries/injections.scm",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const jsdoc = .{
|
||||||
|
.description = "JSDoc",
|
||||||
|
.color = 0xf0db4f,
|
||||||
|
.icon = "",
|
||||||
|
.extensions = .{},
|
||||||
|
.comment = "//",
|
||||||
|
};
|
||||||
|
|
||||||
pub const json = .{
|
pub const json = .{
|
||||||
.description = "JSON",
|
.description = "JSON",
|
||||||
.extensions = .{"json"},
|
.extensions = .{"json"},
|
||||||
|
|
@ -282,8 +318,8 @@ pub const latex = .{
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "tex", "aux", "sty", "cls" },
|
.extensions = .{ "tex", "aux", "sty", "cls" },
|
||||||
.comment = "%",
|
.comment = "%",
|
||||||
.highlights = "nvim-treesitter/queries/latex/highlights.scm",
|
.highlights = "nvim-treesitter/runtime/queries/latex/highlights.scm",
|
||||||
.injections = "nvim-treesitter/queries/latex/injections.scm",
|
.injections = "nvim-treesitter/runtime/queries/latex/injections.scm",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const commonlisp = .{
|
pub const commonlisp = .{
|
||||||
|
|
@ -292,8 +328,17 @@ pub const commonlisp = .{
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "lisp", "ls", "el" },
|
.extensions = .{ "lisp", "ls", "el" },
|
||||||
.comment = ";",
|
.comment = ";",
|
||||||
.highlights = "nvim-treesitter/queries/commonlisp/highlights.scm",
|
.highlights = "nvim-treesitter/runtime/queries/commonlisp/highlights.scm",
|
||||||
.injections = "nvim-treesitter/queries/commonlisp/injections.scm",
|
.injections = "nvim-treesitter/runtime/queries/commonlisp/injections.scm",
|
||||||
|
};
|
||||||
|
|
||||||
|
pub const llvm = .{
|
||||||
|
.description = "Llvm",
|
||||||
|
.icon = "",
|
||||||
|
.extensions = .{ "llvm", "ll" },
|
||||||
|
.comment = ";",
|
||||||
|
.highlights = "nvim-treesitter/runtime/queries/llvm/highlights.scm",
|
||||||
|
.injections = "nvim-treesitter/runtime/queries/llvm/injections.scm",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const lua = .{
|
pub const lua = .{
|
||||||
|
|
@ -311,7 +356,6 @@ pub const mail = .{
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "eml", "mbox" },
|
.extensions = .{ "eml", "mbox" },
|
||||||
.comment = ">",
|
.comment = ">",
|
||||||
.highlights = "tree-sitter-mail/queries/mail/highlights.scm",
|
|
||||||
.first_line_matches = FirstLineMatch{ .prefix = "From" },
|
.first_line_matches = FirstLineMatch{ .prefix = "From" },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -325,7 +369,7 @@ pub const markdown = .{
|
||||||
.description = "Markdown",
|
.description = "Markdown",
|
||||||
.color = 0x000000,
|
.color = 0x000000,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"md", "smd"},
|
.extensions = .{ "md", "smd" },
|
||||||
.comment = "<!--",
|
.comment = "<!--",
|
||||||
.highlights = "tree-sitter-markdown/tree-sitter-markdown/queries/highlights.scm",
|
.highlights = "tree-sitter-markdown/tree-sitter-markdown/queries/highlights.scm",
|
||||||
.injections = "tree-sitter-markdown/tree-sitter-markdown/queries/injections.scm",
|
.injections = "tree-sitter-markdown/tree-sitter-markdown/queries/injections.scm",
|
||||||
|
|
@ -342,8 +386,9 @@ pub const @"markdown-inline" = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const nasm = .{
|
pub const nasm = .{
|
||||||
.description = "Assembly Language (nasm)",
|
.description = "Assembly (nasm)",
|
||||||
.extensions = .{ "asm", "nasm" },
|
.icon = "",
|
||||||
|
.extensions = .{"nasm"},
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
.injections = "tree-sitter-nasm/queries/injections.scm",
|
.injections = "tree-sitter-nasm/queries/injections.scm",
|
||||||
};
|
};
|
||||||
|
|
@ -400,6 +445,19 @@ pub const nu = .{
|
||||||
.injections = "tree-sitter-nu/queries/nu/injections.scm",
|
.injections = "tree-sitter-nu/queries/nu/injections.scm",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const objc = .{
|
||||||
|
.description = "Objective-C",
|
||||||
|
.color = 0xE95325,
|
||||||
|
.icon = "",
|
||||||
|
.extensions = .{ "m", "objc" },
|
||||||
|
.comment = "//",
|
||||||
|
.highlights_list = .{
|
||||||
|
"tree-sitter-c/queries/highlights.scm",
|
||||||
|
"tree-sitter-objc/queries/highlights.scm",
|
||||||
|
},
|
||||||
|
.injections = "tree-sitter-objc/queries/injections.scm",
|
||||||
|
};
|
||||||
|
|
||||||
pub const ocaml = .{
|
pub const ocaml = .{
|
||||||
.description = "OCaml",
|
.description = "OCaml",
|
||||||
.color = 0xF18803,
|
.color = 0xF18803,
|
||||||
|
|
@ -435,7 +493,7 @@ pub const perl = .{
|
||||||
.description = "Perl",
|
.description = "Perl",
|
||||||
.color = 0x005c81,
|
.color = 0x005c81,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"pl", "pm", "t"},
|
.extensions = .{ "pl", "pm", "t" },
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
.injections = "tree-sitter-perl/queries/injections.scm",
|
.injections = "tree-sitter-perl/queries/injections.scm",
|
||||||
};
|
};
|
||||||
|
|
@ -504,20 +562,31 @@ pub const regex = .{
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const rpmbash = .{
|
||||||
|
.description = "RPM spec (bash)",
|
||||||
|
.color = 0xff0000,
|
||||||
|
.icon = "",
|
||||||
|
.extensions = .{},
|
||||||
|
.comment = "#",
|
||||||
|
.highlights = "tree-sitter-rpmspec/rpmbash/queries/highlights.scm",
|
||||||
|
};
|
||||||
|
|
||||||
pub const rpmspec = .{
|
pub const rpmspec = .{
|
||||||
.description = "RPM spec",
|
.description = "RPM spec",
|
||||||
.color = 0xff0000,
|
.color = 0xff0000,
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{"spec"},
|
.extensions = .{"spec"},
|
||||||
.comment = "#",
|
.comment = "#",
|
||||||
|
.highlights = "tree-sitter-rpmspec/rpmspec/queries/highlights.scm",
|
||||||
|
.injections = "tree-sitter-rpmspec/rpmspec/queries/injections.scm",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const rst = .{
|
pub const rst = .{
|
||||||
.description = "reStructuredText",
|
.description = "reStructuredText",
|
||||||
.extensions = .{"rst"},
|
.extensions = .{"rst"},
|
||||||
.comment = "..",
|
.comment = "..",
|
||||||
.highlights = "nvim-treesitter/queries/rst/highlights.scm",
|
.highlights = "nvim-treesitter/runtime/queries/rst/highlights.scm",
|
||||||
.injections = "nvim-treesitter/queries/rst/injections.scm",
|
.injections = "nvim-treesitter/runtime/queries/rst/injections.scm",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ruby = .{
|
pub const ruby = .{
|
||||||
|
|
@ -537,9 +606,17 @@ pub const rust = .{
|
||||||
.injections = "tree-sitter-rust/queries/injections.scm",
|
.injections = "tree-sitter-rust/queries/injections.scm",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const query = .{
|
||||||
|
.description = "Query (tree-sitter)",
|
||||||
|
.extensions = .{"scm"},
|
||||||
|
.comment = ";",
|
||||||
|
.highlights = "tree-sitter-query/queries/query/highlights.scm",
|
||||||
|
.injections = "tree-sitter-query/queries/query/injections.scm",
|
||||||
|
};
|
||||||
|
|
||||||
pub const scheme = .{
|
pub const scheme = .{
|
||||||
.description = "Scheme",
|
.description = "Scheme",
|
||||||
.extensions = .{ "scm", "ss" },
|
.extensions = .{ "scm", "ss", "scheme" },
|
||||||
.comment = ";",
|
.comment = ";",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -564,12 +641,12 @@ pub const swift = .{
|
||||||
.comment = "//",
|
.comment = "//",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const verilog = .{
|
pub const systemverilog = .{
|
||||||
.description = "SystemVerilog",
|
.description = "SystemVerilog",
|
||||||
.extensions = .{ "sv", "svh", "v", "vh" },
|
.extensions = .{ "sv", "svh", "v", "vh" },
|
||||||
.comment = "//",
|
.comment = "//",
|
||||||
.highlights = "nvim-treesitter/queries/verilog/highlights.scm",
|
.highlights = "nvim-treesitter/runtime/queries/systemverilog/highlights.scm",
|
||||||
.injections = "nvim-treesitter/queries/verilog/injections.scm",
|
.injections = "nvim-treesitter/runtime/queries/systemverilog/injections.scm",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const toml = .{
|
pub const toml = .{
|
||||||
|
|
@ -586,6 +663,11 @@ pub const typescript = .{
|
||||||
.icon = "",
|
.icon = "",
|
||||||
.extensions = .{ "ts", "tsx" },
|
.extensions = .{ "ts", "tsx" },
|
||||||
.comment = "//",
|
.comment = "//",
|
||||||
|
.highlights_list = .{
|
||||||
|
"tree-sitter-javascript/queries/highlights.scm",
|
||||||
|
"tree-sitter-typescript/queries/highlights.scm",
|
||||||
|
},
|
||||||
|
.injections = "tree-sitter-javascript/queries/injections.scm",
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const typst = .{
|
pub const typst = .{
|
||||||
|
|
|
||||||
282
src/syntax.zig
282
src/syntax.zig
|
|
@ -20,12 +20,30 @@ const Query = treez.Query;
|
||||||
pub const Node = treez.Node;
|
pub const Node = treez.Node;
|
||||||
|
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
|
query_cache: *QueryCache,
|
||||||
lang: *const Language,
|
lang: *const Language,
|
||||||
parser: *Parser,
|
parser: *Parser,
|
||||||
query: *Query,
|
query: *Query,
|
||||||
errors_query: *Query,
|
errors_query: *Query,
|
||||||
injections: ?*Query,
|
injections: ?*Query,
|
||||||
tree: ?*treez.Tree = null,
|
tree: ?*treez.Tree = null,
|
||||||
|
injection_list: std.ArrayListUnmanaged(Injection) = .{},
|
||||||
|
content: ?[]u8 = null,
|
||||||
|
|
||||||
|
pub const Injection = struct {
|
||||||
|
lang_name: []const u8,
|
||||||
|
file_type: FileType,
|
||||||
|
start_point: Point,
|
||||||
|
end_row: u32,
|
||||||
|
start_byte: u32,
|
||||||
|
end_byte: u32,
|
||||||
|
syntax: ?*Self = null,
|
||||||
|
|
||||||
|
fn deinit(self: *Injection, allocator: std.mem.Allocator) void {
|
||||||
|
if (self.syntax) |syn| syn.destroy();
|
||||||
|
allocator.free(self.lang_name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
pub fn create(file_type: FileType, allocator: std.mem.Allocator, query_cache: *QueryCache) !*Self {
|
pub fn create(file_type: FileType, allocator: std.mem.Allocator, query_cache: *QueryCache) !*Self {
|
||||||
const query = try query_cache.get(file_type, .highlights);
|
const query = try query_cache.get(file_type, .highlights);
|
||||||
|
|
@ -36,10 +54,13 @@ pub fn create(file_type: FileType, allocator: std.mem.Allocator, query_cache: *Q
|
||||||
errdefer if (injections) |injections_| query_cache.release(injections_, .injections);
|
errdefer if (injections) |injections_| query_cache.release(injections_, .injections);
|
||||||
const self = try allocator.create(Self);
|
const self = try allocator.create(Self);
|
||||||
errdefer allocator.destroy(self);
|
errdefer allocator.destroy(self);
|
||||||
|
const parser = try Parser.create();
|
||||||
|
errdefer parser.destroy();
|
||||||
self.* = .{
|
self.* = .{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
|
.query_cache = query_cache,
|
||||||
.lang = file_type.lang_fn() orelse std.debug.panic("tree-sitter parser function failed for language: {s}", .{file_type.name}),
|
.lang = file_type.lang_fn() orelse std.debug.panic("tree-sitter parser function failed for language: {s}", .{file_type.name}),
|
||||||
.parser = try Parser.create(),
|
.parser = parser,
|
||||||
.query = query,
|
.query = query,
|
||||||
.errors_query = errors_query,
|
.errors_query = errors_query,
|
||||||
.injections = injections,
|
.injections = injections,
|
||||||
|
|
@ -58,25 +79,42 @@ pub fn create_guess_file_type_static(allocator: std.mem.Allocator, content: []co
|
||||||
return create(file_type, allocator, query_cache);
|
return create(file_type, allocator, query_cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destroy(self: *Self, query_cache: *QueryCache) void {
|
pub fn destroy(self: *Self) void {
|
||||||
|
self.clear_injections();
|
||||||
|
self.injection_list.deinit(self.allocator);
|
||||||
|
if (self.content) |c| self.allocator.free(c);
|
||||||
if (self.tree) |tree| tree.destroy();
|
if (self.tree) |tree| tree.destroy();
|
||||||
query_cache.release(self.query, .highlights);
|
self.query_cache.release(self.query, .highlights);
|
||||||
query_cache.release(self.errors_query, .highlights);
|
self.query_cache.release(self.errors_query, .highlights);
|
||||||
if (self.injections) |injections| query_cache.release(injections, .injections);
|
if (self.injections) |injections| self.query_cache.release(injections, .injections);
|
||||||
self.parser.destroy();
|
self.parser.destroy();
|
||||||
self.allocator.destroy(self);
|
self.allocator.destroy(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reset(self: *Self) void {
|
pub fn reset(self: *Self) void {
|
||||||
|
self.clear_injections();
|
||||||
|
if (self.content) |c| self.allocator.free(c);
|
||||||
|
self.content = null;
|
||||||
if (self.tree) |tree| {
|
if (self.tree) |tree| {
|
||||||
tree.destroy();
|
tree.destroy();
|
||||||
self.tree = null;
|
self.tree = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn clear_injections(self: *Self) void {
|
||||||
|
for (self.injection_list.items) |*inj| inj.deinit(self.allocator);
|
||||||
|
self.injection_list.clearRetainingCapacity();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn refresh_full(self: *Self, content: []const u8) !void {
|
pub fn refresh_full(self: *Self, content: []const u8) !void {
|
||||||
self.reset();
|
self.clear_injections();
|
||||||
|
if (self.content) |c| self.allocator.free(c);
|
||||||
|
self.content = null;
|
||||||
|
if (self.tree) |tree| tree.destroy();
|
||||||
self.tree = try self.parser.parseString(null, content);
|
self.tree = try self.parser.parseString(null, content);
|
||||||
|
const content_copy = try self.allocator.dupe(u8, content);
|
||||||
|
self.content = content_copy;
|
||||||
|
try self.refresh_injections(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn edit(self: *Self, ed: Edit) void {
|
pub fn edit(self: *Self, ed: Edit) void {
|
||||||
|
|
@ -140,6 +178,168 @@ pub fn refresh_from_string(self: *Self, content: [:0]const u8) !void {
|
||||||
.encoding = .utf_8,
|
.encoding = .utf_8,
|
||||||
};
|
};
|
||||||
self.tree = try self.parser.parse(old_tree, input);
|
self.tree = try self.parser.parse(old_tree, input);
|
||||||
|
if (self.content) |c| self.allocator.free(c);
|
||||||
|
self.content = null;
|
||||||
|
const content_copy = try self.allocator.dupe(u8, content);
|
||||||
|
self.content = content_copy;
|
||||||
|
try self.refresh_injections(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn refresh_injections(self: *Self, content: []const u8) !void {
|
||||||
|
self.clear_injections();
|
||||||
|
|
||||||
|
const injections_query = self.injections orelse return;
|
||||||
|
const tree = self.tree orelse return;
|
||||||
|
|
||||||
|
const cursor = try Query.Cursor.create();
|
||||||
|
defer cursor.destroy();
|
||||||
|
cursor.execute(injections_query, tree.getRootNode());
|
||||||
|
|
||||||
|
while (cursor.nextMatch()) |match| {
|
||||||
|
var lang_range: ?Range = null;
|
||||||
|
var content_range: ?Range = null;
|
||||||
|
|
||||||
|
for (match.captures()) |capture| {
|
||||||
|
const name = injections_query.getCaptureNameForId(capture.id);
|
||||||
|
if (std.mem.eql(u8, name, "injection.language")) {
|
||||||
|
lang_range = capture.node.getRange();
|
||||||
|
} else if (std.mem.eql(u8, name, "injection.content")) {
|
||||||
|
content_range = capture.node.getRange();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const crange = content_range orelse continue;
|
||||||
|
|
||||||
|
const lang_name: []const u8 = if (lang_range) |lr|
|
||||||
|
extract_node_text(content, lr) orelse continue
|
||||||
|
else
|
||||||
|
get_static_injection_language(injections_query, match.pattern_index) orelse continue;
|
||||||
|
|
||||||
|
if (lang_name.len == 0) continue;
|
||||||
|
|
||||||
|
const file_type = FileType.get_by_name_static(lang_name) orelse
|
||||||
|
FileType.get_by_name_static(normalize_lang_name(lang_name)) orelse
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const start_byte = crange.start_byte;
|
||||||
|
const end_byte = crange.end_byte;
|
||||||
|
if (start_byte >= end_byte or end_byte > content.len) continue;
|
||||||
|
|
||||||
|
const lang_name_owned = try self.allocator.dupe(u8, lang_name);
|
||||||
|
errdefer self.allocator.free(lang_name_owned);
|
||||||
|
|
||||||
|
try self.injection_list.append(self.allocator, .{
|
||||||
|
.lang_name = lang_name_owned,
|
||||||
|
.file_type = file_type,
|
||||||
|
.start_point = crange.start_point,
|
||||||
|
.end_row = crange.end_point.row,
|
||||||
|
.start_byte = start_byte,
|
||||||
|
.end_byte = end_byte,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn extract_node_text(content: []const u8, range: Range) ?[]const u8 {
|
||||||
|
const s = range.start_byte;
|
||||||
|
const e = range.end_byte;
|
||||||
|
if (s >= e or e > content.len) return null;
|
||||||
|
return std.mem.trim(u8, content[s..e], &std.ascii.whitespace);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Normalize common language name aliases found in markdown
|
||||||
|
/// This should probably be in file_types
|
||||||
|
fn normalize_lang_name(name: []const u8) []const u8 {
|
||||||
|
const aliases = .{
|
||||||
|
.{ "js", "javascript" },
|
||||||
|
.{ "ts", "typescript" },
|
||||||
|
.{ "py", "python" },
|
||||||
|
.{ "rb", "ruby" },
|
||||||
|
.{ "sh", "bash" },
|
||||||
|
.{ "shell", "bash" },
|
||||||
|
.{ "zsh", "bash" },
|
||||||
|
.{ "c++", "cpp" },
|
||||||
|
.{ "cs", "c-sharp" },
|
||||||
|
.{ "csharp", "c-sharp" },
|
||||||
|
.{ "yml", "yaml" },
|
||||||
|
.{ "md", "markdown" },
|
||||||
|
.{ "rs", "rust" },
|
||||||
|
};
|
||||||
|
inline for (aliases) |alias| {
|
||||||
|
if (std.ascii.eqlIgnoreCase(name, alias[0])) return alias[1];
|
||||||
|
}
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Read a static `#set! injection.language "name"` predicate from the query's
|
||||||
|
/// internal predicate table for the given pattern index, returning the language
|
||||||
|
/// name string if found or null otherwise.
|
||||||
|
///
|
||||||
|
/// This accesses TSQuery internals via the same cast used in ts_bin_query_gen.zig
|
||||||
|
fn get_static_injection_language(query: *Query, pattern_idx: u16) ?[]const u8 {
|
||||||
|
const tss = @import("ts_serializer.zig");
|
||||||
|
const ts_query: *tss.TSQuery = @ptrCast(@alignCast(query));
|
||||||
|
|
||||||
|
const patterns = ts_query.patterns;
|
||||||
|
if (patterns.contents == null or @as(u32, pattern_idx) >= patterns.size) return null;
|
||||||
|
const pattern_arr: [*]tss.QueryPattern = @ptrCast(patterns.contents.?);
|
||||||
|
const pattern = pattern_arr[pattern_idx];
|
||||||
|
|
||||||
|
const pred_steps = ts_query.predicate_steps;
|
||||||
|
if (pred_steps.contents == null or pred_steps.size == 0) return null;
|
||||||
|
const steps_arr: [*]tss.PredicateStep = @ptrCast(pred_steps.contents.?);
|
||||||
|
|
||||||
|
const pred_values = ts_query.predicate_values;
|
||||||
|
if (pred_values.slices.contents == null or pred_values.characters.contents == null) return null;
|
||||||
|
const slices_arr: [*]tss.Slice = @ptrCast(pred_values.slices.contents.?);
|
||||||
|
const chars: [*]u8 = @ptrCast(pred_values.characters.contents.?);
|
||||||
|
|
||||||
|
// Walk the predicate steps for this pattern looking for the sequence:
|
||||||
|
// string("set!") string("injection.language") string("<name>") done
|
||||||
|
const step_start = pattern.predicate_steps.offset;
|
||||||
|
const step_end = step_start + pattern.predicate_steps.length;
|
||||||
|
|
||||||
|
var i = step_start;
|
||||||
|
while (i < step_end) {
|
||||||
|
const s = steps_arr[i];
|
||||||
|
if (s.type == .done) {
|
||||||
|
i += 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We need at least 4 steps: 3 strings + done.
|
||||||
|
if (i + 3 >= step_end) break;
|
||||||
|
|
||||||
|
const s0 = steps_arr[i];
|
||||||
|
const s1 = steps_arr[i + 1];
|
||||||
|
const s2 = steps_arr[i + 2];
|
||||||
|
const s3 = steps_arr[i + 3];
|
||||||
|
|
||||||
|
if (s0.type == .string and s1.type == .string and
|
||||||
|
s2.type == .string and s3.type == .done)
|
||||||
|
{
|
||||||
|
if (s0.value_id < pred_values.slices.size and
|
||||||
|
s1.value_id < pred_values.slices.size and
|
||||||
|
s2.value_id < pred_values.slices.size)
|
||||||
|
{
|
||||||
|
const sl0 = slices_arr[s0.value_id];
|
||||||
|
const sl1 = slices_arr[s1.value_id];
|
||||||
|
const sl2 = slices_arr[s2.value_id];
|
||||||
|
const n0 = chars[sl0.offset .. sl0.offset + sl0.length];
|
||||||
|
const n1 = chars[sl1.offset .. sl1.offset + sl1.length];
|
||||||
|
const n2 = chars[sl2.offset .. sl2.offset + sl2.length];
|
||||||
|
if (std.mem.eql(u8, n0, "set!") and
|
||||||
|
std.mem.eql(u8, n1, "injection.language"))
|
||||||
|
{
|
||||||
|
return n2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Advance past this predicate group to the next .done boundary.
|
||||||
|
while (i < step_end and steps_arr[i].type != .done) i += 1;
|
||||||
|
if (i < step_end) i += 1;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_line_begin(s: []const u8, line: usize) ?usize {
|
fn find_line_begin(s: []const u8, line: usize) ?usize {
|
||||||
|
|
@ -159,7 +359,75 @@ fn CallBack(comptime T: type) type {
|
||||||
return fn (ctx: T, sel: Range, scope: []const u8, id: u32, capture_idx: usize, node: *const Node) error{Stop}!void;
|
return fn (ctx: T, sel: Range, scope: []const u8, id: u32, capture_idx: usize, node: *const Node) error{Stop}!void;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(self: *const Self, ctx: anytype, comptime cb: CallBack(@TypeOf(ctx)), range: ?Range) !void {
|
pub fn render(self: *Self, ctx: anytype, comptime cb: CallBack(@TypeOf(ctx)), range: ?Range) !void {
|
||||||
|
try self.render_highlights_only(ctx, cb, range);
|
||||||
|
|
||||||
|
const content = self.content orelse return;
|
||||||
|
for (self.injection_list.items) |*inj| {
|
||||||
|
if (range) |r| {
|
||||||
|
if (inj.end_row < r.start_point.row) continue;
|
||||||
|
if (inj.start_point.row > r.end_point.row) continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inj.syntax == null) {
|
||||||
|
const child_content = content[inj.start_byte..inj.end_byte];
|
||||||
|
const child = try Self.create(inj.file_type, self.allocator, self.query_cache);
|
||||||
|
errdefer child.destroy();
|
||||||
|
if (child.tree) |t| t.destroy();
|
||||||
|
child.tree = try child.parser.parseString(null, child_content);
|
||||||
|
inj.syntax = child;
|
||||||
|
}
|
||||||
|
const child_syn = inj.syntax.?;
|
||||||
|
|
||||||
|
const child_range: ?Range = if (range) |r| blk: {
|
||||||
|
const child_start_row: u32 = if (r.start_point.row > inj.start_point.row)
|
||||||
|
r.start_point.row - inj.start_point.row
|
||||||
|
else
|
||||||
|
0;
|
||||||
|
const child_end_row: u32 = r.end_point.row - inj.start_point.row;
|
||||||
|
break :blk .{
|
||||||
|
.start_point = .{ .row = child_start_row, .column = 0 },
|
||||||
|
.end_point = .{ .row = child_end_row, .column = 0 },
|
||||||
|
.start_byte = 0,
|
||||||
|
.end_byte = 0,
|
||||||
|
};
|
||||||
|
} else null;
|
||||||
|
|
||||||
|
// Wrap the context to translate local ranges to document coordinates
|
||||||
|
const InjCtx = struct {
|
||||||
|
parent_ctx: @TypeOf(ctx),
|
||||||
|
inj: *const Injection,
|
||||||
|
|
||||||
|
fn translated_cb(
|
||||||
|
self_: *const @This(),
|
||||||
|
child_sel: Range,
|
||||||
|
scope: []const u8,
|
||||||
|
id: u32,
|
||||||
|
capture_idx: usize,
|
||||||
|
node: *const Node,
|
||||||
|
) error{Stop}!void {
|
||||||
|
const start_row = child_sel.start_point.row + self_.inj.start_point.row;
|
||||||
|
const end_row = child_sel.end_point.row + self_.inj.start_point.row;
|
||||||
|
const start_col = child_sel.start_point.column +
|
||||||
|
if (child_sel.start_point.row == 0) self_.inj.start_point.column else 0;
|
||||||
|
const end_col = child_sel.end_point.column +
|
||||||
|
if (child_sel.end_point.row == 0) self_.inj.start_point.column else 0;
|
||||||
|
const doc_range: Range = .{
|
||||||
|
.start_point = .{ .row = start_row, .column = start_col },
|
||||||
|
.end_point = .{ .row = end_row, .column = end_col },
|
||||||
|
.start_byte = child_sel.start_byte,
|
||||||
|
.end_byte = child_sel.end_byte,
|
||||||
|
};
|
||||||
|
try cb(self_.parent_ctx, doc_range, scope, id, capture_idx, node);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var inj_ctx: InjCtx = .{ .parent_ctx = ctx, .inj = inj };
|
||||||
|
try child_syn.render_highlights_only(&inj_ctx, InjCtx.translated_cb, child_range);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_highlights_only(self: *const Self, ctx: anytype, comptime cb: CallBack(@TypeOf(ctx)), range: ?Range) !void {
|
||||||
const cursor = try Query.Cursor.create();
|
const cursor = try Query.Cursor.create();
|
||||||
defer cursor.destroy();
|
defer cursor.destroy();
|
||||||
const tree = self.tree orelse return;
|
const tree = self.tree orelse return;
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ pub const Query = struct {
|
||||||
pub fn destroy(_: *@This()) void {}
|
pub fn destroy(_: *@This()) void {}
|
||||||
|
|
||||||
pub const Match = struct {
|
pub const Match = struct {
|
||||||
|
pattern_index: u16 = 0,
|
||||||
pub fn captures(_: *@This()) []Capture {
|
pub fn captures(_: *@This()) []Capture {
|
||||||
return &[_]Capture{};
|
return &[_]Capture{};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,10 +33,28 @@ pub fn main() anyerror!void {
|
||||||
for (file_types) |file_type| {
|
for (file_types) |file_type| {
|
||||||
const lang = file_type.lang_fn() orelse std.debug.panic("tree-sitter parser function failed for language: {s}", .{file_type.name});
|
const lang = file_type.lang_fn() orelse std.debug.panic("tree-sitter parser function failed for language: {s}", .{file_type.name});
|
||||||
|
|
||||||
|
const lang_abi = lang.getLanguageAbiVersion();
|
||||||
|
if (lang_abi < treez.TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION)
|
||||||
|
std.debug.panic("tree-sitter language '{s}' API is too old: {d} (our MIN API:{d})", .{
|
||||||
|
lang.getLanguageName(),
|
||||||
|
lang_abi,
|
||||||
|
treez.TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION,
|
||||||
|
});
|
||||||
|
if (lang_abi > treez.TREE_SITTER_LANGUAGE_VERSION)
|
||||||
|
std.debug.panic("tree-sitter language '{s}' API is too new: {d} (our API:{d})", .{
|
||||||
|
lang.getLanguageName(),
|
||||||
|
lang_abi,
|
||||||
|
treez.TREE_SITTER_LANGUAGE_VERSION,
|
||||||
|
});
|
||||||
|
|
||||||
try cbor.writeValue(writer, file_type.name);
|
try cbor.writeValue(writer, file_type.name);
|
||||||
try cbor.writeMapHeader(writer, if (file_type.injections) |_| 3 else 2);
|
try cbor.writeMapHeader(writer, if (file_type.injections) |_| 3 else 2);
|
||||||
|
|
||||||
const highlights_in = try treez.Query.create(lang, file_type.highlights);
|
var error_offset: u32 = 0;
|
||||||
|
const highlights_in = treez.Query.create(lang, file_type.highlights, &error_offset) catch |e| switch (e) {
|
||||||
|
error.InvalidLanguage => std.debug.panic("tree-sitter invalid language error: {s}", .{file_type.name}),
|
||||||
|
else => |e_| std.debug.panic("tree-sitter failed to read highlights: {s} -> {t} at pos {d}", .{ file_type.name, e_, error_offset }),
|
||||||
|
};
|
||||||
const ts_highlights_in: *tss.TSQuery = @ptrCast(@alignCast(highlights_in));
|
const ts_highlights_in: *tss.TSQuery = @ptrCast(@alignCast(highlights_in));
|
||||||
|
|
||||||
const highlights_cb = try tss.toCbor(ts_highlights_in, allocator);
|
const highlights_cb = try tss.toCbor(ts_highlights_in, allocator);
|
||||||
|
|
@ -47,7 +65,7 @@ pub fn main() anyerror!void {
|
||||||
if (verbose)
|
if (verbose)
|
||||||
std.log.info("file_type {s} highlights {d} bytes", .{ file_type.name, highlights_cb.len });
|
std.log.info("file_type {s} highlights {d} bytes", .{ file_type.name, highlights_cb.len });
|
||||||
|
|
||||||
const errors_in = try treez.Query.create(lang, "(ERROR) @error");
|
const errors_in = try treez.Query.create(lang, "(ERROR) @error", &error_offset);
|
||||||
const ts_errors_in: *tss.TSQuery = @ptrCast(@alignCast(errors_in));
|
const ts_errors_in: *tss.TSQuery = @ptrCast(@alignCast(errors_in));
|
||||||
|
|
||||||
const errors_cb = try tss.toCbor(ts_errors_in, allocator);
|
const errors_cb = try tss.toCbor(ts_errors_in, allocator);
|
||||||
|
|
@ -59,7 +77,10 @@ pub fn main() anyerror!void {
|
||||||
std.log.info("file_type {s} errors {d} bytes", .{ file_type.name, errors_cb.len });
|
std.log.info("file_type {s} errors {d} bytes", .{ file_type.name, errors_cb.len });
|
||||||
|
|
||||||
if (file_type.injections) |injections| {
|
if (file_type.injections) |injections| {
|
||||||
const injections_in = try treez.Query.create(lang, injections);
|
const injections_in = treez.Query.create(lang, injections, &error_offset) catch |e| switch (e) {
|
||||||
|
error.InvalidLanguage => std.debug.panic("tree-sitter invalid language error: {s}", .{file_type.name}),
|
||||||
|
else => |e_| std.debug.panic("tree-sitter failed to read injections: {s} -> {t} at pos {d}", .{ file_type.name, e_, error_offset }),
|
||||||
|
};
|
||||||
const ts_injections_in: *tss.TSQuery = @ptrCast(@alignCast(injections_in));
|
const ts_injections_in: *tss.TSQuery = @ptrCast(@alignCast(injections_in));
|
||||||
|
|
||||||
const injections_cb = try tss.toCbor(ts_injections_in, allocator);
|
const injections_cb = try tss.toCbor(ts_injections_in, allocator);
|
||||||
|
|
|
||||||
|
|
@ -171,11 +171,12 @@ pub const QueryStep = extern struct {
|
||||||
// is_last_child: u1,
|
// is_last_child: u1,
|
||||||
// is_pass_through: u1,
|
// is_pass_through: u1,
|
||||||
// is_dead_end: u1,
|
// is_dead_end: u1,
|
||||||
// alternative_is_immediate: u1,
|
// is_inside_alternation: u1,
|
||||||
// contains_captures: u1,
|
// contains_captures: u1,
|
||||||
// root_pattern_guaranteed: u1,
|
// root_pattern_guaranteed: u1,
|
||||||
flags8: u8,
|
flags8: u8,
|
||||||
// parent_pattern_guaranteed: u1,
|
// parent_pattern_guaranteed: u1,
|
||||||
|
// is_missing: u1,
|
||||||
flags16: u8,
|
flags16: u8,
|
||||||
|
|
||||||
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
|
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue