Compare commits
No commits in common. "master" and "zig-0.14" have entirely different histories.
8 changed files with 46 additions and 60 deletions
14
build.zig
14
build.zig
|
|
@ -14,7 +14,10 @@ pub fn build(b: *std.Build) void {
|
|||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const tree_sitter_host_dep = b.dependency("tree_sitter", .{});
|
||||
const tree_sitter_host_dep = b.dependency("tree_sitter", .{
|
||||
.target = b.graph.host,
|
||||
.optimize = optimize,
|
||||
});
|
||||
|
||||
const cbor_dep = b.dependency("cbor", .{
|
||||
.target = target,
|
||||
|
|
@ -23,11 +26,8 @@ pub fn build(b: *std.Build) void {
|
|||
|
||||
const ts_bin_query_gen = b.addExecutable(.{
|
||||
.name = "ts_bin_query_gen",
|
||||
.root_module = b.createModule(.{
|
||||
.root_source_file = b.path("src/ts_bin_query_gen.zig"),
|
||||
.target = b.graph.host,
|
||||
.optimize = .Debug,
|
||||
}),
|
||||
.target = b.graph.host,
|
||||
.root_source_file = b.path("src/ts_bin_query_gen.zig"),
|
||||
});
|
||||
ts_bin_query_gen.linkLibC();
|
||||
ts_bin_query_gen.root_module.addImport("cbor", cbor_dep.module("cbor"));
|
||||
|
|
@ -110,7 +110,6 @@ 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");
|
||||
|
|
@ -149,7 +148,6 @@ 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"),
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
.{
|
||||
.name = .flow_syntax,
|
||||
.version = "0.6.0",
|
||||
.version = "0.1.0",
|
||||
.fingerprint = 0x3ba2584ea1cec85f,
|
||||
.minimum_zig_version = "0.15.0",
|
||||
.minimum_zig_version = "0.14.1",
|
||||
|
||||
.dependencies = .{
|
||||
.tree_sitter = .{
|
||||
.url = "https://github.com/neurocyte/tree-sitter/releases/download/master-3cfb01c2f3349791a500f59bcc89b867d017d5b8/source.tar.gz",
|
||||
.hash = "tree_sitter-0.22.4-150-g7e3f5726-z0LhyI7XuS7mSbx26jCz5VkJ_c1oL8vvC6WBgx0Idkpg",
|
||||
.url = "https://github.com/neurocyte/tree-sitter/releases/download/zig-0.14-36eca46fdfe00a53056c8d84e1628f55a25048bb/source.tar.gz",
|
||||
.hash = "N-V-__8AAMF_rS6BaLxN8oA8RJ8DUNN8xZr5718FlLxN-fFO",
|
||||
},
|
||||
.cbor = .{
|
||||
.url = "git+https://github.com/neurocyte/cbor?ref=master#7d2eeb68c8a2fb3f4d6baad6cc04c521b92974c0",
|
||||
.hash = "cbor-1.0.0-RcQE_AswAQAPlqBCZXYQf9DZXn-0Ubt8Mk03ZcJWcsAG",
|
||||
.url = "https://github.com/neurocyte/cbor/archive/1fccb83c70cd84e1dff57cc53f7db8fb99909a94.tar.gz",
|
||||
.hash = "cbor-1.0.0-RcQE_HvqAACcrLH7t3IDZOshgY2xqJA_UX330MvwSepb",
|
||||
},
|
||||
},
|
||||
.paths = .{
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -325,7 +325,7 @@ pub const markdown = .{
|
|||
.description = "Markdown",
|
||||
.color = 0x000000,
|
||||
.icon = "",
|
||||
.extensions = .{"md", "smd"},
|
||||
.extensions = .{"md"},
|
||||
.comment = "<!--",
|
||||
.highlights = "tree-sitter-markdown/tree-sitter-markdown/queries/highlights.scm",
|
||||
.injections = "tree-sitter-markdown/tree-sitter-markdown/queries/injections.scm",
|
||||
|
|
@ -512,14 +512,6 @@ 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,
|
||||
|
|
@ -566,7 +558,7 @@ pub const swift = .{
|
|||
|
||||
pub const verilog = .{
|
||||
.description = "SystemVerilog",
|
||||
.extensions = .{ "sv", "svh", "v", "vh" },
|
||||
.extensions = .{ "sv", "svh" },
|
||||
.comment = "//",
|
||||
.highlights = "nvim-treesitter/queries/verilog/highlights.scm",
|
||||
.injections = "nvim-treesitter/queries/verilog/injections.scm",
|
||||
|
|
@ -654,7 +646,7 @@ pub const @"ziggy-schema" = .{
|
|||
.description = "Ziggy (schema)",
|
||||
.color = 0xf7a41d,
|
||||
.icon = "",
|
||||
.extensions = .{ "ziggy-schema", "zgy-schema" },
|
||||
.extensions = .{ "ziggy-schema", "zyg-schema" },
|
||||
.comment = "//",
|
||||
.highlights = "tree-sitter-ziggy/tree-sitter-ziggy-schema/queries/highlights.scm",
|
||||
};
|
||||
|
|
|
|||
|
|
@ -48,12 +48,12 @@ pub fn create(file_type: FileType, allocator: std.mem.Allocator, query_cache: *Q
|
|||
return self;
|
||||
}
|
||||
|
||||
pub fn create_file_type_static(allocator: std.mem.Allocator, lang_name: []const u8, query_cache: *QueryCache) !*Self {
|
||||
pub fn static_create_file_type(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 create_guess_file_type_static(allocator: std.mem.Allocator, content: []const u8, file_path: ?[]const u8, query_cache: *QueryCache) !*Self {
|
||||
pub fn static_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;
|
||||
|
|
|
|||
|
|
@ -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,7 +87,6 @@ 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 .{};
|
||||
|
|
|
|||
|
|
@ -25,8 +25,9 @@ pub fn main() anyerror!void {
|
|||
};
|
||||
defer output_file.close();
|
||||
|
||||
var output = std.Io.Writer.Allocating.init(allocator);
|
||||
const writer = &output.writer;
|
||||
var output = std.ArrayList(u8).init(allocator);
|
||||
defer output.deinit();
|
||||
const writer = output.writer();
|
||||
|
||||
try cbor.writeMapHeader(writer, file_types.len);
|
||||
|
||||
|
|
@ -37,7 +38,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 = @ptrCast(@alignCast(highlights_in));
|
||||
const ts_highlights_in: *tss.TSQuery = @alignCast(@ptrCast(highlights_in));
|
||||
|
||||
const highlights_cb = try tss.toCbor(ts_highlights_in, allocator);
|
||||
defer allocator.free(highlights_cb);
|
||||
|
|
@ -48,7 +49,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 = @ptrCast(@alignCast(errors_in));
|
||||
const ts_errors_in: *tss.TSQuery = @alignCast(@ptrCast(errors_in));
|
||||
|
||||
const errors_cb = try tss.toCbor(ts_errors_in, allocator);
|
||||
defer allocator.free(errors_cb);
|
||||
|
|
@ -60,7 +61,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 = @ptrCast(@alignCast(injections_in));
|
||||
const ts_injections_in: *tss.TSQuery = @alignCast(@ptrCast(injections_in));
|
||||
|
||||
const injections_cb = try tss.toCbor(ts_injections_in, allocator);
|
||||
defer allocator.free(injections_cb);
|
||||
|
|
@ -72,9 +73,9 @@ pub fn main() anyerror!void {
|
|||
}
|
||||
}
|
||||
|
||||
try output_file.writeAll(output.written());
|
||||
try output_file.writeAll(output.items);
|
||||
if (verbose)
|
||||
std.log.info("file_types total {d} bytes", .{output.written().len});
|
||||
std.log.info("file_types total {d} bytes", .{output.items.len});
|
||||
}
|
||||
|
||||
fn fatal(comptime format: []const u8, args: anytype) noreturn {
|
||||
|
|
@ -90,7 +91,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)) {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
/// 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");
|
||||
|
|
@ -14,7 +13,7 @@ pub const Slice = extern struct {
|
|||
offset: u32,
|
||||
length: u32,
|
||||
|
||||
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
|
||||
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
|
||||
return cbor.writeArray(writer, self.*);
|
||||
}
|
||||
|
||||
|
|
@ -32,7 +31,7 @@ pub fn Array(T: type) type {
|
|||
size: u32,
|
||||
capacity: u32,
|
||||
|
||||
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
|
||||
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
|
||||
if (self.contents) |contents| {
|
||||
const arr: []T = @as([*]T, @ptrCast(contents))[0..self.size];
|
||||
try cbor.writeValue(writer, arr);
|
||||
|
|
@ -54,7 +53,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 = @ptrCast(@constCast(arr.ptr));
|
||||
self.contents = @constCast(@ptrCast(arr.ptr));
|
||||
self.size = @intCast(arr.len);
|
||||
self.capacity = @intCast(arr.len);
|
||||
return true;
|
||||
|
|
@ -75,7 +74,7 @@ pub fn Array(T: type) type {
|
|||
}
|
||||
i += 1;
|
||||
}
|
||||
self.contents = @ptrCast(@constCast(arr.ptr));
|
||||
self.contents = @constCast(@ptrCast(arr.ptr));
|
||||
self.size = @intCast(arr.len);
|
||||
self.capacity = @intCast(arr.len);
|
||||
return true;
|
||||
|
|
@ -87,7 +86,7 @@ pub const SymbolTable = extern struct {
|
|||
characters: Array(u8),
|
||||
slices: Array(Slice),
|
||||
|
||||
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
|
||||
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
|
||||
return cbor.writeArray(writer, self.*);
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +103,7 @@ pub const PatternEntry = extern struct {
|
|||
pattern_index: u16,
|
||||
is_rooted: bool,
|
||||
|
||||
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
|
||||
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
|
||||
return cbor.writeArray(writer, self.*);
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +122,7 @@ pub const QueryPattern = extern struct {
|
|||
end_byte: u32,
|
||||
is_non_local: bool,
|
||||
|
||||
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
|
||||
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
|
||||
return cbor.writeArray(writer, self.*);
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +140,7 @@ pub const StepOffset = extern struct {
|
|||
byte_offset: u32,
|
||||
step_index: u16,
|
||||
|
||||
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
|
||||
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
|
||||
return cbor.writeArray(writer, self.*);
|
||||
}
|
||||
|
||||
|
|
@ -178,7 +177,7 @@ pub const QueryStep = extern struct {
|
|||
// parent_pattern_guaranteed: u1,
|
||||
flags16: u8,
|
||||
|
||||
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
|
||||
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
|
||||
return cbor.writeArray(writer, self.*);
|
||||
}
|
||||
|
||||
|
|
@ -207,7 +206,7 @@ pub const PredicateStep = extern struct {
|
|||
type: Type,
|
||||
value_id: u32,
|
||||
|
||||
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
|
||||
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
|
||||
return cbor.writeArray(writer, self.*);
|
||||
}
|
||||
|
||||
|
|
@ -235,7 +234,7 @@ pub const TSQuery = extern struct {
|
|||
// language: ?*const treez.Language,
|
||||
wildcard_root_pattern_count: u16,
|
||||
|
||||
pub fn cborEncode(self: *const @This(), writer: *Io.Writer) !void {
|
||||
pub fn cborEncode(self: *const @This(), writer: anytype) !void {
|
||||
return cbor.writeArray(writer, self.*);
|
||||
}
|
||||
|
||||
|
|
@ -263,14 +262,13 @@ pub const TSQuery = extern struct {
|
|||
pub const SerializeError = error{OutOfMemory};
|
||||
|
||||
pub fn toCbor(query: *TSQuery, allocator: std.mem.Allocator) SerializeError![]const u8 {
|
||||
var cb: Io.Writer.Allocating = .init(allocator);
|
||||
defer cb.deinit();
|
||||
cbor.writeValue(&cb.writer, query.*) catch return error.OutOfMemory;
|
||||
return cb.toOwnedSlice();
|
||||
var cb: std.ArrayListUnmanaged(u8) = .empty;
|
||||
defer cb.deinit(allocator);
|
||||
try cbor.writeValue(cb.writer(allocator), query.*);
|
||||
return cb.toOwnedSlice(allocator);
|
||||
}
|
||||
|
||||
pub const DeserializeError = error{
|
||||
WriteFailed,
|
||||
OutOfMemory,
|
||||
IntegerTooLarge,
|
||||
IntegerTooSmall,
|
||||
|
|
@ -279,8 +277,6 @@ pub const DeserializeError = error{
|
|||
InvalidFloatType,
|
||||
InvalidArrayType,
|
||||
InvalidPIntType,
|
||||
InvalidMapType,
|
||||
InvalidUnion,
|
||||
JsonIncompatibleType,
|
||||
InvalidQueryCbor,
|
||||
NotAnObject,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue