commit ab8feaac68136da888fb4dbf9c1e33e868a86d30
parent ab7529cac05ebe45f55b703c89e572348f4c074c
Author: Drew DeVault <sir@cmpwn.com>
Date: Sat, 4 Sep 2021 09:05:31 +0200
haredoc: show non-terminating newlines in comments
The difference is evident in `haredoc os::open`
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
1 file changed, 21 insertions(+), 19 deletions(-)
diff --git a/cmd/haredoc/tty.ha b/cmd/haredoc/tty.ha
@@ -1,3 +1,4 @@
+use ascii;
use bufio;
use fmt;
use hare::ast;
@@ -8,16 +9,17 @@ use os;
use strings;
use strio;
+let firstline: bool = true;
+
// Formats output as Hare source code (prototypes) with syntax highlighting
fn emit_tty(ctx: *context) (void | error) = {
const summary = ctx.summary;
- let first = true;
match (ctx.readme) {
readme: *io::stream => {
- first = false;
for (true) match (bufio::scanline(readme)?) {
b: []u8 => {
+ firstline = false;
fmt::printfln(
"\x1b[1m" "// {}" "\x1b[0m",
strings::fromutf8(b))?;
@@ -31,43 +33,43 @@ fn emit_tty(ctx: *context) (void | error) = {
// XXX: Should we emit the dependencies, too?
for (let i = 0z; i < len(summary.types); i += 1) {
- if (!first) {
- fmt::println()?;
- };
- first = false;
details_tty(ctx, summary.types[i])?;
};
for (let i = 0z; i < len(summary.errors); i += 1) {
- if (!first) {
- fmt::println()?;
- };
- first = false;
details_tty(ctx, summary.errors[i])?;
};
for (let i = 0z; i < len(summary.globals); i += 1) {
- if (!first) {
- fmt::println()?;
- };
- first = false;
details_tty(ctx, summary.globals[i])?;
};
for (let i = 0z; i < len(summary.funcs); i += 1) {
- if (!first) {
- fmt::println()?;
- };
- first = false;
details_tty(ctx, summary.funcs[i])?;
};
};
+fn isws(s: str) bool = {
+ const iter = strings::iter(s);
+ for (true) match (strings::next(&iter)) {
+ r: rune => if (!ascii::isspace(r)) {
+ return false;
+ },
+ void => break,
+ };
+ return true;
+};
+
fn details_tty(ctx: *context, decl: ast::decl) (void | error) = {
if (len(decl.docs) == 0 && !ctx.show_undocumented) {
return;
};
+ if (!firstline) {
+ fmt::println()?;
+ };
+ firstline = false;
+
const iter = strings::tokenize(decl.docs, "\n");
for (true) match (strings::next_token(&iter)) {
- s: str => if (len(s) != 0) {
+ s: str => if (!(strings::peek_token(&iter) is void)) {
fmt::printfln("\x1b[1m" "//{}" "\x1b[0m", s)?;
},
void => break,