summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreudoxia <uplink@distress.network>2022-04-01 00:04:08 -0400
committereudoxia <uplink@distress.network>2022-04-01 00:04:08 -0400
commiteac46231ab86e3b6a3862c92323ee58fe1ee722b (patch)
tree0440a92a680eb402735991cd4fa791de0c6437fa
parent27f4773b122a2758cfaf88537c9e1a8ad5df7e69 (diff)
doc generation integrated with distress.network
-rw-r--r--doc/data.html120
-rw-r--r--doc/freestanding/data.html519
-rw-r--r--doc/freestanding/log.html102
-rw-r--r--doc/freestanding/tangle.html141
-rw-r--r--doc/freestanding/weave.html125
-rw-r--r--doc/header8
-rw-r--r--doc/log.html58
-rw-r--r--doc/tangle.html62
-rw-r--r--doc/weave.html60
-rwxr-xr-xgen-docs.sh20
-rwxr-xr-xgen-freestanding.sh10
11 files changed, 1067 insertions, 158 deletions
diff --git a/doc/data.html b/doc/data.html
index 676f209..ccf8c3a 100644
--- a/doc/data.html
+++ b/doc/data.html
@@ -3,60 +3,50 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
-<style>
-* {box-sizing: border-box;}
-html {
---fs-sans: Helvetica, "Helvetica Neue", Arial, "San Francisco", sans;
---fs-mono: jetbrains-mono-regular, Consolas, Menlo, monospace;
-font-size: 16px;
-}
-body {background-color: #111; color: #ddd; margin: 2rem calc(50% - 32rem); font-family: var(--fs-sans); font-size: 1rem; font-style: normal;}
-body * {line-height: 1.5; text-align: justify; text-justify: inter-word;}
-h1,h2 {font-family: var(--fs-sans); margin: 2rem 0 1rem; font-weight: bold; line-height: 1;}
-h1 {font-size: 3rem;}
-h2 {font-size: 2rem;}
-h3 {margin: 1rem; font-size: 1rem; font-weight: normal; font-style: italic;}
-code,code * {font-family: var(--fs-mono); hyphens: none; line-height: 1.25rem;}
-body>pre {background-color: #000; margin: 1rem; padding: 1rem; white-space: pre-wrap; border-radius: 0.25rem;}
-ul,ol {margin: 1rem 0; padding: 0 0 0 2rem;}
-ul ul,ol ol {margin: 0;}
-.ref {font-family: var(--fs-sans); font-style: italic;}
-@media screen and (max-width: 68rem) {body {margin: 2rem calc(50% - 24rem);}}
-@media screen and (max-width: 52rem) {body {margin: 2rem calc(50% - 16rem);}}
-@media screen and (max-width: 36rem) {body {margin: 2rem; hyphens: auto;} h3,body>pre {margin: 1rem 0}}
-</style>
+<link rel="stylesheet" href="/fonts/fonts.css">
+<link rel="stylesheet" href="/css/main.css">
+<link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png">
+<link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png">
+<link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png">
+<link rel="manifest" href="/favicon/site.webmanifest">
+<title>data.lp &mdash; DistressNetwork°</title>
+<meta http-equiv="last-modified" content="2022-03-31 23:28:56-04:00" />
+<style>.lp-ref {font-family: neue-haas-grotesk-text, var(--fs-sans); font-style: italic;}</style>
</head>
-
<body>
+<div class="contentlevel">
+<main>
+<div class="leading">data.lp</div>
+<hr>
<h1 id="data.zig">data.zig</h1>
<p>This file contains the various data processing-related constants and functions referenced by the tangling and weaving processes.</p>
<h3 id="section">*:</h3>
-<pre><code><span class="ref" >(Imports)</span>
+<pre><code><span class="lp-ref">(Imports)</span>
-<span class="ref" >(Processing limits)</span>
+<span class="lp-ref">(Processing limits)</span>
-<span class="ref" >(Formatting keywords)</span>
+<span class="lp-ref">(Formatting keywords)</span>
-<span class="ref" >(Configuration keywords)</span>
+<span class="lp-ref">(Configuration keywords)</span>
-<span class="ref" >(Data structure types)</span>
+<span class="lp-ref">(Data structure types)</span>
-<span class="ref" >(Error set)</span>
+<span class="lp-ref">(Error set)</span>
-<span class="ref" >(Line splitting function)</span>
+<span class="lp-ref">(Line splitting function)</span>
-<span class="ref" >(Configuration searching function)</span>
+<span class="lp-ref">(Configuration searching function)</span>
-<span class="ref" >(Section searching function)</span>
+<span class="lp-ref">(Section searching function)</span>
-<span class="ref" >(Parsing functions)</span>
+<span class="lp-ref">(Parsing functions)</span>
-<span class="ref" >(Code generation functions)</span>
+<span class="lp-ref">(Code generation functions)</span>
-<span class="ref" >(Text generation function)</span>
+<span class="lp-ref">(Text generation function)</span>
</code></pre>
<h2 id="constants">Constants</h2>
@@ -176,7 +166,7 @@ pub const LineRange = struct {
var buffer = std.ArrayList([]const u8).init(alloc);
defer buffer.deinit();
- <span class="ref" >(Split file at each newline)</span>
+ <span class="lp-ref">(Split file at each newline)</span>
return buffer.toOwnedSlice();
}
@@ -211,11 +201,11 @@ while (iterator.next()) |line| {
return try fmt_conf(line, key, alloc);
}
}
- log(.err, "config declaration &#39;{s}&#39; not found", .{std.mem.trimRight(u8, key, " \t")});
+ log(.err, "config declaration '{s}' not found", .{std.mem.trimRight(u8, key, " \t")});
return error.NotFound;
}
-<span class="ref" >(Auxiliary formatting function)</span>
+<span class="lp-ref">(Auxiliary formatting function)</span>
</code></pre>
<p>If the declaration is found, its contained format string is split along instances of the section name escape sequence, and each substring has its instances of the newline escape sequence replaced with a literal newline.</p>
@@ -243,10 +233,10 @@ while (iterator.next()) |line| {
for (list) |section, index| {
if (std.mem.eql(u8, section.name, name)) return index;
}
- log(.err, "section &#39;{s}&#39; not found", .{name});
+ log(.err, "section '{s}' not found", .{name});
return error.NotFound;
}
-&#47;&#47; TODO return last match instead?
+// TODO return last match instead?
</code></pre>
<h2 id="parsing">Parsing</h2>
@@ -259,7 +249,7 @@ while (iterator.next()) |line| {
var sections = std.ArrayList(Section).init(alloc);
defer sections.deinit();
- <span class="ref" >(Main parsing routine)</span>
+ <span class="lp-ref">(Main parsing routine)</span>
return sections.toOwnedSlice();
}
@@ -268,7 +258,7 @@ fn parse_code(lines: [][]const u8, index: u32, alloc: Allocator) !CodeReturn {
var content = std.ArrayList(Content).init(alloc);
defer content.deinit();
- <span class="ref" >(Code parsing subroutine)</span>
+ <span class="lp-ref">(Code parsing subroutine)</span>
return CodeReturn{ .content = content.toOwnedSlice(), .index = i + 1 };
}
@@ -292,9 +282,9 @@ fn parse_code(lines: [][]const u8, index: u32, alloc: Allocator) !CodeReturn {
while (i &#60; lines.len) {
const line = lines[i];
if (std.mem.startsWith(u8, line, k_start)) {
- <span class="ref" >(Add new section)</span>
+ <span class="lp-ref">(Add new section)</span>
} else if (std.mem.startsWith(u8, line, k_add)) {
- <span class="ref" >(Append to section)</span>
+ <span class="lp-ref">(Append to section)</span>
} else if (std.mem.eql(u8, line, k_end)) {
log(.err, "line {d}: unexpected section end", .{i + 1});
return error.UnexpectedEnd;
@@ -309,12 +299,12 @@ while (i &#60; lines.len) {
<h3 id="add-new-section">Add new section:</h3>
<pre><code>const name = line[(k_start.len)..];
-log(.debug, "({d}) starting section &#39;{s}&#39;", .{ i + 1, name });
+log(.debug, "({d}) starting section '{s}'", .{ i + 1, name });
const section = try parse_code(lines, i + 1, alloc);
try sections.append(.{ .name = name, .content = section.content });
-log(.debug, "({d}) ending section &#39;{s}&#39;", .{ section.index, name });
+log(.debug, "({d}) ending section '{s}'", .{ section.index, name });
i = section.index;
</code></pre>
@@ -323,7 +313,7 @@ i = section.index;
<h3 id="append-to-section">Append to section:</h3>
<pre><code>const name = line[(k_add.len)..];
-log(.debug, "({d}) appending to section &#39;{s}&#39;", .{ i + 1, name });
+log(.debug, "({d}) appending to section '{s}'", .{ i + 1, name });
const section = try parse_code(lines, i + 1, alloc);
const index = try search(sections.items, name);
@@ -331,7 +321,7 @@ const old = &#38;sections.items[index];
const new = try std.mem.concat(alloc, Content, &#38;[_][]const Content{ old.*.content, section.content });
old.*.content = new;
-log(.debug, "({d}) ending section &#39;{s}&#39;", .{ section.index, name });
+log(.debug, "({d}) ending section '{s}'", .{ section.index, name });
i = section.index;
</code></pre>
@@ -346,11 +336,11 @@ while (i &#60; lines.len) {
log(.err, "line {d}: unexpected section start", .{i + 1});
return error.UnexpectedStart;
} else if (std.mem.startsWith(u8, std.mem.trimLeft(u8, line, " \t"), k_ref)) {
- <span class="ref" >(Add reference)</span>
+ <span class="lp-ref">(Add reference)</span>
} else if (std.mem.eql(u8, line, k_end)) {
break;
} else {
- <span class="ref" >(Add literal range)</span>
+ <span class="lp-ref">(Add literal range)</span>
}
}
</code></pre>
@@ -361,7 +351,7 @@ while (i &#60; lines.len) {
<pre><code>const ref_name = std.mem.trimLeft(u8, line, " \t")[(k_ref.len)..];
try content.append(.{ .reference = ref_name });
-log(.debug, "({d}) \tappended reference &#39;{s}&#39;", .{ i + 1, ref_name });
+log(.debug, "({d}) \tappended reference '{s}'", .{ i + 1, ref_name });
i += 1;
</code></pre>
@@ -402,17 +392,17 @@ fn codegen_main(lines: [][]const u8, list: []Section, index: usize, depth: u8, a
defer buffer.deinit();
const section = list[index];
- log(.debug, "generating section &#39;{s}&#39;", .{section.name});
+ log(.debug, "generating section '{s}'", .{section.name});
for (section.content) |content| switch (content) {
.literal =&#62; |range| {
- <span class="ref" >(Append literal range)</span>
+ <span class="lp-ref">(Append literal range)</span>
},
.reference =&#62; |name| {
- <span class="ref" >(Resolve reference)</span>
+ <span class="lp-ref">(Resolve reference)</span>
},
};
- log(.debug, "ending section &#39;{s}&#39;", .{section.name});
+ log(.debug, "ending section '{s}'", .{section.name});
return buffer.toOwnedSlice();
}
</code></pre>
@@ -448,7 +438,7 @@ try buffer.appendSlice(code);
var buffer = std.ArrayList([]const u8).init(alloc);
defer buffer.deinit();
- <span class="ref" >(Process configuration declarations)</span>
+ <span class="lp-ref">(Process configuration declarations)</span>
var current_name: []const u8 = undefined;
for (lines) |line| {
@@ -458,13 +448,13 @@ try buffer.appendSlice(code);
or std.mem.startsWith(u8, line, kc_ref)) {
continue;
} else if (std.mem.startsWith(u8, line, k_start)) {
- <span class="ref" >(Format starting command)</span>
+ <span class="lp-ref">(Format starting command)</span>
} else if (std.mem.startsWith(u8, line, k_add)) {
- <span class="ref" >(Format appending command)</span>
+ <span class="lp-ref">(Format appending command)</span>
} else if (std.mem.startsWith(u8, line, k_end)) {
- <span class="ref" >(Format ending command)</span>
+ <span class="lp-ref">(Format ending command)</span>
} else if (std.mem.startsWith(u8, std.mem.trimLeft(u8, line, " \t"), k_ref)) {
- <span class="ref" >(Format reference command)</span>
+ <span class="lp-ref">(Format reference command)</span>
} else {
try buffer.append(line);
}
@@ -515,5 +505,13 @@ try buffer.append(try std.mem.join(alloc, current_name, conf_add));
const ref = try std.mem.join(alloc, line[(start + k_ref.len)..], conf_ref);
try buffer.append(try std.mem.concat(alloc, u8, &#38;[_][]const u8{ line[0..start], ref }));
</code></pre>
+</main>
+<nav>
+</nav>
+</div>
+<footer>
+<p><a href="/info">About.</a> <a href="mailto:uplink@distress.network">Contact.</a> <a href="/cw.html">Content Warning.</a> <a href="https://git.distress.network">Git.</a> <a href="/meta/sitemap">Sitemap.</a> <a href="https://creativecommons.org/licenses/by-sa/4.0">CC BY-SA 4.0.</a></p>
+<img src="/media/distressnetwork-w.svg" alt="">
+</footer>
</body>
-</html> \ No newline at end of file
+</html>
diff --git a/doc/freestanding/data.html b/doc/freestanding/data.html
new file mode 100644
index 0000000..de0cbd8
--- /dev/null
+++ b/doc/freestanding/data.html
@@ -0,0 +1,519 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<style>
+* {box-sizing: border-box;}
+html {
+--fs-sans: Helvetica, "Helvetica Neue", Arial, "San Francisco", sans;
+--fs-mono: jetbrains-mono-regular, Consolas, Menlo, monospace;
+font-size: 16px;
+}
+body {background-color: #111; color: #ddd; margin: 2rem calc(50% - 32rem); font-family: var(--fs-sans); font-size: 1rem; font-style: normal;}
+body * {line-height: 1.5; text-align: justify; text-justify: inter-word;}
+h1,h2 {font-family: var(--fs-sans); margin: 2rem 0 1rem; font-weight: bold; line-height: 1;}
+h1 {font-size: 3rem;}
+h2 {font-size: 2rem;}
+h3 {margin: 1rem; font-size: 1rem; font-weight: normal; font-style: italic;}
+code,code * {font-family: var(--fs-mono); hyphens: none; line-height: 1.25rem;}
+body>pre {background-color: #000; margin: 1rem; padding: 1rem; white-space: pre-wrap; border-radius: 0.25rem;}
+ul,ol {margin: 1rem 0; padding: 0 0 0 2rem;}
+ul ul,ol ol {margin: 0;}
+.ref {font-family: var(--fs-sans); font-style: italic;}
+@media screen and (max-width: 68rem) {body {margin: 2rem calc(50% - 24rem);}}
+@media screen and (max-width: 52rem) {body {margin: 2rem calc(50% - 16rem);}}
+@media screen and (max-width: 36rem) {body {margin: 2rem; hyphens: auto;} h3,body>pre {margin: 1rem 0;}}
+</style>
+</head>
+
+<body>
+<h1 id="data.zig">data.zig</h1>
+
+<p>This file contains the various data processing-related constants and functions referenced by the tangling and weaving processes.</p>
+
+<h3 id="section">*:</h3>
+
+<pre><code><span class="ref" >(Imports)</span>
+
+<span class="ref" >(Processing limits)</span>
+
+<span class="ref" >(Formatting keywords)</span>
+
+<span class="ref" >(Configuration keywords)</span>
+
+<span class="ref" >(Data structure types)</span>
+
+<span class="ref" >(Error set)</span>
+
+<span class="ref" >(Line splitting function)</span>
+
+<span class="ref" >(Configuration searching function)</span>
+
+<span class="ref" >(Section searching function)</span>
+
+<span class="ref" >(Parsing functions)</span>
+
+<span class="ref" >(Code generation functions)</span>
+
+<span class="ref" >(Text generation function)</span>
+</code></pre>
+
+<h2 id="constants">Constants</h2>
+
+<p>We first import the standard library and the logging function from <code>log.zig</code>.</p>
+
+<h3 id="imports">Imports:</h3>
+
+<pre><code>const std = @import("std");
+const log = @import("log.zig").log;
+
+const Allocator = std.mem.Allocator;
+</code></pre>
+
+<p>We define the maximum input file size of 4GiB, and the code generation function&#8217;s maximum recursion depth of 250 nested calls.</p>
+
+<h3 id="processing-limits">Processing limits:</h3>
+
+<pre><code>pub const input_max = 0x1_0000_0000;
+pub const dereference_max = 250;
+</code></pre>
+
+<p>We then define the recognized formatting keywords. These consist of the following:</p>
+
+<ul>
+<li><code>@:</code>, which begins a new code section;</li>
+<li><code>@+</code>, which appends content to a previous code section;</li>
+<li><code>@.</code>, which terminates the definition of a code section;</li>
+<li><code>@=</code>, which creates a reference to another code section;</li>
+<li><code>*</code>, which is a reserved section name representing the root level of the source code.</li>
+</ul>
+
+<h3 id="formatting-keywords">Formatting keywords:</h3>
+
+<pre><code>pub const k_start = "@: ";
+pub const k_add = "@+ ";
+pub const k_end = "@.";
+pub const k_ref = "@= ";
+pub const k_root = "*";
+</code></pre>
+
+<p>We similarly define the recognized configuration keywords, consisting of:</p>
+
+<ul>
+<li><code>@start</code>, which defines the leading formatted code delimiter when beginning new sections;</li>
+<li><code>@add</code>, which defines the leading formatted code delimiter when appending to existing sections;</li>
+<li><code>@end</code>, which defines the trailing formatted code delimiter;</li>
+<li><code>@ref</code>, which defines the format for section references;</li>
+<li><code>@@</code>, which is the escape sequence representing the current section name;</li>
+<li><code>\n</code>, which is the escape sequence representing a newline.</li>
+</ul>
+
+<h3 id="configuration-keywords">Configuration keywords:</h3>
+
+<pre><code>pub const kc_start = "@start ";
+pub const kc_add = "@add ";
+pub const kc_end = "@end ";
+pub const kc_ref = "@ref ";
+pub const kc_esc = "@@";
+pub const kc_nl = "\\n";
+</code></pre>
+
+<p>We then define the data structure used for parsing the input into code sections, described as follows:</p>
+
+<ul>
+<li>The overall structure of the file is an array of <code>Section</code>s.</li>
+<li>A <code>Section</code> consists of the section name and an array of <code>Content</code> elements.</li>
+<li>A <code>Content</code> element may be either a range of literal lines of code or a reference to another section.</li>
+<li>A <code>LineRange</code> is a pair of integers indicating the starting and ending line numbers of the section.</li>
+</ul>
+
+<h3 id="data-structure-types">Data structure types:</h3>
+
+<pre><code>pub const Section = struct {
+ name: []const u8,
+ content: []const Content,
+};
+
+pub const CodeType = enum { literal, reference };
+pub const Content = union(CodeType) {
+ literal: LineRange,
+ reference: []const u8,
+};
+
+pub const LineRange = struct {
+ start: u32,
+ end: u32,
+};
+</code></pre>
+
+<p>We also define the set of errors which may be encountered by the various processing functions, consisting of:</p>
+
+<ul>
+<li>Unexpected section start commands,</li>
+<li>Unexpected section end commands, </li>
+<li>Recursive dereferencing exceeding the specified depth limit,</li>
+<li>References to nonexistent section names or configuration commands.</li>
+</ul>
+
+<h3 id="error-set">Error set:</h3>
+
+<pre><code>pub const Errors = error{
+ UnexpectedStart,
+ UnexpectedEnd,
+ DereferenceLimit,
+ NotFound,
+};
+</code></pre>
+
+<h2 id="preprocessing-searching">Preprocessing &#38; Searching</h2>
+
+<p>The line splitting function is defined, which operates on a buffer as follows.</p>
+
+<h3 id="line-splitting-function">Line splitting function:</h3>
+
+<pre><code>pub fn split_lines(file: []const u8, alloc: Allocator) ![][]const u8 {
+ var buffer = std.ArrayList([]const u8).init(alloc);
+ defer buffer.deinit();
+
+ <span class="ref" >(Split file at each newline)</span>
+
+ return buffer.toOwnedSlice();
+}
+</code></pre>
+
+<p>The function simply iteratively splits the file at each newline, and appends each resulting line to the buffer.</p>
+
+<h3 id="split-file-at-each-newline">Split file at each newline:</h3>
+
+<pre><code>var iterator = std.mem.split(u8, file, "\n");
+while (iterator.next()) |line| {
+ try buffer.append(line);
+}
+</code></pre>
+
+<p>In addition, the final empty line created by the trailing newline at the end of the file (inserted automatically by some text editors) is removed, if it exists. This may only be performed if the file is non-empty, to avoid out-of-bounds indexing.</p>
+
+<h3 id="split-file-at-each-newline-1">+ Split file at each newline:</h3>
+
+<pre><code>if ((buffer.items.len &#62; 0) and std.mem.eql(u8, buffer.items[buffer.items.len - 1], "")) {
+ _ = buffer.pop();
+}
+</code></pre>
+
+<p>We define the configuration command searching function, which returns a list containing the segments of the split format string. The function will return from within the for loop if the declaration is found, otherwise an error is reported.</p>
+
+<h3 id="configuration-searching-function">Configuration searching function:</h3>
+
+<pre><code>pub fn get_conf(lines: [][]const u8, key: []const u8, alloc: Allocator) ![][]const u8 {
+ for (lines) |line| {
+ if (std.mem.startsWith(u8, line, key)) {
+ return try fmt_conf(line, key, alloc);
+ }
+ }
+ log(.err, "config declaration &#39;{s}&#39; not found", .{std.mem.trimRight(u8, key, " \t")});
+ return error.NotFound;
+}
+
+<span class="ref" >(Auxiliary formatting function)</span>
+</code></pre>
+
+<p>If the declaration is found, its contained format string is split along instances of the section name escape sequence, and each substring has its instances of the newline escape sequence replaced with a literal newline.</p>
+
+<h3 id="auxiliary-formatting-function">Auxiliary formatting function:</h3>
+
+<pre><code>fn fmt_conf(line: []const u8, key: []const u8, alloc: Allocator) ![][]const u8 {
+ var buffer = std.ArrayList([]const u8).init(alloc);
+ defer buffer.deinit();
+
+ var iterator = std.mem.split(u8, line[(key.len)..], kc_esc);
+ while (iterator.next()) |str| {
+ try buffer.append(try std.mem.replaceOwned(u8, alloc, str, kc_nl, "\n"));
+ }
+
+ return buffer.toOwnedSlice();
+}
+</code></pre>
+
+<p>We define the code section searching function, which returns the index (into the section list) of the first section with a matching name, or returns an error if none exist.</p>
+
+<h3 id="section-searching-function">Section searching function:</h3>
+
+<pre><code>fn search(list: []Section, name: []const u8) !usize {
+ for (list) |section, index| {
+ if (std.mem.eql(u8, section.name, name)) return index;
+ }
+ log(.err, "section &#39;{s}&#39; not found", .{name});
+ return error.NotFound;
+}
+&#47;&#47; TODO return last match instead?
+</code></pre>
+
+<h2 id="parsing">Parsing</h2>
+
+<p>We then define the parsing functions, consisting of the main <code>parse</code> function which builds the list of <code>Section</code>s, and its auxiliary <code>parse_code</code> subroutine which builds the contents of each <code>CodeSection</code>.</p>
+
+<h3 id="parsing-functions">Parsing functions:</h3>
+
+<pre><code>pub fn parse(lines: [][]const u8, alloc: Allocator) ![]Section {
+ var sections = std.ArrayList(Section).init(alloc);
+ defer sections.deinit();
+
+ <span class="ref" >(Main parsing routine)</span>
+
+ return sections.toOwnedSlice();
+}
+
+fn parse_code(lines: [][]const u8, index: u32, alloc: Allocator) !CodeReturn {
+ var content = std.ArrayList(Content).init(alloc);
+ defer content.deinit();
+
+ <span class="ref" >(Code parsing subroutine)</span>
+
+ return CodeReturn{ .content = content.toOwnedSlice(), .index = i + 1 };
+}
+</code></pre>
+
+<p>The latter function takes as arguments the list of lines and the allocator similarly to the main function, but it is also passed the index of the current line being processed, and returns the line at which the main function should resume parsing after the code section is parsed. It thus returns a struct consisting of the contents of the code section and the next line number index, as follows.</p>
+
+<h3 id="parsing-functions-1">+ Parsing functions:</h3>
+
+<pre><code>const CodeReturn = struct {
+ content: []const Content,
+ index: u32,
+};
+</code></pre>
+
+<p>The main parsing routine iterates over the list of lines, adding code sections where they occur, and otherwise ignoring text sections. If a section end command is encountered in the absence of a preceding starting command, an error is returned.</p>
+
+<h3 id="main-parsing-routine">Main parsing routine:</h3>
+
+<pre><code>var i: u32 = 0;
+while (i &#60; lines.len) {
+ const line = lines[i];
+ if (std.mem.startsWith(u8, line, k_start)) {
+ <span class="ref" >(Add new section)</span>
+ } else if (std.mem.startsWith(u8, line, k_add)) {
+ <span class="ref" >(Append to section)</span>
+ } else if (std.mem.eql(u8, line, k_end)) {
+ log(.err, "line {d}: unexpected section end", .{i + 1});
+ return error.UnexpectedEnd;
+ } else {
+ i += 1;
+ }
+}
+</code></pre>
+
+<p>To add a new section, the name (consisting of everything after the starting token) is first retrieved from the starting command. Then the code parsing subroutine is called, beginning at the line after the starting command, and it returns the resulting code section (<code>section.content</code>) and the next line at which to resume parsing (<code>section.index</code>). The code section is appended to the section list, and the parsing routine continues at the provided index.</p>
+
+<h3 id="add-new-section">Add new section:</h3>
+
+<pre><code>const name = line[(k_start.len)..];
+log(.debug, "({d}) starting section &#39;{s}&#39;", .{ i + 1, name });
+
+const section = try parse_code(lines, i + 1, alloc);
+try sections.append(.{ .name = name, .content = section.content });
+
+log(.debug, "({d}) ending section &#39;{s}&#39;", .{ section.index, name });
+i = section.index;
+</code></pre>
+
+<p>To append to an existing section, the section name and the code section contents to be appended are retrieved as above. The index of the section is located, along with its address within the section list. Next, the new contents of the section are created by concatenating the old contents with the newly parsed code section contents. The section list is then updated to point to the new section contents, and the parsing routine continues.</p>
+
+<h3 id="append-to-section">Append to section:</h3>
+
+<pre><code>const name = line[(k_add.len)..];
+log(.debug, "({d}) appending to section &#39;{s}&#39;", .{ i + 1, name });
+
+const section = try parse_code(lines, i + 1, alloc);
+const index = try search(sections.items, name);
+const old = &#38;sections.items[index];
+const new = try std.mem.concat(alloc, Content, &#38;[_][]const Content{ old.*.content, section.content });
+old.*.content = new;
+
+log(.debug, "({d}) ending section &#39;{s}&#39;", .{ section.index, name });
+i = section.index;
+</code></pre>
+
+<p>The code parsing subroutine iterates over the list of lines similarly to the main routine. If a starting or appending command is encountered (lacking a matching ending command), an error is raised. Reference commands may be preceded with any amount of whitespace. The loop exits upon encountering an ending command. Otherwise, the line is appended as a literal element.</p>
+
+<h3 id="code-parsing-subroutine">Code parsing subroutine:</h3>
+
+<pre><code>var i = index;
+while (i &#60; lines.len) {
+ const line = lines[i];
+ if (std.mem.startsWith(u8, line, k_start) or std.mem.startsWith(u8, line, k_add)) {
+ log(.err, "line {d}: unexpected section start", .{i + 1});
+ return error.UnexpectedStart;
+ } else if (std.mem.startsWith(u8, std.mem.trimLeft(u8, line, " \t"), k_ref)) {
+ <span class="ref" >(Add reference)</span>
+ } else if (std.mem.eql(u8, line, k_end)) {
+ break;
+ } else {
+ <span class="ref" >(Add literal range)</span>
+ }
+}
+</code></pre>
+
+<p>To add a reference, the name of the referenced section is retrieved, consisting of the characters following the leading whitespace and the command token. The resulting string is appended to the section contents list, and the parser continues at the next line.</p>
+
+<h3 id="add-reference">Add reference:</h3>
+
+<pre><code>const ref_name = std.mem.trimLeft(u8, line, " \t")[(k_ref.len)..];
+try content.append(.{ .reference = ref_name });
+log(.debug, "({d}) \tappended reference &#39;{s}&#39;", .{ i + 1, ref_name });
+i += 1;
+</code></pre>
+
+<p>To add a literal range, the parser either updates the end index of the previous literal element, or creates a new literal element if the last element added is a reference. This action of switching on the previous section element must only occur if the section contents list is non-empty, in order to prevent out-of-bounds indexing. Otherwise, the parser unconditionally appends a new literal element to the list. After either case, parsing continues at the next line.</p>
+
+<h3 id="add-literal-range">Add literal range:</h3>
+
+<pre><code>if (content.items.len &#62; 0) {
+ switch (content.items[content.items.len - 1]) {
+ .literal =&#62; |*range| {
+ range.*.end = i;
+ },
+ .reference =&#62; {
+ try content.append(.{ .literal = .{ .start = i, .end = i } });
+ log(.debug, "({d}) \tappending literal", .{i + 1});
+ },
+ }
+} else {
+ try content.append(.{ .literal = .{ .start = i, .end = i } });
+ log(.debug, "({d}) \tappending literal", .{i + 1});
+}
+i += 1;
+</code></pre>
+
+<h2 id="code-generation">Code Generation</h2>
+
+<p>We define the source code generation procedure which is split into two functions, consisting of a wrapper function which begins code generation at (the index of) the top-level section, and the main procedure which iterates over the current section contents, recursively resolving section references and appending literal elements to the list of source code lines.</p>
+
+<h3 id="code-generation-functions">Code generation functions:</h3>
+
+<pre><code>pub fn codegen(lines: [][]const u8, list: []Section, alloc: Allocator) ![][]const u8 {
+ const root = try search(list, k_root);
+ return try codegen_main(lines, list, root, 0, alloc);
+}
+
+fn codegen_main(lines: [][]const u8, list: []Section, index: usize, depth: u8, alloc: Allocator) anyerror![][]const u8 {
+ var buffer = std.ArrayList([]const u8).init(alloc);
+ defer buffer.deinit();
+
+ const section = list[index];
+ log(.debug, "generating section &#39;{s}&#39;", .{section.name});
+ for (section.content) |content| switch (content) {
+ .literal =&#62; |range| {
+ <span class="ref" >(Append literal range)</span>
+ },
+ .reference =&#62; |name| {
+ <span class="ref" >(Resolve reference)</span>
+ },
+ };
+
+ log(.debug, "ending section &#39;{s}&#39;", .{section.name});
+ return buffer.toOwnedSlice();
+}
+</code></pre>
+
+<p>To append a literal range, the range of lines is simply appended to the buffer.</p>
+
+<h3 id="append-literal-range">Append literal range:</h3>
+
+<pre><code>log(.debug, "adding literal range {d}-{d}", .{ range.start + 1, range.end + 1 });
+try buffer.appendSlice(lines[(range.start)..(range.end + 1)]);
+</code></pre>
+
+<p>To resolve a section reference, the function must first check whether the current recursion depth has exceeded the configured limit, and return an error if this occurs. Otherwise, the index of the referenced section is retrieved, its contents are recursively parsed (with an incremented recursion depth), and the resulting source code lines are appended to the buffer.</p>
+
+<h3 id="resolve-reference">Resolve reference:</h3>
+
+<pre><code>if (depth &#62; dereference_max) {
+ log(.err, "section dereferencing recursion depth exceeded (max {d})", .{dereference_max});
+ return error.DereferenceLimit;
+}
+const ref = try search(list, name);
+const code = try codegen_main(lines, list, ref, depth + 1, alloc);
+try buffer.appendSlice(code);
+</code></pre>
+
+<h2 id="text-generation">Text Generation</h2>
+
+<p>Finally, we define the text generation function which iterates over the list of lines and produces the literate program text to be passed to an external document processor. In order to keep track of the name of the code section currently being formatted at any given point, the variable <code>current_name</code> is continually updated to contain the current name string. Configuration declarations are skipped, and lines which do not contain any formatting commands are appended as they are.</p>
+
+<h3 id="text-generation-function">Text generation function:</h3>
+
+<pre><code>pub fn textgen(lines: [][]const u8, alloc: Allocator) ![][]const u8 {
+ var buffer = std.ArrayList([]const u8).init(alloc);
+ defer buffer.deinit();
+
+ <span class="ref" >(Process configuration declarations)</span>
+
+ var current_name: []const u8 = undefined;
+ for (lines) |line| {
+ if ( std.mem.startsWith(u8, line, kc_start)
+ or std.mem.startsWith(u8, line, kc_add)
+ or std.mem.startsWith(u8, line, kc_end)
+ or std.mem.startsWith(u8, line, kc_ref)) {
+ continue;
+ } else if (std.mem.startsWith(u8, line, k_start)) {
+ <span class="ref" >(Format starting command)</span>
+ } else if (std.mem.startsWith(u8, line, k_add)) {
+ <span class="ref" >(Format appending command)</span>
+ } else if (std.mem.startsWith(u8, line, k_end)) {
+ <span class="ref" >(Format ending command)</span>
+ } else if (std.mem.startsWith(u8, std.mem.trimLeft(u8, line, " \t"), k_ref)) {
+ <span class="ref" >(Format reference command)</span>
+ } else {
+ try buffer.append(line);
+ }
+ }
+
+ return buffer.toOwnedSlice();
+}
+</code></pre>
+
+<p>The formatting strings given by each configuration declaration are first retrieved. If the declaration of the format string for the section appending command is omitted, the format string for the section starting command is used in its place.</p>
+
+<h3 id="process-configuration-declarations">Process configuration declarations:</h3>
+
+<pre><code>const conf_start = try get_conf(lines, kc_start, alloc);
+const conf_add = get_conf(lines, kc_add, alloc) catch conf_start;
+const conf_end = try get_conf(lines, kc_end, alloc);
+const conf_ref = try get_conf(lines, kc_ref, alloc);
+</code></pre>
+
+<p>To process a section starting command, the current section name is updated, and the contents of the corresponding formatting command (that is, the segments of the split formatting string) are interspersed with copies of the current section name. The resulting string is then appended to the buffer.</p>
+
+<h3 id="format-starting-command">Format starting command:</h3>
+
+<pre><code>current_name = line[(k_start.len)..];
+try buffer.append(try std.mem.join(alloc, current_name, conf_start));
+</code></pre>
+
+<p>Processing a section appending command is performed similarly.</p>
+
+<h3 id="format-appending-command">Format appending command:</h3>
+
+<pre><code>current_name = line[(k_add.len)..];
+try buffer.append(try std.mem.join(alloc, current_name, conf_add));
+</code></pre>
+
+<p>Processing a section ending command, however, does not require updating the current section name.</p>
+
+<h3 id="format-ending-command">Format ending command:</h3>
+
+<pre><code>try buffer.append(try std.mem.join(alloc, current_name, conf_end));
+</code></pre>
+
+<p>To process a reference command, the index of the reference command keyword is first extracted. Then the formatted reference string is created, to which the reference command line&#8217;s leading whitespace is prepended (to preserve indentation). </p>
+
+<h3 id="format-reference-command">Format reference command:</h3>
+
+<pre><code>const start = std.mem.indexOf(u8, line, k_ref).?;
+const ref = try std.mem.join(alloc, line[(start + k_ref.len)..], conf_ref);
+try buffer.append(try std.mem.concat(alloc, u8, &#38;[_][]const u8{ line[0..start], ref }));
+</code></pre>
+</body>
+</html> \ No newline at end of file
diff --git a/doc/freestanding/log.html b/doc/freestanding/log.html
new file mode 100644
index 0000000..003daf7
--- /dev/null
+++ b/doc/freestanding/log.html
@@ -0,0 +1,102 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<style>
+* {box-sizing: border-box;}
+html {
+--fs-sans: Helvetica, "Helvetica Neue", Arial, "San Francisco", sans;
+--fs-mono: jetbrains-mono-regular, Consolas, Menlo, monospace;
+font-size: 16px;
+}
+body {background-color: #111; color: #ddd; margin: 2rem calc(50% - 32rem); font-family: var(--fs-sans); font-size: 1rem; font-style: normal;}
+body * {line-height: 1.5; text-align: justify; text-justify: inter-word;}
+h1,h2 {font-family: var(--fs-sans); margin: 2rem 0 1rem; font-weight: bold; line-height: 1;}
+h1 {font-size: 3rem;}
+h2 {font-size: 2rem;}
+h3 {margin: 1rem; font-size: 1rem; font-weight: normal; font-style: italic;}
+code,code * {font-family: var(--fs-mono); hyphens: none; line-height: 1.25rem;}
+body>pre {background-color: #000; margin: 1rem; padding: 1rem; white-space: pre-wrap; border-radius: 0.25rem;}
+ul,ol {margin: 1rem 0; padding: 0 0 0 2rem;}
+ul ul,ol ol {margin: 0;}
+.ref {font-family: var(--fs-sans); font-style: italic;}
+@media screen and (max-width: 68rem) {body {margin: 2rem calc(50% - 24rem);}}
+@media screen and (max-width: 52rem) {body {margin: 2rem calc(50% - 16rem);}}
+@media screen and (max-width: 36rem) {body {margin: 2rem; hyphens: auto;} h3,body>pre {margin: 1rem 0;}}
+</style>
+</head>
+
+<body>
+<h1 id="log.zig">log.zig</h1>
+
+<p>This file contains a simple logging function. It is a modified version of the example logging function implementation provided in <code>std.log</code>.</p>
+
+<h3 id="section">*:</h3>
+
+<pre><code><span class="ref" >(Imports)</span>
+
+<span class="ref" >(Level setting)</span>
+
+<span class="ref" >(Logging function)</span>
+</code></pre>
+
+<p>We first import the standard library, and the <code>Level</code> type which is an enum representing the possible log levels.</p>
+
+<h3 id="imports">Imports:</h3>
+
+<pre><code>const std = @import("std");
+const Level = std.log.Level;
+</code></pre>
+
+<p>The logging function is structured such that only log messages equal to or above a certain severity threshold will be printed to the console. This threshold can then be globally modified during development. The threshold constant is defined below.</p>
+
+<h3 id="level-setting">Level setting:</h3>
+
+<pre><code>pub const log_level: Level = .warn;
+</code></pre>
+
+<p>We then define the logging function itself, which accepts a <code>Level</code> value and the format string and argument struct to be passed to the inner print function.</p>
+
+<h3 id="logging-function">Logging function:</h3>
+
+<pre><code>pub fn log(
+ comptime level: Level,
+ comptime format: []const u8,
+ args: anytype,
+) void {
+ <span class="ref" >(Compare with level threshold)</span>
+
+ <span class="ref" >(Define message string)</span>
+
+ <span class="ref" >(Print to console)</span>
+}
+</code></pre>
+
+<p>First the comparison against the severity threshold is made. (A lower integer value signifies a higher severity.) If the severity is lower than the threshold, the function immediately exits.</p>
+
+<h3 id="compare-with-level-threshold">Compare with level threshold:</h3>
+
+<pre><code>if (@enumToInt(level) &#62; @enumToInt(log_level)) return;
+</code></pre>
+
+<p>Next the message string is created. The unformatted content of this string is evaluated at compile-time, before being formatted by the print function at runtime. The &#8220;info&#8221; and &#8220;error&#8221; log levels use custom names, whereas all other levels use their default display names.</p>
+
+<h3 id="define-message-string">Define message string:</h3>
+
+<pre><code>const msg = "[" ++ switch (level) {
+ .info =&#62; "ok",
+ .err =&#62; "err",
+ else =&#62; level.asText(),
+} ++ "]\t" ++ format ++ "\n";
+</code></pre>
+
+<p>Finally, the message is printed to the console. If an error is returned by the <code>print()</code> call, the logging function silently exits.</p>
+
+<h3 id="print-to-console">Print to console:</h3>
+
+<pre><code>const stderr = std.io.getStdErr().writer();
+nosuspend stderr.print(msg, args) catch return;
+</code></pre>
+</body>
+</html> \ No newline at end of file
diff --git a/doc/freestanding/tangle.html b/doc/freestanding/tangle.html
new file mode 100644
index 0000000..aaad088
--- /dev/null
+++ b/doc/freestanding/tangle.html
@@ -0,0 +1,141 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<style>
+* {box-sizing: border-box;}
+html {
+--fs-sans: Helvetica, "Helvetica Neue", Arial, "San Francisco", sans;
+--fs-mono: jetbrains-mono-regular, Consolas, Menlo, monospace;
+font-size: 16px;
+}
+body {background-color: #111; color: #ddd; margin: 2rem calc(50% - 32rem); font-family: var(--fs-sans); font-size: 1rem; font-style: normal;}
+body * {line-height: 1.5; text-align: justify; text-justify: inter-word;}
+h1,h2 {font-family: var(--fs-sans); margin: 2rem 0 1rem; font-weight: bold; line-height: 1;}
+h1 {font-size: 3rem;}
+h2 {font-size: 2rem;}
+h3 {margin: 1rem; font-size: 1rem; font-weight: normal; font-style: italic;}
+code,code * {font-family: var(--fs-mono); hyphens: none; line-height: 1.25rem;}
+body>pre {background-color: #000; margin: 1rem; padding: 1rem; white-space: pre-wrap; border-radius: 0.25rem;}
+ul,ol {margin: 1rem 0; padding: 0 0 0 2rem;}
+ul ul,ol ol {margin: 0;}
+.ref {font-family: var(--fs-sans); font-style: italic;}
+@media screen and (max-width: 68rem) {body {margin: 2rem calc(50% - 24rem);}}
+@media screen and (max-width: 52rem) {body {margin: 2rem calc(50% - 16rem);}}
+@media screen and (max-width: 36rem) {body {margin: 2rem; hyphens: auto;} h3,body>pre {margin: 1rem 0;}}
+</style>
+</head>
+
+<body>
+<h1 id="tangle.zig">tangle.zig</h1>
+
+<p>The structure of this file is quite similar to that of <code>weave.zig</code>, only differing in terms of which functions are used to transform the input data.</p>
+
+<h3 id="section">*:</h3>
+
+<pre><code><span class="ref" >(Imports)</span>
+
+pub fn main() !u8 {
+ <span class="ref" >(IO initialization)</span>
+
+ <span class="ref" >(Allocator initialization)</span>
+
+ <span class="ref" >(Read file from stdin)</span>
+
+ <span class="ref" >(Split into lines)</span>
+
+ <span class="ref" >(Parse lines into sections)</span>
+
+ <span class="ref" >(Generate code)</span>
+
+ <span class="ref" >(Write to stdout)</span>
+
+ return 0;
+}
+</code></pre>
+
+<p>First we import the other files containing the core functions.</p>
+
+<h3 id="imports">Imports:</h3>
+
+<pre><code>const std = @import("std");
+const data = @import("data.zig");
+const log = @import("log.zig").log;
+
+const Allocator = std.mem.Allocator;
+</code></pre>
+
+<p>Within the main procedure, we first initialize the stdin and stdout interfaces.</p>
+
+<h3 id="io-initialization">IO initialization:</h3>
+
+<pre><code>const stdin = std.io.getStdIn();
+const stdout = std.io.getStdOut();
+</code></pre>
+
+<p>We then initialize the allocator, deferring its deinitialization to the end of the process. Since the overall memory usage pattern is one in which all resources may be freed at once, the arena allocator is the most appropriate choice for this program.</p>
+
+<h3 id="allocator-initialization">Allocator initialization:</h3>
+
+<pre><code>var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
+var alloc = arena.allocator();
+defer arena.deinit();
+</code></pre>
+
+<p>The input file is then read from stdin. In the case of input exceeding the maximum permitted file size, the program may report the error and exit normally. All other errors which may be returned are memory allocation failures and should thus yield control to the panic handler.</p>
+
+<h3 id="read-file-from-stdin">Read file from stdin:</h3>
+
+<pre><code>const input = stdin.reader().readAllAlloc(alloc, data.input_max) catch |err| switch (err) {
+ error.StreamTooLong =&#62; {
+ log(.err, "input too large (maximum {})", .{std.fmt.fmtIntSizeBin(data.input_max)});
+ return 1;
+ },
+ else =&#62; |e| return e,
+};
+</code></pre>
+
+<p>We then pass the input into the line splitting function, creating an array of strings.</p>
+
+<h3 id="split-into-lines">Split into lines:</h3>
+
+<pre><code>const lines = try data.split_lines(input, alloc);
+</code></pre>
+
+<p>The lines are then passed into the parsing function, which may return a parsing error. Logging such errors is handled by the function itself, and thus the errors are handled here solely by exiting.</p>
+
+<h3 id="parse-lines-into-sections">Parse lines into sections:</h3>
+
+<pre><code>const sections = data.parse(lines, alloc) catch |err| switch (err) {
+ error.UnexpectedStart,
+ error.UnexpectedEnd =&#62; {
+ return 1;
+ },
+ else =&#62; |e| return e,
+};
+</code></pre>
+
+<p>The code file is then generated. This entails resolving references to section names, which may return an error, handled by exiting as above.</p>
+
+<h3 id="generate-code">Generate code:</h3>
+
+<pre><code>const code = data.codegen(lines, sections, alloc) catch |err| switch (err) {
+ error.DereferenceLimit,
+ error.NotFound =&#62; {
+ return 1;
+ },
+ else =&#62; |e| return e,
+};
+</code></pre>
+
+<p>Finally, the lines of the code file are written to stdout, separated by newlines.</p>
+
+<h3 id="write-to-stdout">Write to stdout:</h3>
+
+<pre><code>for (code) |line| {
+ try stdout.writer().print("{s}\n", .{line});
+}
+</code></pre>
+</body>
+</html> \ No newline at end of file
diff --git a/doc/freestanding/weave.html b/doc/freestanding/weave.html
new file mode 100644
index 0000000..5a10177
--- /dev/null
+++ b/doc/freestanding/weave.html
@@ -0,0 +1,125 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<style>
+* {box-sizing: border-box;}
+html {
+--fs-sans: Helvetica, "Helvetica Neue", Arial, "San Francisco", sans;
+--fs-mono: jetbrains-mono-regular, Consolas, Menlo, monospace;
+font-size: 16px;
+}
+body {background-color: #111; color: #ddd; margin: 2rem calc(50% - 32rem); font-family: var(--fs-sans); font-size: 1rem; font-style: normal;}
+body * {line-height: 1.5; text-align: justify; text-justify: inter-word;}
+h1,h2 {font-family: var(--fs-sans); margin: 2rem 0 1rem; font-weight: bold; line-height: 1;}
+h1 {font-size: 3rem;}
+h2 {font-size: 2rem;}
+h3 {margin: 1rem; font-size: 1rem; font-weight: normal; font-style: italic;}
+code,code * {font-family: var(--fs-mono); hyphens: none; line-height: 1.25rem;}
+body>pre {background-color: #000; margin: 1rem; padding: 1rem; white-space: pre-wrap; border-radius: 0.25rem;}
+ul,ol {margin: 1rem 0; padding: 0 0 0 2rem;}
+ul ul,ol ol {margin: 0;}
+.ref {font-family: var(--fs-sans); font-style: italic;}
+@media screen and (max-width: 68rem) {body {margin: 2rem calc(50% - 24rem);}}
+@media screen and (max-width: 52rem) {body {margin: 2rem calc(50% - 16rem);}}
+@media screen and (max-width: 36rem) {body {margin: 2rem; hyphens: auto;} h3,body>pre {margin: 1rem 0;}}
+</style>
+</head>
+
+<body>
+<h1 id="weave.zig">weave.zig</h1>
+
+<p>The structure of this file is quite similar to that of <code>tangle.zig</code>, only differing in terms of which functions are used to transform the input data.</p>
+
+<h3 id="section">*:</h3>
+
+<pre><code><span class="ref" >(Imports)</span>
+
+pub fn main() !u8 {
+ <span class="ref" >(IO initialization)</span>
+
+ <span class="ref" >(Allocator initialization)</span>
+
+ <span class="ref" >(Read file from stdin)</span>
+
+ <span class="ref" >(Split into lines)</span>
+
+ <span class="ref" >(Generate text)</span>
+
+ <span class="ref" >(Write to stdout)</span>
+
+ return 0;
+}
+</code></pre>
+
+<p>First we import the other files containing the core functions.</p>
+
+<h3 id="imports">Imports:</h3>
+
+<pre><code>const std = @import("std");
+const data = @import("data.zig");
+const log = @import("log.zig").log;
+
+const Allocator = std.mem.Allocator;
+</code></pre>
+
+<p>Within the main procedure, we first initialize the stdin and stdout interfaces.</p>
+
+<h3 id="io-initialization">IO initialization:</h3>
+
+<pre><code>const stdin = std.io.getStdIn();
+const stdout = std.io.getStdOut();
+</code></pre>
+
+<p>We then initialize the allocator, deferring its deinitialization to the end of the process. Since the overall memory usage pattern is one in which all resources may be freed at once, the arena allocator is the most appropriate choice for this program.</p>
+
+<h3 id="allocator-initialization">Allocator initialization:</h3>
+
+<pre><code>var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
+var alloc = arena.allocator();
+defer arena.deinit();
+</code></pre>
+
+<p>The input file is then read from stdin. In the case of input exceeding the maximum permitted file size, the program may report the error and exit normally. All other errors which may be returned are memory allocation failures and should thus yield control to the panic handler.</p>
+
+<h3 id="read-file-from-stdin">Read file from stdin:</h3>
+
+<pre><code>const input = stdin.reader().readAllAlloc(alloc, data.input_max) catch |err| switch (err) {
+ error.StreamTooLong =&#62; {
+ log(.err, "input too large (maximum {})", .{std.fmt.fmtIntSizeBin(data.input_max)});
+ return 1;
+ },
+ else =&#62; |e| return e,
+};
+</code></pre>
+
+<p>We then pass the input into the line splitting function, creating an array of strings.</p>
+
+<h3 id="split-into-lines">Split into lines:</h3>
+
+<pre><code>const lines = try data.split_lines(input, alloc);
+</code></pre>
+
+<p>The text file is then generated. This entails searching for the configuration declarations, which may fail and thus return an error. Logging such errors is handled by the function itself, and thus the errors are handled here solely by exiting.</p>
+
+<h3 id="generate-text">Generate text:</h3>
+
+<pre><code>const text = data.textgen(lines, alloc) catch |err| switch (err) {
+ error.NotFound =&#62; {
+ return 1;
+ },
+ else =&#62; |e| return e,
+};
+</code></pre>
+
+<p>Finally, the lines of the text file are written to stdout, separated by newlines.</p>
+
+<h3 id="write-to-stdout">Write to stdout:</h3>
+
+<pre><code>for (text) |line| {
+ try stdout.writer().print("{s}\n", .{line});
+}
+</code></pre>
+</body>
+</html> \ No newline at end of file
diff --git a/doc/header b/doc/header
new file mode 100644
index 0000000..fcecc47
--- /dev/null
+++ b/doc/header
@@ -0,0 +1,8 @@
+title:
+leading:
+opts: h
+
+@start ### @@:\n```
+@add ### + @@:\n```
+@end ```
+@ref @= @@ =@
diff --git a/doc/log.html b/doc/log.html
index f82d41e..5a538c3 100644
--- a/doc/log.html
+++ b/doc/log.html
@@ -3,42 +3,32 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
-<style>
-* {box-sizing: border-box;}
-html {
---fs-sans: Helvetica, "Helvetica Neue", Arial, "San Francisco", sans;
---fs-mono: jetbrains-mono-regular, Consolas, Menlo, monospace;
-font-size: 16px;
-}
-body {background-color: #111; color: #ddd; margin: 2rem calc(50% - 32rem); font-family: var(--fs-sans); font-size: 1rem; font-style: normal;}
-body * {line-height: 1.5; text-align: justify; text-justify: inter-word;}
-h1,h2 {font-family: var(--fs-sans); margin: 2rem 0 1rem; font-weight: bold; line-height: 1;}
-h1 {font-size: 3rem;}
-h2 {font-size: 2rem;}
-h3 {margin: 1rem; font-size: 1rem; font-weight: normal; font-style: italic;}
-code,code * {font-family: var(--fs-mono); hyphens: none; line-height: 1.25rem;}
-body>pre {background-color: #000; margin: 1rem; padding: 1rem; white-space: pre-wrap; border-radius: 0.25rem;}
-ul,ol {margin: 1rem 0; padding: 0 0 0 2rem;}
-ul ul,ol ol {margin: 0;}
-.ref {font-family: var(--fs-sans); font-style: italic;}
-@media screen and (max-width: 68rem) {body {margin: 2rem calc(50% - 24rem);}}
-@media screen and (max-width: 52rem) {body {margin: 2rem calc(50% - 16rem);}}
-@media screen and (max-width: 36rem) {body {margin: 2rem; hyphens: auto;} h3,body>pre {margin: 1rem 0}}
-</style>
+<link rel="stylesheet" href="/fonts/fonts.css">
+<link rel="stylesheet" href="/css/main.css">
+<link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png">
+<link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png">
+<link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png">
+<link rel="manifest" href="/favicon/site.webmanifest">
+<title>log.lp &mdash; DistressNetwork°</title>
+<meta http-equiv="last-modified" content="2022-03-31 23:28:57-04:00" />
+<style>.lp-ref {font-family: neue-haas-grotesk-text, var(--fs-sans); font-style: italic;}</style>
</head>
-
<body>
+<div class="contentlevel">
+<main>
+<div class="leading">log.lp</div>
+<hr>
<h1 id="log.zig">log.zig</h1>
<p>This file contains a simple logging function. It is a modified version of the example logging function implementation provided in <code>std.log</code>.</p>
<h3 id="section">*:</h3>
-<pre><code><span class="ref" >(Imports)</span>
+<pre><code><span class="lp-ref">(Imports)</span>
-<span class="ref" >(Level setting)</span>
+<span class="lp-ref">(Level setting)</span>
-<span class="ref" >(Logging function)</span>
+<span class="lp-ref">(Logging function)</span>
</code></pre>
<p>We first import the standard library, and the <code>Level</code> type which is an enum representing the possible log levels.</p>
@@ -65,11 +55,11 @@ const Level = std.log.Level;
comptime format: []const u8,
args: anytype,
) void {
- <span class="ref" >(Compare with level threshold)</span>
+ <span class="lp-ref">(Compare with level threshold)</span>
- <span class="ref" >(Define message string)</span>
+ <span class="lp-ref">(Define message string)</span>
- <span class="ref" >(Print to console)</span>
+ <span class="lp-ref">(Print to console)</span>
}
</code></pre>
@@ -98,5 +88,13 @@ const Level = std.log.Level;
<pre><code>const stderr = std.io.getStdErr().writer();
nosuspend stderr.print(msg, args) catch return;
</code></pre>
+</main>
+<nav>
+</nav>
+</div>
+<footer>
+<p><a href="/info">About.</a> <a href="mailto:uplink@distress.network">Contact.</a> <a href="/cw.html">Content Warning.</a> <a href="https://git.distress.network">Git.</a> <a href="/meta/sitemap">Sitemap.</a> <a href="https://creativecommons.org/licenses/by-sa/4.0">CC BY-SA 4.0.</a></p>
+<img src="/media/distressnetwork-w.svg" alt="">
+</footer>
</body>
-</html> \ No newline at end of file
+</html>
diff --git a/doc/tangle.html b/doc/tangle.html
index 1c26eae..b8269a3 100644
--- a/doc/tangle.html
+++ b/doc/tangle.html
@@ -3,53 +3,43 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
-<style>
-* {box-sizing: border-box;}
-html {
---fs-sans: Helvetica, "Helvetica Neue", Arial, "San Francisco", sans;
---fs-mono: jetbrains-mono-regular, Consolas, Menlo, monospace;
-font-size: 16px;
-}
-body {background-color: #111; color: #ddd; margin: 2rem calc(50% - 32rem); font-family: var(--fs-sans); font-size: 1rem; font-style: normal;}
-body * {line-height: 1.5; text-align: justify; text-justify: inter-word;}
-h1,h2 {font-family: var(--fs-sans); margin: 2rem 0 1rem; font-weight: bold; line-height: 1;}
-h1 {font-size: 3rem;}
-h2 {font-size: 2rem;}
-h3 {margin: 1rem; font-size: 1rem; font-weight: normal; font-style: italic;}
-code,code * {font-family: var(--fs-mono); hyphens: none; line-height: 1.25rem;}
-body>pre {background-color: #000; margin: 1rem; padding: 1rem; white-space: pre-wrap; border-radius: 0.25rem;}
-ul,ol {margin: 1rem 0; padding: 0 0 0 2rem;}
-ul ul,ol ol {margin: 0;}
-.ref {font-family: var(--fs-sans); font-style: italic;}
-@media screen and (max-width: 68rem) {body {margin: 2rem calc(50% - 24rem);}}
-@media screen and (max-width: 52rem) {body {margin: 2rem calc(50% - 16rem);}}
-@media screen and (max-width: 36rem) {body {margin: 2rem; hyphens: auto;} h3,body>pre {margin: 1rem 0}}
-</style>
+<link rel="stylesheet" href="/fonts/fonts.css">
+<link rel="stylesheet" href="/css/main.css">
+<link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png">
+<link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png">
+<link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png">
+<link rel="manifest" href="/favicon/site.webmanifest">
+<title>tangle.lp &mdash; DistressNetwork°</title>
+<meta http-equiv="last-modified" content="2022-03-31 23:28:57-04:00" />
+<style>.lp-ref {font-family: neue-haas-grotesk-text, var(--fs-sans); font-style: italic;}</style>
</head>
-
<body>
+<div class="contentlevel">
+<main>
+<div class="leading">tangle.lp</div>
+<hr>
<h1 id="tangle.zig">tangle.zig</h1>
<p>The structure of this file is quite similar to that of <code>weave.zig</code>, only differing in terms of which functions are used to transform the input data.</p>
<h3 id="section">*:</h3>
-<pre><code><span class="ref" >(Imports)</span>
+<pre><code><span class="lp-ref">(Imports)</span>
pub fn main() !u8 {
- <span class="ref" >(IO initialization)</span>
+ <span class="lp-ref">(IO initialization)</span>
- <span class="ref" >(Allocator initialization)</span>
+ <span class="lp-ref">(Allocator initialization)</span>
- <span class="ref" >(Read file from stdin)</span>
+ <span class="lp-ref">(Read file from stdin)</span>
- <span class="ref" >(Split into lines)</span>
+ <span class="lp-ref">(Split into lines)</span>
- <span class="ref" >(Parse lines into sections)</span>
+ <span class="lp-ref">(Parse lines into sections)</span>
- <span class="ref" >(Generate code)</span>
+ <span class="lp-ref">(Generate code)</span>
- <span class="ref" >(Write to stdout)</span>
+ <span class="lp-ref">(Write to stdout)</span>
return 0;
}
@@ -137,5 +127,13 @@ defer arena.deinit();
try stdout.writer().print("{s}\n", .{line});
}
</code></pre>
+</main>
+<nav>
+</nav>
+</div>
+<footer>
+<p><a href="/info">About.</a> <a href="mailto:uplink@distress.network">Contact.</a> <a href="/cw.html">Content Warning.</a> <a href="https://git.distress.network">Git.</a> <a href="/meta/sitemap">Sitemap.</a> <a href="https://creativecommons.org/licenses/by-sa/4.0">CC BY-SA 4.0.</a></p>
+<img src="/media/distressnetwork-w.svg" alt="">
+</footer>
</body>
-</html> \ No newline at end of file
+</html>
diff --git a/doc/weave.html b/doc/weave.html
index 6aaf6c8..9bfee51 100644
--- a/doc/weave.html
+++ b/doc/weave.html
@@ -3,51 +3,41 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
-<style>
-* {box-sizing: border-box;}
-html {
---fs-sans: Helvetica, "Helvetica Neue", Arial, "San Francisco", sans;
---fs-mono: jetbrains-mono-regular, Consolas, Menlo, monospace;
-font-size: 16px;
-}
-body {background-color: #111; color: #ddd; margin: 2rem calc(50% - 32rem); font-family: var(--fs-sans); font-size: 1rem; font-style: normal;}
-body * {line-height: 1.5; text-align: justify; text-justify: inter-word;}
-h1,h2 {font-family: var(--fs-sans); margin: 2rem 0 1rem; font-weight: bold; line-height: 1;}
-h1 {font-size: 3rem;}
-h2 {font-size: 2rem;}
-h3 {margin: 1rem; font-size: 1rem; font-weight: normal; font-style: italic;}
-code,code * {font-family: var(--fs-mono); hyphens: none; line-height: 1.25rem;}
-body>pre {background-color: #000; margin: 1rem; padding: 1rem; white-space: pre-wrap; border-radius: 0.25rem;}
-ul,ol {margin: 1rem 0; padding: 0 0 0 2rem;}
-ul ul,ol ol {margin: 0;}
-.ref {font-family: var(--fs-sans); font-style: italic;}
-@media screen and (max-width: 68rem) {body {margin: 2rem calc(50% - 24rem);}}
-@media screen and (max-width: 52rem) {body {margin: 2rem calc(50% - 16rem);}}
-@media screen and (max-width: 36rem) {body {margin: 2rem; hyphens: auto;} h3,body>pre {margin: 1rem 0}}
-</style>
+<link rel="stylesheet" href="/fonts/fonts.css">
+<link rel="stylesheet" href="/css/main.css">
+<link rel="apple-touch-icon" sizes="180x180" href="/favicon/apple-touch-icon.png">
+<link rel="icon" type="image/png" sizes="32x32" href="/favicon/favicon-32x32.png">
+<link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png">
+<link rel="manifest" href="/favicon/site.webmanifest">
+<title>weave.lp &mdash; DistressNetwork°</title>
+<meta http-equiv="last-modified" content="2022-03-31 23:28:57-04:00" />
+<style>.lp-ref {font-family: neue-haas-grotesk-text, var(--fs-sans); font-style: italic;}</style>
</head>
-
<body>
+<div class="contentlevel">
+<main>
+<div class="leading">weave.lp</div>
+<hr>
<h1 id="weave.zig">weave.zig</h1>
<p>The structure of this file is quite similar to that of <code>tangle.zig</code>, only differing in terms of which functions are used to transform the input data.</p>
<h3 id="section">*:</h3>
-<pre><code><span class="ref" >(Imports)</span>
+<pre><code><span class="lp-ref">(Imports)</span>
pub fn main() !u8 {
- <span class="ref" >(IO initialization)</span>
+ <span class="lp-ref">(IO initialization)</span>
- <span class="ref" >(Allocator initialization)</span>
+ <span class="lp-ref">(Allocator initialization)</span>
- <span class="ref" >(Read file from stdin)</span>
+ <span class="lp-ref">(Read file from stdin)</span>
- <span class="ref" >(Split into lines)</span>
+ <span class="lp-ref">(Split into lines)</span>
- <span class="ref" >(Generate text)</span>
+ <span class="lp-ref">(Generate text)</span>
- <span class="ref" >(Write to stdout)</span>
+ <span class="lp-ref">(Write to stdout)</span>
return 0;
}
@@ -121,5 +111,13 @@ defer arena.deinit();
try stdout.writer().print("{s}\n", .{line});
}
</code></pre>
+</main>
+<nav>
+</nav>
+</div>
+<footer>
+<p><a href="/info">About.</a> <a href="mailto:uplink@distress.network">Contact.</a> <a href="/cw.html">Content Warning.</a> <a href="https://git.distress.network">Git.</a> <a href="/meta/sitemap">Sitemap.</a> <a href="https://creativecommons.org/licenses/by-sa/4.0">CC BY-SA 4.0.</a></p>
+<img src="/media/distressnetwork-w.svg" alt="">
+</footer>
</body>
-</html> \ No newline at end of file
+</html>
diff --git a/gen-docs.sh b/gen-docs.sh
index 12ab3ac..747af12 100755
--- a/gen-docs.sh
+++ b/gen-docs.sh
@@ -1,9 +1,21 @@
#!/bin/sh -e
+tmp=$(mktemp -p /tmp)
+css=".lp-ref {font-family: neue-haas-grotesk-text, var(--fs-sans); font-style: italic;}"
+
for file in "data" "log" "tangle" "weave" ; do
- cp "doc/header-html" "doc/${file}.html" ;
- cat "doc/header-lp" "${file}.lp" | ./weave | lowdown -Thtml >> "doc/${file}.html" ;
- printf "</body>\n</html>" >> "doc/${file}.html" ;
- sed 's/\(.*\)@= \(.*\) =@/\1<span class="ref" >(\2)<\/span>/1' -i'' "doc/${file}.html" ;
+ in="${file}.lp" ; out="doc/${file}.html" ;
+ cat "doc/header" "$in" | ./weave > "$tmp" ;
+ sed "s;title: ;&${in};1" -i'' "$tmp" ;
+ sed "s;leading: ;&${in};1" -i'' "$tmp" ;
+
+ pushd "../web" > "/dev/null" ;
+ sh "./md.sh" "$tmp" "../literary/$out" > "/dev/null" ;
+ popd > "/dev/null" ;
+ sed "s~</head>~<style>${css}</style>\n&~1" -i'' "$out" ;
+ sed 's;\(.*\)@= \(.*\) =@;\1<span class="lp-ref">(\2)</span>;1' -i'' "$out" ;
+
echo "[ok] generated text '${file}'" ;
done
+
+rm "$tmp"
diff --git a/gen-freestanding.sh b/gen-freestanding.sh
new file mode 100755
index 0000000..53f69ca
--- /dev/null
+++ b/gen-freestanding.sh
@@ -0,0 +1,10 @@
+#!/bin/sh -e
+
+for file in "data" "log" "tangle" "weave" ; do
+ in="${file}.lp" ; out="doc/freestanding/${file}.html" ;
+ cp "doc/header-html" "$out" ;
+ cat "doc/header-lp" "$in" | ./weave | lowdown -Thtml >> "$out" ;
+ printf "</body>\n</html>" >> "$out" ;
+ sed 's/\(.*\)@= \(.*\) =@/\1<span class="ref" >(\2)<\/span>/1' -i'' "$out" ;
+ echo "[ok] generated text '${file}'" ;
+done