Compare commits

...
Sign in to create a new pull request.

25 commits

Author SHA1 Message Date
6cedbcb362
fix: bitrot building with -Duse_tree_sitter=false 2025-11-06 14:12:36 +01:00
1624276f9c
fix: .zon version field 2025-11-06 14:07:48 +01:00
10b92330cf
feat: add reStructuredText file type 2025-11-04 17:15:42 +01:00
Anthon van der Neut
a2356a459e Correct shortened ziggy schema extension
4353b20ef2/src/cli/fmt.zig (L139)
2025-11-02 18:04:36 +01:00
9106b13b4c
fix: add smd extention to the markdown file type 2025-10-15 11:29:58 +02:00
45d79d4156
feat: update tree-sitter for newer rust grammar 2025-10-10 09:10:06 +02:00
35c356a867
fix: add missing verilog file extensions 2025-10-10 08:49:27 +02:00
7dad2163a4
Merge branch 'zig-0.14' 2025-09-29 21:31:07 +02:00
2a74de8f73
Merge branch 'zig-0.14' 2025-09-29 20:58:06 +02:00
0221af1286
fix: update tree-sitter to fix paths 2025-09-29 18:10:07 +02:00
fa2685056c
Merge branch 'zig-0.14' 2025-09-29 16:40:36 +02:00
c7eb09f145
feat: update tree-sitter for new file types 2025-09-29 16:38:56 +02:00
05938cb025
fix: update tree-sitter to fix zig-0.15 build 2025-09-25 15:45:08 +02:00
4c0218f805
fix: update tree-sitter to fix missing package paths 2025-09-13 16:28:14 +02:00
6404532851
Merge branch 'zig-0.14' 2025-09-11 10:43:34 +02:00
789f049207
Merge branch 'zig-0.14' 2025-09-11 09:52:16 +02:00
ed50776aae
Merge branch 'zig-0.14' 2025-08-23 17:20:42 +02:00
2c28091fe5
Merge branch 'zig-0.14' 2025-08-21 10:41:23 +02:00
Loris Cro
81e397b06c update to Zig 0.15.0 2025-08-20 21:30:15 +02:00
Loris Cro
167a588dee update to zig 0.15.0-dev.1048+f43f89a70 2025-07-17 11:59:24 +02:00
d71afb5db8 Merge branch 'master' into zig-0.15.0 2025-07-15 18:41:19 +02:00
3c72f6596a build: update flow-syntax for 0.15.0-dev.1034+bd97b6618 2025-07-15 17:00:06 +02:00
4c42ede5ea Merge branch 'master' into zig-0.15.0 2025-07-15 13:17:43 +02:00
33dafaa516 Merge branch 'master' into zig-0.15.0 2025-07-14 21:17:08 +02:00
6197895864 build: update to zig-0.15.0-dev.936+fc2c1883b
The last pre-writergate version.
2025-07-14 20:56:11 +02:00
8 changed files with 60 additions and 46 deletions

View file

