hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 67e68fd03cfd7d724c8b04d2d9b5b53ad9ea5e98
parent 4fc141eaaa1ea5f23a5032c9aa59cc1c53e33aa2
Author: Byron Torres <b@torresjrjr.com>
Date:   Tue, 26 Apr 2022 03:22:33 +0100

haredoc: -F{hare,tty}: list submodules

Implements: https://todo.sr.ht/~sircmpwn/hare/641
Signed-off-by: Byron Torres <b@torresjrjr.com>

Diffstat:
Mcmd/haredoc/hare.ha | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Mcmd/haredoc/tty.ha | 2++
2 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/cmd/haredoc/hare.ha b/cmd/haredoc/hare.ha @@ -6,6 +6,7 @@ use bufio; use fmt; use hare::ast; use hare::lex; +use hare::module; use hare::unparse; use io; use os; @@ -32,6 +33,8 @@ fn emit_hare(ctx: *context) (void | error) = { case void => void; }; + emit_submodules(ctx)?; + // XXX: Should we emit the dependencies, too? for (let i = 0z; i < len(summary.types); i += 1) { if (!first) { @@ -70,6 +73,54 @@ fn emit_hare(ctx: *context) (void | error) = { }; }; +fn emit_submodules(ctx: *context) (void | error) = { + let identpath = module::identpath(ctx.ident); + defer free(identpath); + + let submodules: []str = []; + defer free(submodules); + + for (let i = 0z; i < len(ctx.version.subdirs); i += 1) { + let dir = ctx.version.subdirs[i]; + // XXX: the list of reserved directory names is not yet + // finalized. See https://todo.sr.ht/~sircmpwn/hare/516 + if (dir == "contrib") continue; + if (dir == "cmd") continue; + if (dir == "docs") continue; + if (dir == "ext") continue; + if (dir == "vendor") continue; + if (dir == "scripts") continue; + + let submod = [identpath, dir]: ast::ident; + if (module::lookup(ctx.mctx, submod) is module::error) { + continue; + }; + + append(submodules, dir); + }; + + if (len(submodules) != 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(submodules); i += 1) { + let submodule = if (len(ctx.ident) != 0) { + yield strings::concat(identpath, "::", submodules[i]); + } else { + yield submodules[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; diff --git a/cmd/haredoc/tty.ha b/cmd/haredoc/tty.ha @@ -33,6 +33,8 @@ fn emit_tty(ctx: *context) (void | error) = { case void => void; }; + emit_submodules(ctx)?; + // XXX: Should we emit the dependencies, too? for (let i = 0z; i < len(summary.types); i += 1) { details_tty(ctx, summary.types[i])?;