File: main.ha

package info (click to toggle)
hare 0.25.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,948 kB
  • sloc: asm: 1,264; makefile: 123; sh: 114; lisp: 101
file content (55 lines) | stat: -rw-r--r-- 1,206 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-License-Identifier: GPL-3.0-only
// (c) Hare authors <https://harelang.org>

use bufio;
use fmt;
use fs;
use hare::ast;
use hare::lex;
use hare::parse;
use io;
use os;
use path;

export fn main() void = {
	let buf = path::init()!;
	let status: int = os::status::SUCCESS;
	iter(&buf, &status);
	os::exit(status);
};

fn iter(buf: *path::buffer, status: *int) void = {
	let it = os::iter(path::string(buf))!;
	defer fs::finish(it);
	for (let ent => fs::next(it)!) {
		path::push(buf, ent.name)!;
		defer path::pop(buf);
		const st = os::stat(path::string(buf))!;
		if (fs::isfile(st.mode)) {
			match (path::peek_ext(buf)) {
			case let s: str =>
				if (s == "ha") {
					parse(path::string(buf), status);
				};
			case void => void;
			};
		} else if (fs::isdir(st.mode)) {
			iter(buf, status);
		};
	};
};

fn parse(path: str, status: *int) void = {
	const f = os::open(path)!;
	defer io::close(f)!;
	let sc = bufio::newscanner(f);
	defer bufio::finish(&sc);
	let lexer = lex::init(&sc, path);
	match (parse::subunit(&lexer)) {
	case let su: ast::subunit =>
		ast::subunit_finish(su);
	case let err: parse::error =>
		fmt::errorln(parse::strerror(err))!;
		*status = os::status::FAILURE;
	};
};