commit ceca1b49a652baaeb5aa13db801e53964ed1a417
parent c929eb16a3d1a99d54acfc055778b30367fc2bec
Author: Sebastian <sebastian@sebsite.pw>
Date: Tue, 17 Oct 2023 22:30:10 -0400
haredoc: remove -Fhare
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
3 files changed, 13 insertions(+), 157 deletions(-)
diff --git a/cmd/haredoc/doc/hare.ha b/cmd/haredoc/doc/hare.ha
@@ -1,119 +0,0 @@
-// SPDX-License-Identifier: GPL-3.0-only
-// (c) Hare authors <https://harelang.org>
-
-use bufio;
-use fmt;
-use hare::ast;
-use hare::module;
-use hare::unparse;
-use io;
-use os;
-use strings;
-
-// Formats output as Hare source code (prototypes)
-export fn emit_hare(ctx: *context) (void | error) = {
- const summary = ctx.summary;
-
- let first = true;
- match (ctx.readme) {
- case let readme: io::file =>
- first = false;
- for (true) {
- match (bufio::read_line(readme)?) {
- case io::EOF =>
- break;
- case let b: []u8 =>
- fmt::fprintfln(ctx.out,
- "// {}", strings::fromutf8(b)!)?;
- free(b);
- };
- };
- case void => void;
- };
-
- emit_submodules_hare(ctx)?;
-
- // XXX: Should we emit the dependencies, too?
- for (let i = 0z; i < len(summary.types); i += 1) {
- if (!first) {
- fmt::fprintln(ctx.out)?;
- };
- first = false;
- details_hare(ctx, summary.types[i])?;
- };
- for (let i = 0z; i < len(summary.constants); i += 1) {
- if (!first) {
- fmt::fprintln(ctx.out)?;
- };
- first = false;
- details_hare(ctx, summary.constants[i])?;
- };
- for (let i = 0z; i < len(summary.errors); i += 1) {
- if (!first) {
- fmt::fprintln(ctx.out)?;
- };
- first = false;
- details_hare(ctx, summary.errors[i])?;
- };
- for (let i = 0z; i < len(summary.globals); i += 1) {
- if (!first) {
- fmt::fprintln(ctx.out)?;
- };
- first = false;
- details_hare(ctx, summary.globals[i])?;
- };
- for (let i = 0z; i < len(summary.funcs); i += 1) {
- if (!first) {
- fmt::fprintln(ctx.out)?;
- };
- first = false;
- details_hare(ctx, summary.funcs[i])?;
- };
-};
-
-fn emit_submodules_hare(ctx: *context) (void | error) = {
- if (len(ctx.submods) != 0) {
- fmt::fprintln(ctx.out)?;
- if (len(ctx.ident) == 0) {
- fmt::fprintln(ctx.out, "// Modules")?;
- } else {
- fmt::fprintln(ctx.out, "// Submodules")?;
- };
- for (let i = 0z; i < len(ctx.submods); i += 1) {
- let submodule = if (len(ctx.ident) != 0) {
- const s = unparse::identstr(ctx.ident);
- defer free(s);
- yield strings::concat(s, "::", ctx.submods[i]);
- } else {
- yield strings::dup(ctx.submods[i]);
- };
- defer free(submodule);
-
- fmt::fprintf(ctx.out, "// - [[")?;
- fmt::fprintf(ctx.out, submodule)?;
- fmt::fprintfln(ctx.out, "]]")?;
- };
- };
-};
-
-fn details_hare(ctx: *context, decl: ast::decl) (void | error) = {
- if (len(decl.docs) == 0 && !ctx.show_undocumented) {
- return;
- };
-
- const iter = strings::tokenize(decl.docs, "\n");
- for (true) {
- match (strings::next_token(&iter)) {
- case void =>
- break;
- case let s: str =>
- if (len(s) != 0) {
- fmt::fprintfln(ctx.out, "//{}", s)?;
- };
- };
- };
-
- unparse::decl(ctx.out, &unparse::syn_wrap, decl)?;
- fmt::fprintln(ctx.out)?;
- return;
-};
diff --git a/cmd/haredoc/doc/types.ha b/cmd/haredoc/doc/types.ha
@@ -41,12 +41,6 @@ export fn strerror(err: error) str = {
};
};
-export type format = enum {
- HARE,
- TTY,
- HTML,
-};
-
export type context = struct {
mctx: *module::context,
ident: ast::ident,
@@ -55,7 +49,6 @@ export type context = struct {
srcs: module::srcset,
submods: []str,
summary: summary,
- format: format,
template: bool,
show_undocumented: bool,
readme: (io::file | void),
diff --git a/cmd/haredoc/main.ha b/cmd/haredoc/main.ha
@@ -21,9 +21,9 @@ use unix::tty;
const help: []getopt::help = [
"reads and formats Hare documentation",
- ('a', "show undocumented members (only applies to -Fhare and -Ftty)"),
+ ('a', "show undocumented members (only applies to -Ftty)"),
('t', "disable HTML template (requires postprocessing)"),
- ('F', "format", "specify output format (hare, tty, or html)"),
+ ('F', "format", "specify output format (tty or html)"),
('T', "tagset", "set/unset build tags"),
"[identifier|path]",
];
@@ -53,11 +53,7 @@ export fn main() void = {
};
fn doc(name: str, cmd: *getopt::command) (void | error) = {
- let fmt = if (tty::isatty(os::stdout_file)) {
- yield doc::format::TTY;
- } else {
- yield doc::format::HARE;
- };
+ let html = false;
let template = true;
let show_undocumented = false;
let tags: []str = default_tags()?;
@@ -68,12 +64,10 @@ fn doc(name: str, cmd: *getopt::command) (void | error) = {
switch (opt.0) {
case 'F' =>
switch (opt.1) {
- case "hare" =>
- fmt = doc::format::HARE;
case "tty" =>
- fmt = doc::format::TTY;
+ html = false;
case "html" =>
- fmt = doc::format::HTML;
+ html = true;
case =>
fmt::fatal("Invalid format", opt.1);
};
@@ -87,10 +81,8 @@ fn doc(name: str, cmd: *getopt::command) (void | error) = {
};
};
- if (show_undocumented) switch (fmt) {
- case doc::format::HARE, doc::format::TTY => void;
- case =>
- fmt::fatal("Option -a must be used only with -Fhare or -Ftty");
+ if (show_undocumented && html) {
+ fmt::fatal("Option -a must be used only with -Ftty");
};
let ctx = module::context {
@@ -223,7 +215,6 @@ fn doc(name: str, cmd: *getopt::command) (void | error) = {
srcs = srcs,
submods = submods,
summary = doc::sort_decls(decls),
- format = fmt,
template = template,
readme = readme,
show_undocumented = show_undocumented,
@@ -231,12 +222,13 @@ fn doc(name: str, cmd: *getopt::command) (void | error) = {
pager = void,
};
- if (fmt == doc::format::TTY) {
+ const ret = if (html) {
+ yield doc::emit_html(&ctx);
+ } else {
ctx.out = init_tty(&ctx);
+ yield doc::emit_tty(&ctx);
};
- const ret = emit(&ctx);
-
io::close(ctx.out)!;
match (ctx.pager) {
case void => void;
@@ -244,7 +236,8 @@ fn doc(name: str, cmd: *getopt::command) (void | error) = {
exec::wait(&proc)!;
};
- return ret;
+ // TODO: remove ? (harec bug workaround)
+ return ret?;
};
// Nearly identical to parse::identstr, except alphanumeric lexical tokens are
@@ -365,17 +358,6 @@ fn has_decl(decl: ast::decl, name: str) bool = {
return false;
};
-fn emit(ctx: *doc::context) (void | error) = {
- switch (ctx.format) {
- case doc::format::HARE =>
- doc::emit_hare(ctx)?;
- case doc::format::TTY =>
- doc::emit_tty(ctx)?;
- case doc::format::HTML =>
- doc::emit_html(ctx)?;
- };
-};
-
@test fn parseident() void = {
let (ident, trailing) = parseident("hare::lex") as (ast::ident, bool);
assert(ast::ident_eq(ident, ["hare", "lex"]));