From 28ad74e8a6ed3484d632a6a615f5d0935c03676a Mon Sep 17 00:00:00 2001 From: Loris Cro Date: Mon, 3 Jul 2023 19:18:44 +0200 Subject: [PATCH] autodoc: wire in js tokenizer to frontend --- lib/docs/index.html | 82 ++++++++++++++++++++++++++++++++++++++++++++ lib/docs/main.js | 45 ++---------------------- lib/docs/ziglexer.js | 6 ++-- src/Autodoc.zig | 1 + 4 files changed, 88 insertions(+), 46 deletions(-) diff --git a/lib/docs/index.html b/lib/docs/index.html index 4c9dcb2031..6840ae0a3d 100644 --- a/lib/docs/index.html +++ b/lib/docs/index.html @@ -680,7 +680,88 @@ .banner a { color: black; text-decoration: underline; + } + + + + @@ -906,6 +987,7 @@ + diff --git a/lib/docs/main.js b/lib/docs/main.js index dfe6c1e496..10e5eae248 100644 --- a/lib/docs/main.js +++ b/lib/docs/main.js @@ -660,25 +660,7 @@ const NAV_MODES = { if (!decl.decltest) return; const astNode = getAstNode(decl.decltest); domSectDocTests.classList.remove("hidden"); - domDocTestsCode.innerHTML = renderZigSource(astNode.code); - } - - function renderZigSource(code) { - let lines = code.split("\n"); - let result = ""; - let indent_level = 0; - for (let i = 0; i < lines.length; i += 1) { - let line = lines[i].trim(); - if (line[0] == "}") indent_level -= 1; - for (let j = 0; j < indent_level; j += 1) { - result += " "; - } - if (line.startsWith("\\\\")) result += " " - result += line; - if (i != lines.length - 1) result += "\n"; - if (line[line.length - 1] == "{") indent_level += 1; - } - return result; + domDocTestsCode.innerHTML = generate_html_for_src(astNode.code); } function renderUnknownDecl(decl) { @@ -1774,7 +1756,7 @@ const NAV_MODES = { return payloadHtml + "}"; } case "comptimeExpr": { - return renderZigSource(zigAnalysis.comptimeExprs[expr.comptimeExpr].code); + return generate_html_for_src(zigAnalysis.comptimeExprs[expr.comptimeExpr].code); } case "call": { let call = zigAnalysis.calls[expr.call]; @@ -5016,26 +4998,3 @@ function RadixTree() { } } -// RADIX TREE: - -// apple -// appliance - -// "appl" => [ -// 'e', => $ -// 'i' => "ance" => $ -// ] - -// OUR STUFF: - -// AutoHashMap -// AutoArrayHashMap - -// "Auto" => [ -// 'A', => "rrayHashMap" => $ -// 'H' => "ashMap" => $ -// ] - -// BUT! - -// We want to be able to search "Hash", for example! diff --git a/lib/docs/ziglexer.js b/lib/docs/ziglexer.js index ef85c1e431..06a37dfb97 100644 --- a/lib/docs/ziglexer.js +++ b/lib/docs/ziglexer.js @@ -1,3 +1,5 @@ +'use strict'; + const Tag = { invalid: "invalid", identifier: "identifier", @@ -1941,7 +1943,7 @@ function tokenize_zig_source(raw_source) { } - toks = [] + let toks = [] for (let i = 0; i < raw_source.length * 2; i++) { const tok = next(); @@ -1960,7 +1962,6 @@ function generate_html_for_src(src) { var toks = tokenize_zig_source(src); var html = []; - html.push("
");
     let offset = 0;
     for (let z = 0; z < toks.length; z++) {
         const t = toks[z];
@@ -1980,7 +1981,6 @@ function generate_html_for_src(src) {
 
 
     html.push(src);
-    html.push("
"); return html.join(""); diff --git a/src/Autodoc.zig b/src/Autodoc.zig index 320893a3c3..b979aa741c 100644 --- a/src/Autodoc.zig +++ b/src/Autodoc.zig @@ -435,6 +435,7 @@ pub fn generateZirData(self: *Autodoc) !void { var docs_dir = try self.comp_module.comp.zig_lib_directory.handle.openDir("docs", .{}); defer docs_dir.close(); try docs_dir.copyFile("main.js", output_dir, "main.js", .{}); + try docs_dir.copyFile("ziglexer.js", output_dir, "ziglexer.js", .{}); try docs_dir.copyFile("commonmark.js", output_dir, "commonmark.js", .{}); try docs_dir.copyFile("index.html", output_dir, "index.html", .{}); }