Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b4b3af5

Browse files
committedFeb 13, 2025
Migrate to latest patched 0.14-compatible zine, update this to zig 0.14
1 parent 21cde80 commit b4b3af5

File tree

9 files changed

+84
-90
lines changed

9 files changed

+84
-90
lines changed
 

‎assets/main.wasm

-194 KB
Binary file not shown.

‎assets/zml_api.js

+1
Original file line numberDiff line numberDiff line change
@@ -982,3 +982,4 @@
982982
wasmArray.set(jsArray);
983983
}
984984
})();
985+

‎build.zig.zon

+2-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
// .hash = "1220a59c2cf0e42a6f42cf1bf9b6a6c2691abfd91fcafa0e81a6282c4a197d05c41a",
99

1010
// modified zine
11-
.url = "git+https://github.com/renerocksai/zine#170567737efc5333b38886cfe83211e011267b24",
12-
.hash = "1220ec97928f9e1f1a95ff8c39a943cf6ebab2ff2e6acb1900aeb7844f906b1ce3aa",
13-
14-
// rene local dev
15-
// .path = "../../renerocksai/zine",
11+
.url = "https://github.com/renerocksai/zine/archive/refs/tags/zig-0.14.0.tar.gz",
12+
.hash = "1220dfe5a9352fc7c9c16b07c5c6d7417fc96ee92dbab5f27b8d4d02400ba5a9f88c",
1613
},
1714
},
1815
.paths = .{"."},

‎zig_docs/Decl.zig

-36
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ file: Walk.File.Index,
1212
/// The decl whose namespace this is in.
1313
parent: Index,
1414

15-
/// Delete this to find out where URL escaping needs to be added.
16-
const missing_feature_url_escape = true;
17-
1815
pub const ExtraInfo = struct {
1916
is_pub: bool,
2017
name: []const u8,
@@ -160,16 +157,6 @@ pub fn fqn(decl: *const Decl, out: *std.ArrayListUnmanaged(u8)) Oom!void {
160157
}
161158
}
162159

163-
threadlocal var _fqn_buf: [1024]u8 = undefined;
164-
165-
pub fn fqnAsHref(decl: *const Decl, allocator: std.mem.Allocator, out: *std.ArrayListUnmanaged(u8)) Oom!void {
166-
var _fqn = std.ArrayListUnmanaged(u8).fromOwnedSlice(&_fqn_buf);
167-
_fqn.items.len = 0;
168-
try decl.fqn(&_fqn);
169-
170-
try renderHref(out.writer(allocator), _fqn.items);
171-
}
172-
173160
pub fn reset_with_path(decl: *const Decl, list: *std.ArrayListUnmanaged(u8)) Oom!void {
174161
list.clearRetainingCapacity();
175162
try append_path(decl, list);
@@ -237,26 +224,3 @@ pub fn find(search_string: []const u8) Decl.Index {
237224
}
238225
return current_decl_index;
239226
}
240-
241-
/// Replace a fully qualified name from Zig std symbol by an external link.
242-
/// fqn is not allowed to alias to out.
243-
pub fn renderHref(writer: anytype, noalias name: []const u8) !void {
244-
std.log.debug("checking fqn: \"{s}\"", .{name});
245-
246-
const std_module = std.mem.indexOf(u8, name, ".std.");
247-
const std_root = if (std.mem.endsWith(u8, name, ".std")) name.len - 4 else null;
248-
249-
if (std_module orelse std_root) |std_dot_start| {
250-
const std_href = " href=\"https://ziglang.org/documentation/0.13.0/std/#";
251-
try writer.writeAll(std_href);
252-
_ = missing_feature_url_escape;
253-
try writer.writeAll(name[std_dot_start + 1 ..]);
254-
try writer.writeByte('"');
255-
std.log.debug("replaced name: \"{s}\" -> {s}{s}", .{ name, std_href, name });
256-
} else {
257-
try writer.writeAll(" href=\"#");
258-
_ = missing_feature_url_escape;
259-
try writer.writeAll(name);
260-
try writer.writeByte('"');
261-
}
262-
}

‎zig_docs/Walk.zig

+11-11
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ const Oom = error{OutOfMemory};
1010

1111
pub const Decl = @import("Decl.zig");
1212

13-
pub var files: std.StringArrayHashMapUnmanaged(File) = .{};
14-
pub var decls: std.ArrayListUnmanaged(Decl) = .{};
15-
pub var modules: std.StringArrayHashMapUnmanaged(File.Index) = .{};
13+
pub var files: std.StringArrayHashMapUnmanaged(File) = .empty;
14+
pub var decls: std.ArrayListUnmanaged(Decl) = .empty;
15+
pub var modules: std.StringArrayHashMapUnmanaged(File.Index) = .empty;
1616

