hare

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

commit 7f6580d4eb42fbbf92ebba6a524abcaa4c5ab943
parent 73040fb158ede13a1b5b7ee215df0bf909084fb2
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue, 20 Apr 2021 12:56:59 -0400

haredoc: sort errors out separately

Diffstat:
Mcmd/haredoc/html.ha | 52++++++++++++++++++++++++++++++++++++++++++----------
Mcmd/haredoc/resolver.ha | 6++++++
Mcmd/haredoc/sort.ha | 7++++++-
Merrors/common.ha | 4++--
4 files changed, 56 insertions(+), 13 deletions(-)

diff --git a/cmd/haredoc/html.ha b/cmd/haredoc/html.ha @@ -38,6 +38,7 @@ fn emit_html(ctx: *context) (void | error) = { }, }; + fmt::println("<h3>Index</h3>")?; if (len(decls.types) != 0) { fmt::println("<h4>Types</h4>")?; fmt::println("<pre>")?; @@ -47,6 +48,15 @@ fn emit_html(ctx: *context) (void | error) = { fmt::print("</pre>")?; }; + if (len(decls.errors) != 0) { + fmt::println("<h4>Errors</h4>")?; + fmt::println("<pre>")?; + for (let i = 0z; i < len(decls.errors); i += 1) { + tocentry(decls.errors[i])?; + }; + fmt::print("</pre>")?; + }; + if (len(decls.globals) != 0) { fmt::println("<h4>Globals</h4>")?; fmt::print("<pre>")?; @@ -64,16 +74,33 @@ fn emit_html(ctx: *context) (void | error) = { }; fmt::println("</pre>")?; }; - fmt::println("<hr />")?; - for (let i = 0z; i < len(decls.types); i += 1) { - details(ctx, decls.types[i])?; + if (len(decls.types) != 0) { + fmt::println("<h3>Types</h3>")?; + for (let i = 0z; i < len(decls.types); i += 1) { + details(ctx, decls.types[i])?; + }; }; - for (let i = 0z; i < len(decls.globals); i += 1) { - details(ctx, decls.globals[i])?; + + if (len(decls.errors) != 0) { + fmt::println("<h3>Errors</h3>")?; + for (let i = 0z; i < len(decls.errors); i += 1) { + details(ctx, decls.errors[i])?; + }; }; - for (let i = 0z; i < len(decls.funcs); i += 1) { - details(ctx, decls.funcs[i])?; + + if (len(decls.globals) != 0) { + fmt::println("<h3>Globals</h3>")?; + for (let i = 0z; i < len(decls.globals); i += 1) { + details(ctx, decls.globals[i])?; + }; + }; + + if (len(decls.funcs) != 0) { + fmt::println("<h3>Functions</h3>")?; + for (let i = 0z; i < len(decls.funcs); i += 1) { + details(ctx, decls.funcs[i])?; + }; }; }; @@ -93,7 +120,7 @@ fn tocentry(decl: ast::decl) (void | error) = { match (decl.decl) { g: []ast::decl_global => { let g = g[0]; - fmt::fprint(os::stdout, ": ")?; + fmt::print(": ")?; type_html(os::stdout, 0, g._type, true)?; }, t: []ast::decl_type => void, @@ -107,7 +134,7 @@ fn tocentry(decl: ast::decl) (void | error) = { fn details(ctx: *context, decl: ast::decl) (void | error) = { fmt::println("<section class='member'>"); - fmt::print("<h3 id='")?; + fmt::print("<h4 id='")?; unparse::ident(os::stdout, decl_ident(decl))?; fmt::print("'>")?; fmt::printf("{} ", @@ -123,7 +150,7 @@ fn details(ctx: *context, decl: ast::decl) (void | error) = { unparse::ident(os::stdout, decl_ident(decl))?; fmt::print("'>[link]</a> </span>")?; - fmt::println("</h3>")?; + fmt::println("</h4>")?; fmt::println("<pre class='decl'>")?; unparse_html(os::stdout, decl)?; @@ -427,6 +454,11 @@ h2, h3, h4 { display: flex; } +h3 { + border-bottom: 1px solid #ccc; + padding-bottom: 0.25rem; +} + .invalid { color: red; } diff --git a/cmd/haredoc/resolver.ha b/cmd/haredoc/resolver.ha @@ -49,6 +49,12 @@ fn is_local(ctx: *context, what: ast::ident) bool = { return true; }; }; + for (let i = 0z; i < len(summary.errors); i += 1) { + const name = decl_ident(summary.errors[i])[0]; + if (name == what[0]) { + return true; + }; + }; for (let i = 0z; i < len(summary.globals); i += 1) { const name = decl_ident(summary.globals[i])[0]; if (name == what[0]) { diff --git a/cmd/haredoc/sort.ha b/cmd/haredoc/sort.ha @@ -4,6 +4,7 @@ use sort; type summary = struct { // TODO: Constants + errors: []ast::decl, types: []ast::decl, globals: []ast::decl, funcs: []ast::decl, @@ -26,7 +27,11 @@ fn sort_decls(decls: []ast::decl) summary = { f: ast::decl_func => append(sorted.funcs, decl), t: []ast::decl_type => for (let j = 0z; j < len(t); j += 1) { - append(sorted.types, ast::decl { + let bucket = &sorted.types; + if (t[j]._type.flags & ast::type_flags::ERROR == ast::type_flags::ERROR) { + bucket = &sorted.errors; + }; + append(*bucket, ast::decl { exported = true, loc = decl.loc, decl = { diff --git a/errors/common.ha b/errors/common.ha @@ -11,7 +11,7 @@ export type invalid = void!; export type noaccess = void!; // An entry was requested which does not exist. -export type noentry = void; +export type noentry = void!; // The requested operation caused a numeric overflow condition. export type overflow = void!; @@ -29,4 +29,4 @@ export type error = ( overflow | unsupported | opaque -); +)!;