ed

[hare] The standard editor
Log | Files | Refs | README | LICENSE

commit 90fa396a8ec963a7eedce9e1434840b438a38824
parent 6cb1f03ea0722b123261051d9de277762e4a3fc1
Author: Byron Torres <b@torresjrjr.com>
Date:   Tue,  9 Jan 2024 23:31:40 +0000

add error.ha

Diffstat:
MMakefile | 1+
Aerror.ha | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Minteraction.ha | 2+-
Mmain.ha | 76----------------------------------------------------------------------------
4 files changed, 81 insertions(+), 77 deletions(-)

diff --git a/Makefile b/Makefile @@ -6,6 +6,7 @@ source=\ address.ha \ buffer.ha \ command.ha \ + error.ha \ execute.ha \ file.ha \ global.ha \ diff --git a/error.ha b/error.ha @@ -0,0 +1,79 @@ +use encoding::utf8; +use fmt; +use fs; +use io; +use os; +use os::exec; +use regex; + +type Error = !(...InteractionError | ...ParseError | ...CmdError); + +fn errormsg(s: *Session, err: Error) void = { + if (err is Quit) + return; + + fmt::errorln('?')!; + if (s.helpmode) + fmt::errorfln(strerror(err))!; + + s.lasterror = err; +}; + +fn strerror(err: Error) str = { + match (err) { + // InteractionError + case let e: InteractionError => + match (e) { + case Quit => + return ""; + case UnexpectedEOF => + return "Unexpected end-of-file input"; + case let e: encoding::utf8::invalid => + return encoding::utf8::strerror(e); + case let e: io::error => + return io::strerror(e); + }; + // CmdError + case InvalidAddress => + return "Invalid address"; + case NoFilename => + return "No filename"; + case WarnBufferModified => + return "Warning: Buffer modified"; + case UnexpectedAddress => + return "Unexpected address"; + case InvalidDestination => + return "Invalid destination"; + case NoMatch => + return "No match"; + case NoPrevRegex => + return "No previous search pattern"; + case NoPrevShCmd => + return "No previous shell command"; + case NoPrevGlobalSubCmd => + return "No previous global subcommand"; + case let e: InvalidGlobalSubCmd => + return "Invalid interactive global subcommand"; // TODO: append 'e'? + case let e: regex::error => + return regex::strerror(e); + case let e: fs::error => + return fs::strerror(e); + case let e: os::exec::error => + return os::exec::strerror(e); + // ParseError + case let e: UnknownCommand => + return "Unknown command"; // TODO: append 'e'? + case UnexpectedSuffix => + return "Unexpected suffix"; + case TrailingCharacters => + return "Trailing characters"; + case ExpectedArgument => + return "Expected argument"; + case ExpectedMark => + return "Expected mark"; + case InvalidDelimiter => + return "Invalid delimiter"; + case ExpectedDelimiter => + return "Expected delimiter"; + }; +}; diff --git a/interaction.ha b/interaction.ha @@ -9,7 +9,7 @@ type InteractionError = !( Quit | io::EOF | UnexpectedEOF - | utf8::invalid + | encoding::utf8::invalid | io::error ); diff --git a/main.ha b/main.ha @@ -1,12 +1,8 @@ use bufio; -use encoding::utf8; use fmt; -use fs; use getopt; use io; use os; -use os::exec; -use regex; use strings; use types; @@ -24,8 +20,6 @@ type Session = struct{ lastregex: (void | str), }; -type Error = !(...InteractionError | ...ParseError | ...CmdError); - def proghelp: [_]getopt::help = [ "standard line editor", ('p', "prompt", "set the command prompt"), @@ -123,73 +117,3 @@ fn exit_usage() never = { getopt::printusage(os::stderr, os::args[0], proghelp)!; os::exit(1); }; - -fn errormsg(s: *Session, err: Error) void = { - if (err is Quit) - return; - - fmt::errorln('?')!; - if (s.helpmode) - fmt::errorfln(strerror(err))!; - - s.lasterror = err; -}; - -fn strerror(err: Error) str = { - match (err) { - // InteractionError - case let e: InteractionError => - match (e) { - case Quit => - return ""; - case UnexpectedEOF => - return "Unexpected end-of-file input"; - case let e: encoding::utf8::invalid => - return encoding::utf8::strerror(e); - case let e: io::error => - return io::strerror(e); - }; - // CmdError - case InvalidAddress => - return "Invalid address"; - case NoFilename => - return "No filename"; - case WarnBufferModified => - return "Warning: Buffer modified"; - case UnexpectedAddress => - return "Unexpected address"; - case InvalidDestination => - return "Invalid destination"; - case NoMatch => - return "No match"; - case NoPrevRegex => - return "No previous search pattern"; - case NoPrevShCmd => - return "No previous shell command"; - case NoPrevGlobalSubCmd => - return "No previous global subcommand"; - case let e: InvalidGlobalSubCmd => - return "Invalid interactive global subcommand"; // TODO: append 'e'? - case let e: regex::error => - return regex::strerror(e); - case let e: fs::error => - return fs::strerror(e); - case let e: os::exec::error => - return os::exec::strerror(e); - // ParseError - case let e: UnknownCommand => - return "Unknown command"; // TODO: append 'e'? - case UnexpectedSuffix => - return "Unexpected suffix"; - case TrailingCharacters => - return "Trailing characters"; - case ExpectedArgument => - return "Expected argument"; - case ExpectedMark => - return "Expected mark"; - case InvalidDelimiter => - return "Invalid delimiter"; - case ExpectedDelimiter => - return "Expected delimiter"; - }; -};