hare

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

types.ha (2075B)


      1 // SPDX-License-Identifier: GPL-3.0-only
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use encoding::utf8;
      5 use fmt;
      6 use fs;
      7 use hare::ast;
      8 use hare::lex;
      9 use hare::module;
     10 use hare::parse;
     11 use hare::parse::doc;
     12 use io;
     13 use os::exec;
     14 
     15 export type haredoc_colors_error = !str;
     16 
     17 export type error = !(lex::error | parse::error | doc::error | io::error |
     18 	module::error | exec::error | fs::error | haredoc_colors_error |
     19 	utf8::invalid);
     20 
     21 export fn strerror(err: error) str = {
     22 	match (err) {
     23 	case let err: lex::error =>
     24 		return lex::strerror(err);
     25 	case let err: parse::error =>
     26 		return parse::strerror(err);
     27 	case let err: doc::error =>
     28 		return doc::strerror(err);
     29 	case let err: io::error =>
     30 		return io::strerror(err);
     31 	case let err: module::error =>
     32 		return module::strerror(err);
     33 	case let err: exec::error =>
     34 		return exec::strerror(err);
     35 	case let err: fs::error =>
     36 		return fs::strerror(err);
     37 	case let err: utf8::invalid =>
     38 		return utf8::strerror(err);
     39 	case let err: haredoc_colors_error =>
     40 		def ERRMSG = "Error parsing HAREDOC_COLORS: invalid key";
     41 		if (len(err) == 0) {
     42 			return ERRMSG;
     43 		};
     44 		static let buf: [len(ERRMSG) + 64 + 3]u8 = [0...];
     45 		return fmt::bsprintf(buf, "{} '{}'", ERRMSG, err);
     46 	};
     47 };
     48 
     49 export type context = struct {
     50 	mctx: *module::context,
     51 	ident: ast::ident,
     52 	tags: []str,
     53 	ambiguous: bool,
     54 	srcs: module::srcset,
     55 	submods: []str,
     56 	summary: summary,
     57 	template: bool,
     58 	show_undocumented: bool,
     59 	readme: (io::file | void),
     60 	out: io::handle,
     61 	pager: (exec::process | void),
     62 };
     63 
     64 export type summary = struct {
     65 	constants: []ast::decl,
     66 	errors: []ast::decl,
     67 	types: []ast::decl,
     68 	globals: []ast::decl,
     69 	funcs: []ast::decl,
     70 };
     71 
     72 export fn finish_summary(s: summary) void = {
     73 	for (let c .. s.constants) {
     74 		free(c.decl as []ast::decl_const);
     75 	};
     76 	free(s.constants);
     77 
     78 	for (let e .. s.errors) {
     79 		free(e.decl as []ast::decl_type);
     80 	};
     81 	free(s.errors);
     82 
     83 	for (let t .. s.types) {
     84 		free(t.decl as []ast::decl_type);
     85 	};
     86 	free(s.types);
     87 
     88 	for (let g .. s.globals) {
     89 		free(g.decl as []ast::decl_global);
     90 	};
     91 	free(s.globals);
     92 
     93 	free(s.funcs);
     94 };