Skip to content

Commit

Permalink
langref: automatic update of builtin.zig
Browse files Browse the repository at this point in the history
now the docs can't get out of date for this

See #367
  • Loading branch information
andrewrk committed Jun 7, 2018
1 parent 31aefa6 commit 688ff28
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 428 deletions.
18 changes: 18 additions & 0 deletions doc/docgen.zig
Expand Up @@ -300,6 +300,7 @@ const Link = struct {
const Node = union(enum) {
Content: []const u8,
Nav,
Builtin,
HeaderOpen: HeaderOpen,
SeeAlso: []const SeeAlsoItem,
Code: Code,
Expand Down Expand Up @@ -356,6 +357,9 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
_ = try eatToken(tokenizer, Token.Id.BracketClose);

try nodes.append(Node.Nav);
} else if (mem.eql(u8, tag_name, "builtin")) {
_ = try eatToken(tokenizer, Token.Id.BracketClose);
try nodes.append(Node.Builtin);
} else if (mem.eql(u8, tag_name, "header_open")) {
_ = try eatToken(tokenizer, Token.Id.Separator);
const content_token = try eatToken(tokenizer, Token.Id.TagContent);
Expand Down Expand Up @@ -690,6 +694,9 @@ fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {

fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var, zig_exe: []const u8) !void {
var code_progress_index: usize = 0;

const builtin_code = try escapeHtml(allocator, try getBuiltinCode(allocator, zig_exe));

for (toc.nodes) |node| {
switch (node) {
Node.Content => |data| {
Expand All @@ -704,6 +711,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
Node.Nav => {
try out.write(toc.toc);
},
Node.Builtin => {
try out.print("<pre><code class=\"zig\">{}</code></pre>", builtin_code);
},
Node.HeaderOpen => |info| {
try out.print("<h{} id=\"{}\">{}</h{}>\n", info.n, info.url, info.name, info.n);
},
Expand Down Expand Up @@ -1060,3 +1070,11 @@ fn exec(allocator: *mem.Allocator, args: []const []const u8) !os.ChildProcess.Ex
}
return result;
}

fn getBuiltinCode(allocator: *mem.Allocator, zig_exe: []const u8) ![]const u8 {
const result = try exec(allocator, []const []const u8{
zig_exe,
"builtin",
});
return result.stdout;
}

0 comments on commit 688ff28

Please sign in to comment.