1717
file: File.Index,
1818

@@ -36,23 +36,23 @@ pub const Category = union(enum(u8)) {
3636
/// A function that returns a type.
3737
type_function: Ast.Node.Index,
3838

39-
pub const Tag = @typeInfo(Category).Union.tag_type.?;
39+
pub const Tag = @typeInfo(Category).@"union".tag_type.?;
4040
};
4141

4242
pub const File = struct {
4343
ast: Ast,
4444
/// Maps identifiers to the declarations they point to.
45-
ident_decls: std.AutoArrayHashMapUnmanaged(Ast.TokenIndex, Ast.Node.Index) = .{},
45+
ident_decls: std.AutoArrayHashMapUnmanaged(Ast.TokenIndex, Ast.Node.Index) = .empty,
4646
/// Maps field access identifiers to the containing field access node.
47-
token_parents: std.AutoArrayHashMapUnmanaged(Ast.TokenIndex, Ast.Node.Index) = .{},
47+
token_parents: std.AutoArrayHashMapUnmanaged(Ast.TokenIndex, Ast.Node.Index) = .empty,
4848
/// Maps declarations to their global index.
49-
node_decls: std.AutoArrayHashMapUnmanaged(Ast.Node.Index, Decl.Index) = .{},
49+
node_decls: std.AutoArrayHashMapUnmanaged(Ast.Node.Index, Decl.Index) = .empty,
5050
/// Maps function declarations to doctests.
51-
doctests: std.AutoArrayHashMapUnmanaged(Ast.Node.Index, Ast.Node.Index) = .{},
51+
doctests: std.AutoArrayHashMapUnmanaged(Ast.Node.Index, Ast.Node.Index) = .empty,
5252
/// root node => its namespace scope
5353
/// struct/union/enum/opaque decl node => its namespace scope
5454
/// local var decl node => its local variable scope
55-
scopes: std.AutoArrayHashMapUnmanaged(Ast.Node.Index, *Scope) = .{},
55+
scopes: std.AutoArrayHashMapUnmanaged(Ast.Node.Index, *Scope) = .empty,
5656

5757
pub fn lookup_token(file: *File, token: Ast.TokenIndex) Decl.Index {
5858
const decl_node = file.ident_decls.get(token) orelse return .none;
@@ -464,8 +464,8 @@ pub const Scope = struct {
464464
const Namespace = struct {
465465
base: Scope = .{ .tag = .namespace },
466466
parent: *Scope,
467-
names: std.StringArrayHashMapUnmanaged(Ast.Node.Index) = .{},
468-
doctests: std.StringArrayHashMapUnmanaged(Ast.Node.Index) = .{},
467+
names: std.StringArrayHashMapUnmanaged(Ast.Node.Index) = .empty,
468+
doctests: std.StringArrayHashMapUnmanaged(Ast.Node.Index) = .empty,
469469
decl_index: Decl.Index,
470470
};
471471

‎zig_docs/html_render.zig

+39-9
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,24 @@ const Decl = Walk.Decl;
88
const gpa = std.heap.wasm_allocator;
99
const Oom = error{OutOfMemory};
1010

11+
/// Delete this to find out where URL escaping needs to be added.
12+
pub const missing_feature_url_escape = true;
13+
1114
pub const RenderSourceOptions = struct {
1215
skip_doc_comments: bool = false,
1316
skip_comments: bool = false,
1417
collapse_whitespace: bool = false,
1518
fn_link: Decl.Index = .none,
19+
/// Assumed to be sorted ascending.
20+
source_location_annotations: []const Annotation = &.{},
21+
/// Concatenated with dom_id.
22+
annotation_prefix: []const u8 = "l",
23+
};
24+
25+
pub const Annotation = struct {
26+
file_byte_offset: u32,
27+
/// Concatenated with annotation_prefix.
28+
dom_id: u32,
1629
};
1730

1831
pub fn fileSourceHtml(
@@ -25,7 +38,7 @@ pub fn fileSourceHtml(
2538
const file = file_index.get();
2639

2740
const g = struct {
28-
var field_access_buffer: std.ArrayListUnmanaged(u8) = .{};
41+
var field_access_buffer: std.ArrayListUnmanaged(u8) = .empty;
2942
};
3043

3144
const token_tags = ast.tokens.items(.tag);
@@ -48,6 +61,8 @@ pub fn fileSourceHtml(
4861
}
4962
}
5063

64+
var next_annotate_index: usize = 0;
65+
5166
for (
5267
token_tags[start_token..end_token],
5368
token_starts[start_token..end_token],
@@ -71,6 +86,18 @@ pub fn fileSourceHtml(
7186
if (tag == .eof) break;
7287
const slice = ast.tokenSlice(token_index);
7388
cursor = start + slice.len;
89+
90+
// Insert annotations.
91+
while (true) {
92+
if (next_annotate_index >= options.source_location_annotations.len) break;
93+
const next_annotation = options.source_location_annotations[next_annotate_index];
94+
if (cursor <= next_annotation.file_byte_offset) break;
95+
try out.writer(gpa).print("<span id=\"{s}{d}\"></span>", .{
96+
options.annotation_prefix, next_annotation.dom_id,
97+
});
98+
next_annotate_index += 1;
99+
}
100+
74101
switch (tag) {
75102
.eof => unreachable,
76103

@@ -159,8 +186,9 @@ pub fn fileSourceHtml(
159186
const fn_link = options.fn_link.get();
160187
const fn_token = main_tokens[fn_link.ast_node];
161188
if (token_index == fn_token + 1) {
162-
try out.appendSlice(gpa, "<a class=\"tok-fn\"");
163-
try fn_link.fqnAsHref(gpa, out);
189+
try out.appendSlice(gpa, "<a class=\"tok-fn\" href=\"#");
190+
_ = missing_feature_url_escape;
191+
try fn_link.fqn(out);
164192
try out.appendSlice(gpa, "\">");
165193
try appendEscaped(out, slice);
166194
try out.appendSlice(gpa, "</a>");
@@ -193,9 +221,10 @@ pub fn fileSourceHtml(
193221
g.field_access_buffer.clearRetainingCapacity();
194222
try walkFieldAccesses(file_index, &g.field_access_buffer, field_access_node);
195223
if (g.field_access_buffer.items.len > 0) {
196-
try out.appendSlice(gpa, "<a");
197-
try Decl.renderHref(out.writer(gpa), g.field_access_buffer.items);
198-
try out.appendSlice(gpa, ">");
224+
try out.appendSlice(gpa, "<a href=\"#");
225+
_ = missing_feature_url_escape;
226+
try out.appendSlice(gpa, g.field_access_buffer.items);
227+
try out.appendSlice(gpa, "\">");
199228
try appendEscaped(out, slice);
200229
try out.appendSlice(gpa, "</a>");
201230
} else {
@@ -208,9 +237,10 @@ pub fn fileSourceHtml(
208237
g.field_access_buffer.clearRetainingCapacity();
209238
try resolveIdentLink(file_index, &g.field_access_buffer, token_index);
210239
if (g.field_access_buffer.items.len > 0) {
211-
try out.appendSlice(gpa, "<a");
212-
try Decl.renderHref(out.writer(gpa), g.field_access_buffer.items);
213-
try out.appendSlice(gpa, ">");
240+
try out.appendSlice(gpa, "<a href=\"#");
241+
_ = missing_feature_url_escape;
242+
try out.appendSlice(gpa, g.field_access_buffer.items);
243+
try out.appendSlice(gpa, "\">");
214244
try appendEscaped(out, slice);
215245
try out.appendSlice(gpa, "</a>");
216246
break :i;

‎zig_docs/main.zig

+21-19
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const Decl = Walk.Decl;
99
const fileSourceHtml = @import("html_render.zig").fileSourceHtml;
1010
const appendEscaped = @import("html_render.zig").appendEscaped;
1111
const resolveDeclLink = @import("html_render.zig").resolveDeclLink;
12-
const renderHref = Decl.renderHref;
12+
const missing_feature_url_escape = @import("html_render.zig").missing_feature_url_escape;
1313

1414
const gpa = std.heap.wasm_allocator;
1515

@@ -60,8 +60,8 @@ export fn unpack(tar_ptr: [*]u8, tar_len: usize) void {
6060
};
6161
}
6262

63-
var query_string: std.ArrayListUnmanaged(u8) = .{};
64-
var query_results: std.ArrayListUnmanaged(Decl.Index) = .{};
63+
var query_string: std.ArrayListUnmanaged(u8) = .empty;
64+
var query_results: std.ArrayListUnmanaged(Decl.Index) = .empty;
6565

6666
/// Resizes the query string to be the correct length; returns the pointer to
6767
/// the query string.
@@ -93,11 +93,11 @@ fn query_exec_fallible(query: []const u8, ignore_case: bool) !void {
9393
segments: u16,
9494
};
9595
const g = struct {
96-
var full_path_search_text: std.ArrayListUnmanaged(u8) = .{};
97-
var full_path_search_text_lower: std.ArrayListUnmanaged(u8) = .{};
98-
var doc_search_text: std.ArrayListUnmanaged(u8) = .{};
96+
var full_path_search_text: std.ArrayListUnmanaged(u8) = .empty;
97+
var full_path_search_text_lower: std.ArrayListUnmanaged(u8) = .empty;
98+
var doc_search_text: std.ArrayListUnmanaged(u8) = .empty;
9999
/// Each element matches a corresponding query_results element.
100-
var scores: std.ArrayListUnmanaged(Score) = .{};
100+
var scores: std.ArrayListUnmanaged(Score) = .empty;
101101
};
102102

103103
// First element stores the size of the list.
@@ -238,8 +238,9 @@ const ErrorIdentifier = packed struct(u64) {
238238
try out.appendSlice(gpa, "<dt>");
239239
try out.appendSlice(gpa, name);
240240
if (has_link) {
241-
try out.appendSlice(gpa, " <a");
242-
try decl_index.get().fqnAsHref(gpa, out);
241+
try out.appendSlice(gpa, " <a href=\"#");
242+
_ = missing_feature_url_escape;
243+
try decl_index.get().fqn(out);
243244
try out.appendSlice(gpa, "\">");
244245
try out.appendSlice(gpa, decl_index.get().extra_info().name);
245246
try out.appendSlice(gpa, "</a>");
@@ -254,8 +255,8 @@ const ErrorIdentifier = packed struct(u64) {
254255
}
255256
};
256257

257-
var string_result: std.ArrayListUnmanaged(u8) = .{};
258-
var error_set_result: std.StringArrayHashMapUnmanaged(ErrorIdentifier) = .{};
258+
var string_result: std.ArrayListUnmanaged(u8) = .empty;
259+
var error_set_result: std.StringArrayHashMapUnmanaged(ErrorIdentifier) = .empty;
259260

260261
export fn decl_error_set(decl_index: Decl.Index) Slice(ErrorIdentifier) {
261262
return Slice(ErrorIdentifier).init(decl_error_set_fallible(decl_index) catch @panic("OOM"));
@@ -380,7 +381,7 @@ export fn decl_params(decl_index: Decl.Index) Slice(Ast.Node.Index) {
380381

381382
fn decl_fields_fallible(decl_index: Decl.Index) ![]Ast.Node.Index {
382383
const g = struct {
383-
var result: std.ArrayListUnmanaged(Ast.Node.Index) = .{};
384+
var result: std.ArrayListUnmanaged(Ast.Node.Index) = .empty;
384385
};
385386
g.result.clearRetainingCapacity();
386387
const decl = decl_index.get();
@@ -402,7 +403,7 @@ fn decl_fields_fallible(decl_index: Decl.Index) ![]Ast.Node.Index {
402403

403404
fn decl_params_fallible(decl_index: Decl.Index) ![]Ast.Node.Index {
404405
const g = struct {
405-
var result: std.ArrayListUnmanaged(Ast.Node.Index) = .{};
406+
var result: std.ArrayListUnmanaged(Ast.Node.Index) = .empty;
406407
};
407408
g.result.clearRetainingCapacity();
408409
const decl = decl_index.get();
@@ -671,7 +672,7 @@ fn render_docs(
671672
defer parsed_doc.deinit(gpa);
672673

673674
const g = struct {
674-
var link_buffer: std.ArrayListUnmanaged(u8) = .{};
675+
var link_buffer: std.ArrayListUnmanaged(u8) = .empty;
675676
};
676677

677678
const Writer = std.ArrayListUnmanaged(u8).Writer;
@@ -694,8 +695,9 @@ fn render_docs(
694695
g.link_buffer.clearRetainingCapacity();
695696
try resolveDeclLink(resolved_decl_index, &g.link_buffer);
696697

697-
try writer.writeAll("<a");
698-
try renderHref(writer, g.link_buffer.items);
698+
try writer.writeAll("<a href=\"#");
699+
_ = missing_feature_url_escape;
700+
try writer.writeAll(g.link_buffer.items);
699701
try writer.print("\">{}</a>", .{markdown.fmtHtml(content)});
700702
} else {
701703
try writer.print("{}", .{markdown.fmtHtml(content)});
@@ -815,7 +817,7 @@ export fn find_module_root(pkg: Walk.ModuleIndex) Decl.Index {
815817
}
816818

817819
/// Set by `set_input_string`.
818-
var input_string: std.ArrayListUnmanaged(u8) = .{};
820+
var input_string: std.ArrayListUnmanaged(u8) = .empty;
819821

820822
export fn set_input_string(len: usize) [*]u8 {
821823
input_string.resize(gpa, len) catch @panic("OOM");
@@ -837,7 +839,7 @@ export fn find_decl() Decl.Index {
837839
if (result != .none) return result;
838840

839841
const g = struct {
840-
var match_fqn: std.ArrayListUnmanaged(u8) = .{};
842+
var match_fqn: std.ArrayListUnmanaged(u8) = .empty;
841843
};
842844
for (Walk.decls.items, 0..) |*decl, decl_index| {
843845
g.match_fqn.clearRetainingCapacity();
@@ -886,7 +888,7 @@ export fn type_fn_members(parent: Decl.Index, include_private: bool) Slice(Decl.
886888

887889
export fn namespace_members(parent: Decl.Index, include_private: bool) Slice(Decl.Index) {
888890
const g = struct {
889-
var members: std.ArrayListUnmanaged(Decl.Index) = .{};
891+
var members: std.ArrayListUnmanaged(Decl.Index) = .empty;
890892
};
891893

892894
g.members.clearRetainingCapacity();

‎zig_docs/markdown/Document.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub fn ExtraData(comptime T: type) type {
170170
}
171171

172172
pub fn extraData(doc: Document, comptime T: type, index: ExtraIndex) ExtraData(T) {
173-
const fields = @typeInfo(T).Struct.fields;
173+
const fields = @typeInfo(T).@"struct".fields;
174174
var i: usize = @intFromEnum(index);
175175
var result: T = undefined;
176176
inline for (fields) |field| {

‎zig_docs/markdown/Parser.zig

+9-9
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ const ExtraData = Document.ExtraData;
3131
const StringIndex = Document.StringIndex;
3232

3333
nodes: Node.List = .{},
34-
extra: std.ArrayListUnmanaged(u32) = .{},
35-
scratch_extra: std.ArrayListUnmanaged(u32) = .{},
36-
string_bytes: std.ArrayListUnmanaged(u8) = .{},
37-
scratch_string: std.ArrayListUnmanaged(u8) = .{},
38-
pending_blocks: std.ArrayListUnmanaged(Block) = .{},
34+
extra: std.ArrayListUnmanaged(u32) = .empty,
35+
scratch_extra: std.ArrayListUnmanaged(u32) = .empty,
36+
string_bytes: std.ArrayListUnmanaged(u8) = .empty,
37+
scratch_string: std.ArrayListUnmanaged(u8) = .empty,
38+
pending_blocks: std.ArrayListUnmanaged(Block) = .empty,
3939
allocator: Allocator,
4040

4141
const Parser = @This();
@@ -816,7 +816,7 @@ fn isThematicBreak(line: []const u8) bool {
816816
}
817817

818818
fn closeLastBlock(p: *Parser) !void {
819-
const b = p.pending_blocks.pop();
819+
const b = p.pending_blocks.pop().?;
820820
const node = switch (b.tag) {
821821
.list => list: {
822822
assert(b.string_start == p.scratch_string.items.len);
@@ -928,8 +928,8 @@ const InlineParser = struct {
928928
parent: *Parser,
929929
content: []const u8,
930930
pos: usize = 0,
931-
pending_inlines: std.ArrayListUnmanaged(PendingInline) = .{},
932-
completed_inlines: std.ArrayListUnmanaged(CompletedInline) = .{},
931+
pending_inlines: std.ArrayListUnmanaged(PendingInline) = .empty,
932+
completed_inlines: std.ArrayListUnmanaged(CompletedInline) = .empty,
933933

934934
const PendingInline = struct {
935935
tag: Tag,
@@ -1564,7 +1564,7 @@ fn parseInlines(p: *Parser, content: []const u8) !ExtraIndex {
15641564
}
15651565

15661566
pub fn extraData(p: Parser, comptime T: type, index: ExtraIndex) ExtraData(T) {
1567-
const fields = @typeInfo(T).Struct.fields;
1567+
const fields = @typeInfo(T).@"struct".fields;
15681568
var i: usize = @intFromEnum(index);
15691569
var result: T = undefined;
15701570
inline for (fields) |field| {

0 commit comments

Comments
 (0)
Please sign in to comment.