| 1 |
// SPDX-License-Identifier: GPL-3.0-only |
| 2 |
// (c) Hare authors <https://harelang.org> |
| 3 |
|
| 4 |
use bufio; |
| 5 |
use fmt; |
| 6 |
use fs; |
| 7 |
use hare::ast; |
| 8 |
use hare::lex; |
| 9 |
use hare::parse; |
| 10 |
use io; |
| 11 |
use os; |
| 12 |
use path; |
| 13 |
|
| 14 |
export fn main() void = { |
| 15 |
let buf = path::init()!; |
| 16 |
let status: int = os::status::SUCCESS; |
| 17 |
iter(&buf, &status); |
| 18 |
os::exit(status); |
| 19 |
}; |
| 20 |
|
| 21 |
fn iter(buf: *path::buffer, status: *int) void = { |
| 22 |
let it = os::iter(path::string(buf))!; |
| 23 |
defer fs::finish(it); |
| 24 |
for (let ent => fs::next(it)!) { |
| 25 |
path::push(buf, ent.name)!; |
| 26 |
defer path::pop(buf); |
| 27 |
const st = os::stat(path::string(buf))!; |
| 28 |
if (fs::isfile(st.mode)) { |
| 29 |
match (path::peek_ext(buf)) { |
| 30 |
case let s: str => |
| 31 |
if (s == "ha") { |
| 32 |
parse(path::string(buf), status); |
| 33 |
}; |
| 34 |
case void => void; |
| 35 |
}; |
| 36 |
} else if (fs::isdir(st.mode)) { |
| 37 |
iter(buf, status); |
| 38 |
}; |
| 39 |
}; |
| 40 |
}; |
| 41 |
|
| 42 |
fn parse(path: str, status: *int) void = { |
| 43 |
const f = os::open(path)!; |
| 44 |
defer io::close(f)!; |
| 45 |
let sc = bufio::newscanner(f); |
| 46 |
defer bufio::finish(&sc); |
| 47 |
let lexer = lex::init(&sc, path); |
| 48 |
defer lex::finish(&lexer); |
| 49 |
match (parse::subunit(&lexer)) { |
| 50 |
case let su: ast::subunit => |
| 51 |
ast::subunit_finish(su); |
| 52 |
case let err: parse::error => |
| 53 |
fmt::errorln(parse::strerror(err))!; |
| 54 |
*status = os::status::FAILURE; |
| 55 |
}; |
| 56 |
}; |