diff options
author | eudoxia <uplink@distress.network> | 2022-04-08 00:39:50 -0400 |
---|---|---|
committer | eudoxia <uplink@distress.network> | 2022-04-08 00:39:50 -0400 |
commit | bca585386877d125019b332190d4868c28acff26 (patch) | |
tree | 470b1ddbf26738bee50c21de7d79fead3e4b86c4 | |
parent | 4ae210e0c2593587dbcb07fe5ed3a7ce687b8d1d (diff) |
software/literary: docs syncing
-rwxr-xr-x | software/literary/data.html | 112 | ||||
-rwxr-xr-x | software/literary/log.html | 1 | ||||
-rwxr-xr-x | software/literary/tangle.html | 1 | ||||
-rwxr-xr-x | software/literary/weave.html | 1 |
4 files changed, 75 insertions, 40 deletions
diff --git a/software/literary/data.html b/software/literary/data.html index 66ecb30..7b5e079 100755 --- a/software/literary/data.html +++ b/software/literary/data.html @@ -10,7 +10,6 @@ <link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png"> <link rel="manifest" href="/favicon/site.webmanifest"> <title>data.lp — DistressNetwork°</title> -<meta http-equiv="last-modified" content="2022-04-01 10:35:03-04:00" /> <style>h3,.lp-ref {font-family: neue-haas-grotesk-text, var(--fs-sans); font-size: 1rem; font-weight: normal; font-style: italic;} h3 {margin: 1rem;}</style> </head> <body> @@ -40,6 +39,8 @@ <span class="lp-ref">(Section searching function)</span> +<span class="lp-ref">(Command type detection function)</span> + <span class="lp-ref">(Parsing functions)</span> <span class="lp-ref">(Code generation functions)</span> @@ -146,7 +147,7 @@ pub const LineRange = struct { <h3 id="error-set">Error set:</h3> -<pre><code>pub const Errors = error{ +<pre><code>pub const Errors = error { UnexpectedStart, UnexpectedEnd, DereferenceLimit, @@ -239,6 +240,27 @@ while (iterator.next()) |line| { <h2 id="parsing">Parsing</h2> +<p>We first define a function which, for a given line, determines whether it consists of a formatting command, and which type of command it contains. This is done in order to enable the use of switch statements in later functions using this routine.</p> + +<h3 id="command-type-detection-function">Command type detection function:</h3> + +<pre><code>const CommandType = enum { start, add, end, ref, none }; + +fn command_type(line: []const u8) CommandType { + if (std.mem.startsWith(u8, line, k_start)) { + return .start; + } else if (std.mem.startsWith(u8, line, k_add)) { + return .add; + } else if (std.mem.eql(u8, line, k_end)) { + return .end; + } else if (std.mem.startsWith(u8, std.mem.trimLeft(u8, line, " \t"), k_ref)) { + return .ref; + } else { + return .none; + } +} +</code></pre> + <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> @@ -279,15 +301,20 @@ fn parse_code(lines: [][]const u8, index: u32, alloc: Allocator) !CodeReturn { <pre><code>var i: u32 = 0; while (i < lines.len) { const line = lines[i]; - if (std.mem.startsWith(u8, line, k_start)) { - <span class="lp-ref">(Add new section)</span> - } else if (std.mem.startsWith(u8, line, k_add)) { - <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; - } else { - i += 1; + switch (command_type(line)) { + .start => { + <span class="lp-ref">(Add new section)</span> + }, + .add => { + <span class="lp-ref">(Append to section)</span> + }, + .end => { + log(.err, "line {d}: unexpected section end", .{i + 1}); + return error.UnexpectedEnd; + }, + else => { + i += 1; + }, } } </code></pre> @@ -330,15 +357,20 @@ i = section.index; <pre><code>var i = index; while (i < 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="lp-ref">(Add reference)</span> - } else if (std.mem.eql(u8, line, k_end)) { - break; - } else { - <span class="lp-ref">(Add literal range)</span> + switch (command_type(line)) { + .start, .add => { + log(.err, "line {d}: unexpected section start", .{i + 1}); + return error.UnexpectedStart; + }, + .ref => { + <span class="lp-ref">(Add reference)</span> + }, + .end => { + break; + }, + else => { + <span class="lp-ref">(Add literal range)</span> + }, } } </code></pre> @@ -445,16 +477,22 @@ try buffer.appendSlice(code); 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="lp-ref">(Format starting command)</span> - } else if (std.mem.startsWith(u8, line, k_add)) { - <span class="lp-ref">(Format appending command)</span> - } else if (std.mem.startsWith(u8, line, k_end)) { - <span class="lp-ref">(Format ending command)</span> - } else if (std.mem.startsWith(u8, std.mem.trimLeft(u8, line, " \t"), k_ref)) { - <span class="lp-ref">(Format reference command)</span> - } else { - try buffer.append(line); + } else switch (command_type(line)) { + .start => { + <span class="lp-ref">(Format starting command)</span> + }, + .add => { + <span class="lp-ref">(Format appending command)</span> + }, + .ref => { + <span class="lp-ref">(Format reference command)</span> + }, + .end => { + <span class="lp-ref">(Format ending command)</span> + }, + else => { + try buffer.append(line); + }, } } @@ -488,13 +526,6 @@ try buffer.append(try std.mem.join(alloc, current_name, conf_start)); 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’s leading whitespace is prepended (to preserve indentation). </p> <h3 id="format-reference-command">Format reference command:</h3> @@ -503,6 +534,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, &[_][]const u8{ line[0..start], ref })); </code></pre> + +<p>Processing a section ending command is performed similarly to the starting and appending commands, however it 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> </main> <nav> </nav> diff --git a/software/literary/log.html b/software/literary/log.html index 9ebf2dc..89f861a 100755 --- a/software/literary/log.html +++ b/software/literary/log.html @@ -10,7 +10,6 @@ <link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png"> <link rel="manifest" href="/favicon/site.webmanifest"> <title>log.lp — DistressNetwork°</title> -<meta http-equiv="last-modified" content="2022-04-01 10:35:03-04:00" /> <style>h3,.lp-ref {font-family: neue-haas-grotesk-text, var(--fs-sans); font-size: 1rem; font-weight: normal; font-style: italic;} h3 {margin: 1rem;}</style> </head> <body> diff --git a/software/literary/tangle.html b/software/literary/tangle.html index 1559d31..3fd4c02 100755 --- a/software/literary/tangle.html +++ b/software/literary/tangle.html @@ -10,7 +10,6 @@ <link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png"> <link rel="manifest" href="/favicon/site.webmanifest"> <title>tangle.lp — DistressNetwork°</title> -<meta http-equiv="last-modified" content="2022-04-01 10:35:03-04:00" /> <style>h3,.lp-ref {font-family: neue-haas-grotesk-text, var(--fs-sans); font-size: 1rem; font-weight: normal; font-style: italic;} h3 {margin: 1rem;}</style> </head> <body> diff --git a/software/literary/weave.html b/software/literary/weave.html index 9edd4f1..81ef1d6 100755 --- a/software/literary/weave.html +++ b/software/literary/weave.html @@ -10,7 +10,6 @@ <link rel="icon" type="image/png" sizes="16x16" href="/favicon/favicon-16x16.png"> <link rel="manifest" href="/favicon/site.webmanifest"> <title>weave.lp — DistressNetwork°</title> -<meta http-equiv="last-modified" content="2022-04-01 10:35:03-04:00" /> <style>h3,.lp-ref {font-family: neue-haas-grotesk-text, var(--fs-sans); font-size: 1rem; font-weight: normal; font-style: italic;} h3 {margin: 1rem;}</style> </head> <body> |