update to Zig 0.15.0
This commit is contained in:
parent
167a588dee
commit
81e397b06c
3 changed files with 29 additions and 26 deletions
|
@ -2,7 +2,7 @@
|
|||
.name = .flow_syntax,
|
||||
.version = "0.1.0",
|
||||
.fingerprint = 0x3ba2584ea1cec85f,
|
||||
.minimum_zig_version = "0.15.0-dev.1048+f43f89a70",
|
||||
.minimum_zig_version = "0.15.0",
|
||||
|
||||
.dependencies = .{
|
||||
.tree_sitter = .{
|
||||
|
@ -10,8 +10,8 @@
|
|||
.hash = "tree_sitter-0.22.4-150-g7e3f5726-z0LhyN88UicDHlr22vQnOZ3DW9NWN1gOhDwLuCRXvrh2",
|
||||
},
|
||||
.cbor = .{
|
||||
.url = "git+https://github.com/neurocyte/cbor#6eccce0b984296e7d05c20d83933cb31530e4fac",
|
||||
.hash = "cbor-1.0.0-RcQE_N3yAADXjbyvhsmTQ6lf22l1nYgePq5FT8NaC4ic",
|
||||
.url = "git+https://github.com/neurocyte/cbor?ref=master#0708420594f5af0a8289e6e1bae0ae03f011731f",
|
||||
.hash = "cbor-1.0.0-RcQE_CUwAQChkeU-LO-eTSbLAdRox-wuxUGmi2nDAWri",
|
||||
},
|
||||
},
|
||||
.paths = .{
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue