hare

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

commit c19cf06d6549e89b522229f8fc34df9a9e0a6671
parent ef41e579db9857fc6042057fe61946067cda3f8b
Author: Sebastian <sebastian@sebsite.pw>
Date:   Fri,  8 Apr 2022 15:10:00 -0400

unparse: print empty line between declarations

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mhare/parse/+test/expr.ha | 56++++++++++++++++++++++++++++----------------------------
Mhare/parse/+test/types.ha | 7+++++++
Mhare/parse/+test/unit.ha | 14+++++++-------
Mhare/unparse/unit.ha | 1+
4 files changed, 43 insertions(+), 35 deletions(-)

diff --git a/hare/parse/+test/expr.ha b/hare/parse/+test/expr.ha @@ -78,18 +78,18 @@ }; @test fn call() void = { - roundtrip("export fn main() void = test();\n" - "export fn main() void = test(void, void, void);\n" - "export fn main() void = test(void, void, void...);\n" + roundtrip("export fn main() void = test();\n\n" + "export fn main() void = test(void, void, void);\n\n" + "export fn main() void = test(void, void, void...);\n\n" "export fn main() void = test()()(void);\n"); }; @test fn cast() void = { - roundtrip("export fn main() void = void: int;\n" - "export fn main() void = void as int;\n" - "export fn main() void = void is int;\n" - "export fn main() void = void: int: uint: u16: u8;\n" - "export fn main() void = void: int as uint: u16 is u8;\n" + roundtrip("export fn main() void = void: int;\n\n" + "export fn main() void = void as int;\n\n" + "export fn main() void = void is int;\n\n" + "export fn main() void = void: int: uint: u16: u8;\n\n" + "export fn main() void = void: int as uint: u16 is u8;\n\n" "export fn main() void = {\n\tyield void;\n}: int;\n"); }; @@ -213,22 +213,22 @@ }; @test fn postfix() void = { - roundtrip("export fn main() void = x.y;\n" - "export fn main() void = x.y.z.q;\n" - "export fn main() void = x().y;\n" - "export fn main() void = x.42;\n" - "export fn main() void = x().y.0.q;\n" - "export fn main() void = x?;\n" - "export fn main() void = x!;\n" - "export fn main() void = x()?.y;\n" - "export fn main() void = x[10];\n" + roundtrip("export fn main() void = x.y;\n\n" + "export fn main() void = x.y.z.q;\n\n" + "export fn main() void = x().y;\n\n" + "export fn main() void = x.42;\n\n" + "export fn main() void = x().y.0.q;\n\n" + "export fn main() void = x?;\n\n" + "export fn main() void = x!;\n\n" + "export fn main() void = x()?.y;\n\n" + "export fn main() void = x[10];\n\n" "export fn main() void = x[10 + 10][20];\n"); }; @test fn slice() void = { - roundtrip("export fn main() void = x[..];\n" - "export fn main() void = x[123..];\n" - "export fn main() void = x[123..321];\n" + roundtrip("export fn main() void = x[..];\n\n" + "export fn main() void = x[123..];\n\n" + "export fn main() void = x[123..321];\n\n" "export fn main() void = x[..321];\n"); }; @@ -273,17 +273,17 @@ }; @test fn unarithm() void = { - roundtrip("export fn main() void = +void;\n" - "export fn main() void = -void;\n" - "export fn main() void = *void;\n" - "export fn main() void = ~void;\n" - "export fn main() void = !void;\n" + roundtrip("export fn main() void = +void;\n\n" + "export fn main() void = -void;\n\n" + "export fn main() void = *void;\n\n" + "export fn main() void = ~void;\n\n" + "export fn main() void = !void;\n\n" "export fn main() void = &void;\n"); }; @test fn yield_expr() void = { - roundtrip("export fn main() void = yield;\n" - "export fn main() void = yield void;\n" - "export fn main() void = yield :foo;\n" + roundtrip("export fn main() void = yield;\n\n" + "export fn main() void = yield void;\n\n" + "export fn main() void = yield :foo;\n\n" "export fn main() void = yield :foo, void;\n"); }; diff --git a/hare/parse/+test/types.ha b/hare/parse/+test/types.ha @@ -6,11 +6,13 @@ @offset(void) x: int, y: int, }; + export type bar = union { x: int, // docs docs docs y: int, }; + export type baz = struct { embedded, struct { @@ -23,8 +25,11 @@ export type baz = struct { @test fn array_slice() void = { roundtrip("export type foo = []int; + export type bar = [*]int; + export type baz = [_]int; + export type bat = [void]int; "); }; @@ -38,12 +43,14 @@ export type bat = [void]int; Z, // foo Q, // bar }; + export type bar = enum uint { X = void, Y = void, Z, Q, }; + export type baz = enum rune { X = void, Y = void, diff --git a/hare/parse/+test/unit.ha b/hare/parse/+test/unit.ha @@ -120,13 +120,13 @@ fn tup_to_import(tup: import_tuple) ast::import = ast::import { }; @test fn decls() void = { - roundtrip("export type foo::bar = *int, baz = const void;\n" - "type foo = ...bar;\n" - "type foo = nullable *fn(x: rune, _: int) void;\n" - "export let @symbol(\"_\") foo::bar: int = void, baz: int = void;\n" - "def foo::bar: int = void;\n" - "@symbol(\".f9$oo\") fn foo(bar: int, baz: int...) void;\n" - "@test fn foo(_: int, ...) void;\n" + roundtrip("export type foo::bar = *int, baz = const void;\n\n" + "type foo = ...bar;\n\n" + "type foo = nullable *fn(x: rune, _: int) void;\n\n" + "export let @symbol(\"_\") foo::bar: int = void, baz: int = void;\n\n" + "def foo::bar: int = void;\n\n" + "@symbol(\".f9$oo\") fn foo(bar: int, baz: int...) void;\n\n" + "@test fn foo(_: int, ...) void;\n\n" "export fn main() void = void;\n"); }; diff --git a/hare/unparse/unit.ha b/hare/unparse/unit.ha @@ -14,6 +14,7 @@ export fn subunit(out: io::handle, s: ast::subunit) (size | io::error) = { }; for (let i = 0z; i < len(s.decls); i += 1) { n += decl(out, s.decls[i])?; + if (i < len(s.decls) - 1) n += fmt::fprintln(out)?; n += fmt::fprintln(out)?; }; return n;