hare

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

unit.ha (623B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use fmt;
      5 use hare::ast;
      6 use io;
      7 
      8 // Unparses a [[hare::ast::subunit]].
      9 export fn subunit(
     10 	out: io::handle,
     11 	syn: *synfunc,
     12 	s: ast::subunit,
     13 ) (size | io::error) = {
     14 	let n = 0z;
     15 	for (let i = 0z; i < len(s.imports); i += 1) {
     16 		n += import(out, syn, &s.imports[i])?;
     17 		n += fmt::fprintln(out)?;
     18 	};
     19 	if (len(s.imports) > 0) {
     20 		n += fmt::fprintln(out)?;
     21 	};
     22 	for (let i = 0z; i < len(s.decls); i += 1) {
     23 		n += decl(out, syn, &s.decls[i])?;
     24 		if (i < len(s.decls) - 1) n += fmt::fprintln(out)?;
     25 		n += fmt::fprintln(out)?;
     26 	};
     27 	return n;
     28 };