hare

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

util.ha (962B)


      1 // SPDX-License-Identifier: GPL-3.0-only
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 use fmt;
      5 use fs;
      6 use hare::module;
      7 use io;
      8 use memio;
      9 use os;
     10 use path;
     11 use sort;
     12 use sort::cmp;
     13 use strings;
     14 
     15 let firstline: bool = true;
     16 
     17 fn trim_comment(s: str) str = {
     18 	let trimmed = memio::dynamic();
     19 	let tok = strings::tokenize(s, "\n");
     20 	for (let line => strings::next_token(&tok)) {
     21 		memio::concat(&trimmed, strings::trimprefix(line, " "), "\n")!;
     22 	};
     23 	return strings::dup(memio::string(&trimmed)!);
     24 };
     25 
     26 export fn submodules(path: str, show_undocumented: bool) ([]str | error) = {
     27 	let submodules: []str = [];
     28 	let it = os::iter(path)?;
     29 	defer fs::finish(it);
     30 	let pathbuf = path::init(path)!;
     31 	for (let d => module::next(it)?) {
     32 		path::set(&pathbuf, path, d.name, "README")!;
     33 		if (show_undocumented || os::exists(path::string(&pathbuf))) {
     34 			append(submodules, strings::dup(d.name));
     35 		};
     36 	};
     37 	sort::sort(submodules, size(str), &cmp::strs);
     38 	return submodules;
     39 };