commit d4cb2309bcb8de35695adcc9bdb31a8b115d424b
parent 0dadb04584223e1493440f1f5abc3d818bf499d4
Author: Alexey Yerin <yyp@disroot.org>
Date: Wed, 13 Oct 2021 10:12:38 +0300
cmd/haredoc: implement constants (def) in -Fhare and -Ftty
Signed-off-by: Alexey Yerin <yyp@disroot.org>
Diffstat:
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/cmd/haredoc/hare.ha b/cmd/haredoc/hare.ha
@@ -35,6 +35,13 @@ fn emit_hare(ctx: *context) (void | error) = {
first = false;
details_hare(ctx, summary.types[i])?;
};
+ for (let i = 0z; i < len(summary.constants); i += 1) {
+ if (!first) {
+ fmt::println()?;
+ };
+ first = false;
+ details_hare(ctx, summary.constants[i])?;
+ };
for (let i = 0z; i < len(summary.errors); i += 1) {
if (!first) {
fmt::println()?;
@@ -85,7 +92,7 @@ fn unparse_hare(out: *io::stream, d: ast::decl) (size | io::error) = {
match (d.decl) {
case g: []ast::decl_global =>
n += fmt::fprint(out,
- if (g[0].is_const) "def " else "let ")?;
+ if (g[0].is_const) "const " else "let ")?;
for (let i = 0z; i < len(g); i += 1) {
if (len(g[i].symbol) != 0) {
n += fmt::fprintf(out,
@@ -108,6 +115,16 @@ fn unparse_hare(out: *io::stream, d: ast::decl) (size | io::error) = {
n += fmt::fprint(out, ", ")?;
};
};
+ case c: []ast::decl_const =>
+ n += fmt::fprint(out, "def ")?;
+ for (let i = 0z; i < len(c); i += 1) {
+ n += unparse::ident(out, c[i].ident)?;
+ n += fmt::fprint(out, ": ")?;
+ n += unparse::_type(out, 0, c[i]._type)?;
+ if (i + 1 < len(c)) {
+ n += fmt::fprint(out, ", ")?;
+ };
+ };
case f: ast::decl_func =>
n += fmt::fprint(out, switch (f.attrs) {
case ast::fndecl_attrs::NONE =>
diff --git a/cmd/haredoc/tty.ha b/cmd/haredoc/tty.ha
@@ -33,6 +33,9 @@ fn emit_tty(ctx: *context) (void | error) = {
for (let i = 0z; i < len(summary.types); i += 1) {
details_tty(ctx, summary.types[i])?;
};
+ for (let i = 0z; i < len(summary.constants); i += 1) {
+ details_tty(ctx, summary.constants[i])?;
+ };
for (let i = 0z; i < len(summary.errors); i += 1) {
details_tty(ctx, summary.errors[i])?;
};
@@ -91,7 +94,7 @@ fn unparse_tty(out: *io::stream, d: ast::decl) (size | io::error) = {
case g: []ast::decl_global =>
n += fmt::fprint(out, "\x1b[34m")?;
n += fmt::fprint(out,
- if (g[0].is_const) "def " else "let ")?;
+ if (g[0].is_const) "const " else "let ")?;
n += fmt::fprint(out, "\x1b[0m")?;
for (let i = 0z; i < len(g); i += 1) {
if (len(g[i].symbol) != 0) {
@@ -106,6 +109,16 @@ fn unparse_tty(out: *io::stream, d: ast::decl) (size | io::error) = {
n += fmt::fprint(out, ", ")?;
};
};
+ case c: []ast::decl_const =>
+ n += fmt::fprintf(out, "\x1b[34m" "def " "\x1b[0m")?;
+ for (let i = 0z; i < len(c); i += 1) {
+ n += unparse::ident(out, c[i].ident)?;
+ n += fmt::fprint(out, ": ")?;
+ n += type_tty(out, 0, c[i]._type)?;
+ if (i + 1 < len(c)) {
+ n += fmt::fprint(out, ", ")?;
+ };
+ };
case t: []ast::decl_type =>
n += fmt::fprint(out, "\x1b[34m" "type " "\x1b[0m")?;
for (let i = 0z; i < len(t); i += 1) {