commit 77b6a64b37633148b8afe2a95e1a7827f6881401
parent e26d35cf2d4f379f59f9f8218d61d8bed6d1b2a8
Author: Lou Woell <lou.woell@posteo.de>
Date:   Thu,  9 Oct 2025 20:03:47 +0200

[harehelper] move error handling to its own file

Diffstat:
Acmd/harehelper/error.ha | 40++++++++++++++++++++++++++++++++++++++++
Mcmd/harehelper/util.ha | 22----------------------
2 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/cmd/harehelper/error.ha b/cmd/harehelper/error.ha @@ -0,0 +1,40 @@ +// Copyright (C) 2025 Lou Woell <lou@repetitions.de> + +// 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. + +// 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 <https://www.gnu.org/licenses/>. + +use encoding::utf8; +use fs; +use hare::lex; +use hare::module; +use hare::parse; +use io; + +type error = !(parse::error | lex::error | fs::error | module::error | io::error | + utf8::invalid); + +fn strerror (e: error) const str = { + match (e) { + case let e: parse::error => + return parse::strerror(e); + case let e: lex::error => + return lex::strerror(e); + case let e: fs::error => + return fs::strerror(e); + case let e: module::error => + return module::strerror(e); + case let e: io::error => + return io::strerror(e); + case => + return "unknown error"; + }; +}; diff --git a/cmd/harehelper/util.ha b/cmd/harehelper/util.ha @@ -14,9 +14,7 @@ use ascii; use bufio; -use encoding::utf8; use fmt; -use fs; use hare::ast; use hare::lex; use hare::module; @@ -46,26 +44,6 @@ fn ident_ns(id: ast::ident) ast::ident = { if (l > 1) return id[..l - 1] else return id; }; -type error = !(parse::error | lex::error | fs::error | module::error | io::error | - utf8::invalid); - -fn strerror (e: error) const str = { - match (e) { - case let e: parse::error => - return parse::strerror(e); - case let e: lex::error => - return lex::strerror(e); - case let e: fs::error => - return fs::strerror(e); - case let e: module::error => - return module::strerror(e); - case let e: io::error => - return io::strerror(e); - case => - return "unknown error"; - }; -}; - fn scan(path: str) ([]ast::decl | error) = { // This function is copied from haredoc (GPL-3.0-only) (c) Hare authors; const input = os::open(path)?;