~smlavine/hareimports

d0910a9624978040bbeb6fa5b3d9a00bccf88595 — Sebastian LaVine 27 days ago bd1b522
Reorganize source structure into flat module

Having a cmd/hareimports path with two three files in it gives me Java
nightmares.

Additionally, I re-added the list() function back to main.ha, as it is
simple and will not rely on the helper functions that the operations in
editing.ha will.

I also exported the operation functions.
4 files changed, 23 insertions(+), 42 deletions(-)

M Makefile
D cmd/hareimports/list.ha
R cmd/hareimports/editing.ha => editing.ha
R cmd/hareimports/main.ha => main.ha
M Makefile => Makefile +3 -3
@@ 3,15 3,15 @@

HARE = hare

MODULE = cmd/hareimports/
SRC = editing.ha main.ha

all: hareimports

hareimports: $(SRC)
	$(HARE) build $(HAREFLAGS) -o $@ $(MODULE)
	$(HARE) build $(HAREFLAGS) -o $@

check:
	$(HARE) test $(MODULE)
	$(HARE) test

clean:
	rm -f hareimports

D cmd/hareimports/list.ha => cmd/hareimports/list.ha +0 -36
@@ 1,36 0,0 @@
// hareimports - Hare import manager
// Copyright (C) 2022 Sebastian LaVine <mail@smlavine.com>
// Copyright (C) 2022 Sebastian <sebastian@sebsite.pw>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3 only.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.

use fmt;
use hare::ast;
use hare::unparse;

// Lists the imports of the given file, in the order they are imported.
fn list(source: source_file) void = {
	const u: *ast::subunit = &source; // sub-typing
	fmt::printfln("{}:", source.path)!;
	for (let i = 0z; i < len(u.imports); i += 1) {
		const s = unparse::identstr(u.imports[i].ident);
		defer free(s);

		switch (u.imports[i].mode) {
		case ast::import_mode::ALIAS =>
			fmt::printfln("{} (= {})", u.imports[i].alias, s)!;
		case =>
			fmt::println(s)!;
		};
	};
};

R cmd/hareimports/editing.ha => editing.ha +2 -3
@@ 14,12 14,11 @@
// along with this program. If not, see http://www.gnu.org/licenses/.

// Displays a diff of the given file, before and after processing imports.
fn diff(source: source_file) void = {
export fn diff(source: source_file) void = {
	abort("diff not supported yet");
};

// Edits the given file in place.
fn in_place(source: source_file) void = {
export fn in_place(source: source_file) void = {
	abort("editing in place not supported yet");
};


R cmd/hareimports/main.ha => main.ha +18 -0
@@ 20,6 20,7 @@ use hare::ast;
use hare::lex;
use hare::module;
use hare::parse;
use hare::unparse;
use io;
use os;



@@ 28,6 29,23 @@ type source_file = struct {
	path: str,
};

// Lists the imports of the given file, in the order they are imported.
export fn list(source: source_file) void = {
	const u: *ast::subunit = &source; // sub-typing
	fmt::printfln("{}:", source.path)!;
	for (let i = 0z; i < len(u.imports); i += 1) {
		const s = unparse::identstr(u.imports[i].ident);
		defer free(s);

		switch (u.imports[i].mode) {
		case ast::import_mode::ALIAS =>
			fmt::printfln("{} (= {})", u.imports[i].alias, s)!;
		case =>
			fmt::println(s)!;
		};
	};
};

export fn main() void = {
	const help: []getopt::help = [
		"Hare import manager",