hare

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

commit f870e1e4ab5c829be61d52ab307dc7df794b5f3a
parent 257bc4164fec78dd2d57c492b0ef876c5b8702da
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed, 21 Apr 2021 09:47:27 -0400

haredoc: support empty ident (to index stdlib)

Diffstat:
AREADME | 12++++++++++++
Mcmd/haredoc/html.ha | 19+++++++++++++++++--
Mcmd/haredoc/main.ha | 15++++++---------
Mdocs/stdlib.md | 2+-
4 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/README b/README @@ -0,0 +1,12 @@ +This is the Hare standard library reference documentation. For a guided +introduction to the standard library, see the tutorial: + +https://harelang.org/tutorials/stdlib + +The standard library mandate states that the following services are provided: + +- An interface to the host operating system +- Implementations of broadly useful algorithms +- Implementations of broadly useful formats and protocols +- Useful features to complement Hare language features +- Introspective meta-features for Hare-aware programs diff --git a/cmd/haredoc/html.ha b/cmd/haredoc/html.ha @@ -40,7 +40,11 @@ fn emit_html(ctx: *context) (void | error) = { if (len(ctx.version.subdirs) != 0) { // TODO: Verify that these are actually modules - fmt::println("<h3>Submodules</h3>")?; + if (len(ctx.ident) == 0) { + fmt::println("<h3>Modules</h3>")?; + } else { + fmt::println("<h3>Submodules</h3>")?; + }; fmt::println("<ul class='submodules'>")?; for (let i = 0z; i < len(ctx.version.subdirs); i += 1) { let dir = ctx.version.subdirs[i]; @@ -231,7 +235,15 @@ fn markup_html(ctx: *context, in: *io::stream) (void | io::error) = { fmt::println()?; fmt::print("<p>")?; }, - tx: text => { + tx: text => if (strings::has_prefix(tx, "https://")) { + // Temporary hack + fmt::print("<a rel='nofollow noopener' href='"); + html::escape(os::stdout, tx); + fmt::print("'>"); + html::escape(os::stdout, tx); + fmt::print("</a>"); + free(tx); + } else { html::escape(os::stdout, tx); free(tx); }, @@ -365,6 +377,9 @@ fn prototype_html( }; fn breadcrumb(ident: ast::ident) str = { + if (len(ident) == 0) { + return ""; + }; let buf = strio::dynamic(); fmt::fprintf(buf, "<a href='/'>stdlib</a> ยป "); for (let i = 0z; i < len(ident) - 1; i += 1) { diff --git a/cmd/haredoc/main.ha b/cmd/haredoc/main.ha @@ -64,15 +64,12 @@ export fn main() void = { let ctx = module::context_init(tags, [], default_harepath()); defer module::context_finish(&ctx); - if (len(cmd.args) < 1) { - getopt::printusage(os::stderr, os::args[0], help); - os::exit(1); - }; - - const id = match (parse::identstr(cmd.args[0])) { - err: parse::error => fmt::fatal(parse::strerror(err)), - id: ast::ident => id, - }; + const id: ast::ident = + if (len(cmd.args) < 1) [] + else match (parse::identstr(cmd.args[0])) { + err: parse::error => fmt::fatal(parse::strerror(err)), + id: ast::ident => id, + }; const version = match (module::lookup(&ctx, id)) { ver: module::version => ver, diff --git a/docs/stdlib.md b/docs/stdlib.md @@ -2,10 +2,10 @@ The Hare standard library shall provide: -1. Useful features to complement Hare language features 2. An interface to the host operating system 3. Implementations of broadly useful algorithms 4. Implementations of broadly useful formats and protocols +1. Useful features to complement Hare language features 5. Introspective meta-features for Hare-aware programs Each of these services shall: