File: unit.ha

package info (click to toggle)
hare-update 0.26.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,044 kB
  • sloc: makefile: 37; sh: 14
file content (28 lines) | stat: -rw-r--r-- 597 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// SPDX-License-Identifier: MPL-2.0
// (c) Hare authors <https://harelang.org>

use fmt;
use vNEXT::ast;
use io;

// Unparses a [[hare::ast::subunit]].
export fn subunit(
	out: io::handle,
	syn: *synfunc,
	s: ast::subunit,
) (size | io::error) = {
	let n = 0z;
	for (let imp &.. s.imports) {
		n += import(out, syn, imp)?;
		n += fmt::fprintln(out)?;
	};
	if (len(s.imports) > 0) {
		n += fmt::fprintln(out)?;
	};
	for (let i = 0z; i < len(s.decls); i += 1) {
		n += decl(out, syn, &s.decls[i])?;
		if (i < len(s.decls) - 1) n += fmt::fprintln(out)?;
		n += fmt::fprintln(out)?;
	};
	return n;
};