feat: update flow-syntax
This commit is contained in:
parent
ebccd70d7d
commit
7ee2cb5ba3
2 changed files with 13 additions and 10 deletions
|
@ -12,8 +12,8 @@
|
||||||
.hash = "N-V-__8AAJiAIgDMVIi8CRb_xko9_qVQ-UiQzd5FTBBr0aPa",
|
.hash = "N-V-__8AAJiAIgDMVIi8CRb_xko9_qVQ-UiQzd5FTBBr0aPa",
|
||||||
},
|
},
|
||||||
.syntax = .{
|
.syntax = .{
|
||||||
.url = "https://github.com/neurocyte/flow-syntax/archive/fa6a411bc769882acc87cf0d961af3813abf2eac.tar.gz",
|
.url = "git+https://github.com/neurocyte/flow-syntax?ref=zig-0.14#410d19e633f237cd1602175450bd7d3bb03a1898",
|
||||||
.hash = "flow_syntax-0.1.0-X8jOof39AADK25RT1Bst_x7aUIwHbh7y09PJXBghLu_b",
|
.hash = "flow_syntax-0.1.0-X8jOoT4OAQDibKKzYlJls3u5KczVh__cWYN7vTqCE1o3",
|
||||||
},
|
},
|
||||||
.ansi_term = .{
|
.ansi_term = .{
|
||||||
.url = "https://github.com/ziglibs/ansi-term/archive/c0e6ad093d4f6a9ed4e65d962d1e53b97888f989.tar.gz",
|
.url = "https://github.com/ziglibs/ansi-term/archive/c0e6ad093d4f6a9ed4e65d962d1e53b97888f989.tar.gz",
|
||||||
|
|
19
src/main.zig
19
src/main.zig
|
@ -167,11 +167,14 @@ pub fn main() !void {
|
||||||
try write_html_postamble(writer);
|
try write_html_postamble(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_parser(a: std.mem.Allocator, content: []const u8, file_path: []const u8, query_cache: *syntax.QueryCache) *syntax {
|
fn get_parser(a: std.mem.Allocator, content: []const u8, file_path: []const u8, query_cache: *syntax.QueryCache) struct { syntax.FileType, *syntax } {
|
||||||
return (if (lang_override) |name|
|
return if (lang_override) |name| blk: {
|
||||||
syntax.create_file_type(a, name, query_cache) catch unknown_file_type(name)
|
const file_type = syntax.FileType.get_by_name_static(name) orelse unknown_file_type(lang_default);
|
||||||
else
|
break :blk .{ file_type, syntax.create(file_type, a, query_cache) catch unknown_file_type(name) };
|
||||||
syntax.create_guess_file_type(a, content, file_path, query_cache)) catch syntax.create_file_type(a, lang_default, query_cache) catch unknown_file_type(lang_default);
|
} else blk: {
|
||||||
|
const file_type = syntax.FileType.guess_static(file_path, content) orelse unknown_file_type(lang_default);
|
||||||
|
break :blk .{ file_type, syntax.create(file_type, a, query_cache) catch unknown_file_type(lang_default) };
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unknown_file_type(name: []const u8) noreturn {
|
fn unknown_file_type(name: []const u8) noreturn {
|
||||||
|
@ -211,10 +214,10 @@ fn render_file(
|
||||||
}
|
}
|
||||||
|
|
||||||
const query_cache = try syntax.QueryCache.create(a, .{});
|
const query_cache = try syntax.QueryCache.create(a, .{});
|
||||||
const parser = get_parser(a, content, file_path, query_cache);
|
const file_type, const parser = get_parser(a, content, file_path, query_cache);
|
||||||
try parser.refresh_full(content);
|
try parser.refresh_full(content);
|
||||||
if (show_file_type) {
|
if (show_file_type) {
|
||||||
try render_file_type(writer, parser.file_type, theme);
|
try render_file_type(writer, &file_type, theme);
|
||||||
end_line -= 1;
|
end_line -= 1;
|
||||||
}
|
}
|
||||||
if (show_theme) {
|
if (show_theme) {
|
||||||
|
@ -468,7 +471,7 @@ fn write_hex_color(writer: Writer, color: u24) !void {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_langs(writer: Writer) !void {
|
fn list_langs(writer: Writer) !void {
|
||||||
for (syntax.FileType.file_types) |file_type| {
|
for (syntax.FileType.get_all()) |file_type| {
|
||||||
try writer.writeAll(file_type.name);
|
try writer.writeAll(file_type.name);
|
||||||
try writer.writeAll("\n");
|
try writer.writeAll("\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue