hare

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

util.ha (491B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use fmt;
      5 use io;
      6 
      7 fn newline(ctx: *context) (size | io::error) = {
      8 	let n = 0z;
      9 	n += fmt::fprint(ctx.out, "\n")?;
     10 	ctx.linelen = 0;
     11 	for (let i = 0z; i < ctx.indent; i += 1) {
     12 		n += fmt::fprint(ctx.out, "\t")?;
     13 		ctx.linelen += 8;
     14 	};
     15 	return n;
     16 };
     17 
     18 fn space(ctx: *context) (size | io::error) = {
     19 	if (ctx.linelen <= ctx.indent * 8) {
     20 		return 0z;
     21 	};
     22 	ctx.linelen += 1;
     23 	return fmt::fprint(ctx.out, " ");
     24 };