@ -14,10 +14,7 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
});
const tree_sitter_host_dep = b.dependency("tree_sitter", .{
.target = b.graph.host,
.optimize = optimize,
});
const tree_sitter_host_dep = b.dependency("tree_sitter", .{});
const cbor_dep = b.dependency("cbor", .{
.target = target,
@ -26,8 +23,11 @@ pub fn build(b: *std.Build) void {
const ts_bin_query_gen = b.addExecutable(.{
.name = "ts_bin_query_gen",
.target = b.graph.host,
.root_source_file = b.path("src/ts_bin_query_gen.zig"),
.root_module = b.createModule(.{
.root_source_file = b.path("src/ts_bin_query_gen.zig"),
.target = b.graph.host,
.optimize = .Debug,
}),
});
ts_bin_query_gen.linkLibC();
ts_bin_query_gen.root_module.addImport("cbor", cbor_dep.module("cbor"));
@ -110,6 +110,7 @@ pub fn build(b: *std.Build) void {
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/queries/latex/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/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, "tree-sitter-astro/queries/injections.scm");
@ -148,6 +149,7 @@ pub fn build(b: *std.Build) void {
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/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/queries/rst/injections.scm");
const syntax_mod = b.addModule("syntax", .{
.root_source_file = b.path("src/syntax.zig"),

View file

@ -1,17 +1,17 @@
.{
.name = .flow_syntax,
.version = "0.1.0",
.version = "0.6.0",
.fingerprint = 0x3ba2584ea1cec85f,
.minimum_zig_version = "0.14.1",
.minimum_zig_version = "0.15.0",
.dependencies = .{
.tree_sitter = .{
.url = "https://github.com/neurocyte/tree-sitter/releases/download/zig-0.14-36eca46fdfe00a53056c8d84e1628f55a25048bb/source.tar.gz",
.hash = "N-V-__8AAMF_rS6BaLxN8oA8RJ8DUNN8xZr5718FlLxN-fFO",
.url = "https://github.com/neurocyte/tree-sitter/releases/download/master-3cfb01c2f3349791a500f59bcc89b867d017d5b8/source.tar.gz",
.hash = "tree_sitter-0.22.4-150-g7e3f5726-z0LhyI7XuS7mSbx26jCz5VkJ_c1oL8vvC6WBgx0Idkpg",
},
.cbor = .{
.url = "https://github.com/neurocyte/cbor/archive/1fccb83c70cd84e1dff57cc53f7db8fb99909a94.tar.gz",
.hash = "cbor-1.0.0-RcQE_HvqAACcrLH7t3IDZOshgY2xqJA_UX330MvwSepb",
.url = "git+https://github.com/neurocyte/cbor?ref=master#7d2eeb68c8a2fb3f4d6baad6cc04c521b92974c0",
.hash = "cbor-1.0.0-RcQE_AswAQAPlqBCZXYQf9DZXn-0Ubt8Mk03ZcJWcsAG",
},
},
.paths = .{

View file

@ -85,7 +85,7 @@ fn ft_func_name(comptime lang: []const u8) []const u8 {
return &func_name;
}
pub const LangFn = *const fn () callconv(.C) ?*const treez.Language;
pub const LangFn = *const fn () callconv(.c) ?*const treez.Language;
pub const FirstLineMatch = struct {
prefix: ?[]const u8 = null,

View file

@ -325,7 +325,7 @@ pub const markdown = .{
.description = "Markdown",
.color = 0x000000,
.icon = "󰍔",
.extensions = .{"md"},
.extensions = .{"md", "smd"},
.comment = "<!--",
.highlights = "tree-sitter-markdown/tree-sitter-markdown/queries/highlights.scm",
.injections = "tree-sitter-markdown/tree-sitter-markdown/queries/injections.scm",
@ -512,6 +512,14 @@ pub const rpmspec = .{
.comment = "#",
};
pub const rst = .{
.description = "reStructuredText",
.extensions = .{"rst"},
.comment = "..",
.highlights = "nvim-treesitter/queries/rst/highlights.scm",
.injections = "nvim-treesitter/queries/rst/injections.scm",
};
pub const ruby = .{
.description = "Ruby",
.color = 0xd91404,
@ -558,7 +566,7 @@ pub const swift = .{
pub const verilog = .{
.description = "SystemVerilog",
.extensions = .{ "sv", "svh" },
.extensions = .{ "sv", "svh", "v", "vh" },
.comment = "//",
.highlights = "nvim-treesitter/queries/verilog/highlights.scm",
.injections = "nvim-treesitter/queries/verilog/injections.scm",
@ -646,7 +654,7 @@ pub const @"ziggy-schema" = .{
.description = "Ziggy (schema)",
.color = 0xf7a41d,
.icon = "",
.extensions = .{ "ziggy-schema", "zyg-schema" },
.extensions = .{ "ziggy-schema", "zgy-schema" },
.comment = "//",
.highlights = "tree-sitter-ziggy/tree-sitter-ziggy-schema/queries/highlights.scm",
};

View file

@ -48,12 +48,12 @@ pub fn create(file_type: FileType, allocator: std.mem.Allocator, query_cache: *Q
return self;
}
pub fn static_create_file_type(allocator: std.mem.Allocator, lang_name: []const u8, query_cache: *QueryCache) !*Self {
pub fn create_file_type_static(allocator: std.mem.Allocator, lang_name: []const u8, query_cache: *QueryCache) !*Self {
const file_type = FileType.get_by_name_static(lang_name) orelse return error.NotFound;
return create(file_type, allocator, query_cache);
}
pub fn static_create_guess_file_type_static(allocator: std.mem.Allocator, content: []const u8, file_path: ?[]const u8, query_cache: *QueryCache) !*Self {
pub fn create_guess_file_type_static(allocator: std.mem.Allocator, content: []const u8, file_path: ?[]const u8, query_cache: *QueryCache) !*Self {
const file_type = FileType.guess_static(file_path, content) orelse return error.NotFound;
return create(file_type, allocator, query_cache);
}
@ -102,7 +102,7 @@ pub fn refresh_from_buffer(self: *Self, buffer: anytype, metrics: anytype) !void
const input: Input = .{
.payload = &state,
.read = struct {
fn read(payload: ?*anyopaque, _: u32, position: treez.Point, bytes_read: *u32) callconv(.C) [*:0]const u8 {
fn read(payload: ?*anyopaque, _: u32, position: treez.Point, bytes_read: *u32) callconv(.c) [*:0]const u8 {
const ctx: *State = @ptrCast(@alignCast(payload orelse return ""));
const result = ctx.buffer.get_from_pos(.{ .row = position.row, .col = position.column }, &ctx.result_buf, ctx.metrics);
bytes_read.* = @intCast(result.len);
@ -128,7 +128,7 @@ pub fn refresh_from_string(self: *Self, content: [:0]const u8) !void {
const input: Input = .{
.payload = &state,
.read = struct {
fn read(payload: ?*anyopaque, _: u32, position: treez.Point, bytes_read: *u32) callconv(.C) [*:0]const u8 {
fn read(payload: ?*anyopaque, _: u32, position: treez.Point, bytes_read: *u32) callconv(.c) [*:0]const u8 {
bytes_read.* = 0;
const ctx: *State = @ptrCast(@alignCast(payload orelse return ""));
const pos = (find_line_begin(ctx.content, position.row) orelse return "") + position.column;

View file

@ -23,12 +23,12 @@ pub const InputEncoding = enum(c_uint) {
};
pub const Input = extern struct {
payload: ?*anyopaque,
read: ?*const fn (payload: ?*anyopaque, byte_index: u32, position: Point, bytes_read: *u32) callconv(.C) [*:0]const u8,
read: ?*const fn (payload: ?*anyopaque, byte_index: u32, position: Point, bytes_read: *u32) callconv(.c) [*:0]const u8,
encoding: InputEncoding,
};
pub const Language = struct {
var dummy: @This() = .{};
pub fn LangFn() callconv(.C) ?*const Language {
pub fn LangFn() callconv(.c) ?*const Language {
return &dummy;
}
};
@ -87,6 +87,7 @@ pub const Tree = struct {
pub fn edit(_: *Tree, _: *const InputEdit) void {}
};
pub const Node = struct {
tree: ?*Tree = null,
var dummy: @This() = .{};
pub fn getRange(_: *const @This()) Range {
return .{};

View file

@ -25,9 +25,8 @@ pub fn main() anyerror!void {
};
defer output_file.close();
var output = std.ArrayList(u8).init(allocator);
defer output.deinit();
const writer = output.writer();
var output = std.Io.Writer.Allocating.init(allocator);
const writer = &output.writer;
try cbor.writeMapHeader(writer, file_types.len);
@ -38,7 +37,7 @@ pub fn main() anyerror!void {
try cbor.writeMapHeader(writer, if (file_type.injections) |_| 3 else 2);
const highlights_in = try treez.Query.create(lang, file_type.highlights);
const ts_highlights_in: *tss.TSQuery = @alignCast(@ptrCast(highlights_in));
const ts_highlights_in: *tss.TSQuery = @ptrCast(@alignCast(highlights_in));
const highlights_cb = try tss.toCbor(ts_highlights_in, allocator);
defer allocator.free(highlights_cb);
@ -49,7 +48,7 @@ pub fn main() anyerror!void {
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 ts_errors_in: *tss.TSQuery = @alignCast(@ptrCast(errors_in));
const ts_errors_in: *tss.TSQuery = @ptrCast(@alignCast(errors_in));
const errors_cb = try tss.toCbor(ts_errors_in, allocator);
defer allocator.free(errors_cb);
@ -61,7 +60,7 @@ pub fn main() anyerror!void {
if (file_type.injections) |injections| {
const injections_in = try treez.Query.create(lang, injections);
const ts_injections_in: *tss.TSQuery = @alignCast(@ptrCast(injections_in));
const ts_injections_in: *tss.TSQuery = @ptrCast(@alignCast(injections_in));
const injections_cb = try tss.toCbor(ts_injections_in, allocator);
defer allocator.free(injections_cb);
@ -73,9 +72,9 @@ pub fn main() anyerror!void {
}
}
try output_file.writeAll(output.items);
try output_file.writeAll(output.written());
if (verbose)
std.log.info("file_types total {d} bytes", .{output.items.len});
std.log.info("file_types total {d} bytes", .{output.written().len});
}
fn fatal(comptime format: []const u8, args: anytype) noreturn {
@ -91,7 +90,7 @@ const FileType = struct {
highlights: [:0]const u8,
injections: ?[:0]const u8,
};
const LangFn = *const fn () callconv(.C) ?*const treez.Language;
const LangFn = *const fn () callconv(.c) ?*const treez.Language;
fn load_file_types(comptime Namespace: type) []const FileType {
comptime switch (@typeInfo(Namespace)) {

View file

@ -5,6 +5,7 @@
/// Yes,... it is not a public API! Here be dragons!
///
const std = @import("std");
const Io = std.Io;
const cbor = @import("cbor");
const build_options = @import("build_options");
const treez = if (build_options.use_tree_sitter) @import("treez") else @import("treez_dummy.zig");
@ -13,7 +14,7 @@ pub const Slice = extern struct {
offset: u32,
length: u32,
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
return cbor.writeArray(writer, self.*);
}
@ -31,7 +32,7 @@ pub fn Array(T: type) type {
size: u32,
capacity: u32,
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
if (self.contents) |contents| {
const arr: []T = @as([*]T, @ptrCast(contents))[0..self.size];
try cbor.writeValue(writer, arr);
@ -53,7 +54,7 @@ pub fn Array(T: type) type {
if (T == u8) {
var arr: []const u8 = undefined;
if (try cbor.matchValue(iter, cbor.extract(&arr))) {
self.contents = @constCast(@ptrCast(arr.ptr));
self.contents = @ptrCast(@constCast(arr.ptr));
self.size = @intCast(arr.len);
self.capacity = @intCast(arr.len);
return true;
@ -74,7 +75,7 @@ pub fn Array(T: type) type {
}
i += 1;
}
self.contents = @constCast(@ptrCast(arr.ptr));
self.contents = @ptrCast(@constCast(arr.ptr));
self.size = @intCast(arr.len);
self.capacity = @intCast(arr.len);
return true;
@ -86,7 +87,7 @@ pub const SymbolTable = extern struct {
characters: Array(u8),
slices: Array(Slice),
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
return cbor.writeArray(writer, self.*);
}
@ -103,7 +104,7 @@ pub const PatternEntry = extern struct {
pattern_index: u16,
is_rooted: bool,
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
return cbor.writeArray(writer, self.*);
}
@ -122,7 +123,7 @@ pub const QueryPattern = extern struct {
end_byte: u32,
is_non_local: bool,
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
return cbor.writeArray(writer, self.*);
}
@ -140,7 +141,7 @@ pub const StepOffset = extern struct {
byte_offset: u32,
step_index: u16,
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
return cbor.writeArray(writer, self.*);
}
@ -177,7 +178,7 @@ pub const QueryStep = extern struct {
// parent_pattern_guaranteed: u1,
flags16: u8,
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
return cbor.writeArray(writer, self.*);
}
@ -206,7 +207,7 @@ pub const PredicateStep = extern struct {
type: Type,
value_id: u32,
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
return cbor.writeArray(writer, self.*);
}
@ -234,7 +235,7 @@ pub const TSQuery = extern struct {
// language: ?*const treez.Language,
wildcard_root_pattern_count: u16,
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
return cbor.writeArray(writer, self.*);
}
@ -262,13 +263,14 @@ pub const TSQuery = extern struct {
pub const SerializeError = error{OutOfMemory};
pub fn toCbor(query: *TSQuery, allocator: std.mem.Allocator) SerializeError![]const u8 {
var cb: std.ArrayListUnmanaged(u8) = .empty;
defer cb.deinit(allocator);
try cbor.writeValue(cb.writer(allocator), query.*);
return cb.toOwnedSlice(allocator);
var cb: Io.Writer.Allocating = .init(allocator);
defer cb.deinit();
cbor.writeValue(&cb.writer, query.*) catch return error.OutOfMemory;
return cb.toOwnedSlice();
}
pub const DeserializeError = error{
WriteFailed,
OutOfMemory,
IntegerTooLarge,
IntegerTooSmall,
@ -277,6 +279,8 @@ pub const DeserializeError = error{
InvalidFloatType,
InvalidArrayType,
InvalidPIntType,
InvalidMapType,
InvalidUnion,
JsonIncompatibleType,
InvalidQueryCbor,
NotAnObject,