ed

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

commit 473245f0a1963396ae069fd167f707a42fa3600e
parent 79a170f6ff4b1881d49041e6b3dc2ebcaeef5ac0
Author: Byron Torres <b@torresjrjr.com>
Date:   Sun, 19 May 2024 00:41:00 +0100

upgrade for-each

Diffstat:
Mcommand.ha | 39+++++++++++++++++----------------------
Mparse.ha | 84++++++++++++++++++++++++++-----------------------------------------------------
Mprint.ha | 9+--------
3 files changed, 45 insertions(+), 87 deletions(-)

diff --git a/command.ha b/command.ha @@ -716,29 +716,24 @@ fn cmd_shellescape(s: *Session, cmd: *Command) (void | Error) = { }; // handling '%' and '\%' - for (true) { - match (strings::next(&t)) { - case void => - break; - case let r: rune => - switch (r) { - case => - memio::appendrune(&new, r)!; - case '%' => - if (strings::prev(&t) == '\\') { - strings::next(&t); - memio::appendrune(&new, '%')!; - continue; - } else { - strings::next(&t); - }; - - if (s.buf.filename == "") - return NoFilename; - - memio::concat(&new, s.buf.filename)!; - preview = true; + for (let r: rune => strings::next(&t)) { + switch (r) { + case => + memio::appendrune(&new, r)!; + case '%' => + if (strings::prev(&t) == '\\') { + strings::next(&t); + memio::appendrune(&new, '%')!; + continue; + } else { + strings::next(&t); }; + + if (s.buf.filename == "") + return NoFilename; + + memio::concat(&new, s.buf.filename)!; + preview = true; }; }; diff --git a/parse.ha b/parse.ha @@ -151,7 +151,7 @@ fn parse_cmdargs(cmd: *Command, t: *strings::iterator) (bool | ParseError) = { match (strings::next(t)) { case let r: rune => return r: UnexpectedSuffix; - case void => + case done => return true; }; cmd.arg1 = scan_rest(t); @@ -168,7 +168,7 @@ fn parse_cmdargs(cmd: *Command, t: *strings::iterator) (bool | ParseError) = { } else { return r: InvalidSuffix; }; - case void => + case done => return true; }; cmd.arg1 = scan_rest(t); @@ -179,7 +179,7 @@ fn parse_cmdargs(cmd: *Command, t: *strings::iterator) (bool | ParseError) = { match (strings::next(t)) { case let r: rune => cmd.suffix = r; - case void => + case done => return ExpectedMark; }; scan_end_assert(t)?; @@ -211,7 +211,7 @@ fn parse_cmdargs(cmd: *Command, t: *strings::iterator) (bool | ParseError) = { // ./<regex>[/] where delimiter '/' is arbitrary case 'G', 'V' => cmd.delim = match (strings::next(t)) { - case void => + case done => return ExpectedArgument; case let r: rune => yield if (r == ' ') { @@ -228,7 +228,7 @@ fn parse_cmdargs(cmd: *Command, t: *strings::iterator) (bool | ParseError) = { // ./<regex>/<cmdlist...> case 'g', 'v' => cmd.delim = match (strings::next(t)) { - case void => + case done => return ExpectedArgument; case let r: rune => yield if (r == ' ') { @@ -248,7 +248,7 @@ fn parse_cmdargs(cmd: *Command, t: *strings::iterator) (bool | ParseError) = { // s/<regex>/[<replace>[/[<flags>]]] case 's' => cmd.delim = match (strings::next(t)) { - case void => + case done => return ExpectedArgument; case let r: rune => yield if (r == ' ') { @@ -260,13 +260,13 @@ fn parse_cmdargs(cmd: *Command, t: *strings::iterator) (bool | ParseError) = { cmd.arg1 = scan_item(t, cmd.delim).0; match (strings::next(t)) { case rune => void; - case void => + case done => return ExpectedDelimiter; }; append(cmd.textinput, scan_item(t, cmd.delim).0); match (strings::next(t)) { case rune => void; - case void => + case done => if (strings::prev(t) == '\\') return false else @@ -294,7 +294,7 @@ fn scan_addrs(t: *strings::iterator) []Address = { scan_blanks(t); match (strings::next(t)) { - case void => + case done => return addrs; case let r: rune => switch (r) { @@ -339,7 +339,7 @@ fn scan_addrs(t: *strings::iterator) []Address = { scan_blanks(t); match (strings::next(t)) { - case void => + case done => append(addrs, addr); break; case let r: rune => @@ -365,7 +365,7 @@ fn scan_addrs(t: *strings::iterator) []Address = { fn scan_addr(t: *strings::iterator) (Address | void) = { scan_blanks(t); let r = match (strings::next(t)) { - case void => + case done => return void; case let r: rune => yield r; @@ -433,7 +433,7 @@ fn scan_offsets(t: *strings::iterator) []int = { scan_blanks(t); match (strings::next(t)) { - case void => + case done => return offs; case let r: rune => if (r == '+') { @@ -455,7 +455,7 @@ fn scan_offsets(t: *strings::iterator) []int = { fn scan_offset(t: *strings::iterator) int = { match (strings::next(t)) { - case void => + case done => return 1; case let r: rune => strings::prev(t); @@ -470,7 +470,7 @@ fn scan_offset(t: *strings::iterator) int = { fn scan_cmdname(t: *strings::iterator) (rune | UnknownCommand) = { scan_blanks(t); let r = match (strings::next(t)) { - case void => + case done => return NUL; case let r: rune => yield r; @@ -490,7 +490,7 @@ fn scan_cmdname(t: *strings::iterator) (rune | UnknownCommand) = { fn scan_printmode(t: *strings::iterator) PrintMode = { let r = match (strings::next(t)) { - case void => + case done => return PrintMode::NONE; case let r: rune => yield r; @@ -512,13 +512,8 @@ fn scan_printmode(t: *strings::iterator) PrintMode = { fn scan_rest(t: *strings::iterator) str = { // TODO: just use [[strings::iterstr]]? let rs: []rune = []; - for (true) { - match (strings::next(t)) { - case void => - break; - case let r: rune => - append(rs, r); - }; + for (let r: rune => strings::next(t)) { + append(rs, r); }; return strings::trim(strings::fromrunes(rs)); }; @@ -526,16 +521,10 @@ fn scan_rest(t: *strings::iterator) str = { fn scan_item(t: *strings::iterator, delim: rune) (str, bool) = { let rs: []rune = []; let seen_delim = false; - for (true) { - let r = match (strings::next(t)) { - case void => - break; - case let r: rune => - yield r; - }; + for (let r: rune => strings::next(t)) { if (r == '\\') { match (strings::next(t)) { - case void => + case done => break; // TODO: Error here? how? case let r: rune => if (r == delim) { @@ -558,7 +547,7 @@ fn scan_item(t: *strings::iterator, delim: rune) (str, bool) = { fn scan_mark(t: *strings::iterator) rune = { match (strings::next(t)) { - case void => + case done => abort(); // TODO: aborts? case let r: rune => if (ascii::isalpha(r)) { // TODO: cover all mark chars @@ -574,14 +563,7 @@ fn scan_substitute_flags(t: *strings::iterator) (size, bool, PrintMode) = { let global = false; let printmode = PrintMode::NONE; - for (true) { - let r = match (strings::next(t)) { - case void => - break; - case let r: rune => - yield r; - }; - + for (let r => (strings::next(t))) { switch (r) { case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' => strings::prev(t); @@ -605,14 +587,7 @@ fn scan_substitute_flags(t: *strings::iterator) (size, bool, PrintMode) = { fn scan_size(t: *strings::iterator) size = { let begin = *t; // reimplement this function using another iterator - for (true) { - let r = match (strings::next(t)) { - case void => - break; - case let r: rune => - yield r; - }; - + for (let r => (strings::next(t))) { if (!ascii::isdigit(r)) { strings::prev(t); break; @@ -636,17 +611,12 @@ fn scan_size(t: *strings::iterator) size = { fn scan_blanks(t: *strings::iterator) size = { let sz = 0z; // runes, not bytes - for (true) { - match (strings::next(t)) { - case void => + for (let r: rune => strings::next(t)) { + if (!ascii::isblank(r)) { + strings::prev(t); break; - case let r: rune => - if (!ascii::isblank(r)) { - strings::prev(t); - break; - }; - sz += 1; }; + sz += 1; }; return sz; }; @@ -656,7 +626,7 @@ fn scan_end_assert(t: *strings::iterator) (void | TrailingCharacters) = { match (strings::next(t)) { case rune => return TrailingCharacters; - case void => + case done => return void; }; }; diff --git a/print.ha b/print.ha @@ -46,14 +46,7 @@ fn printlistline(text: str) (size | io::error) = { const t = strings::iter(text); let sz = 0z; - for (true) { - const r = match (strings::next(&t)) { - case void => - break; - case let r: rune => - yield r; - }; - + for (let r: rune => strings::next(&t)) { sz += switch (r) { case '\\' => yield fmt::print("\\\\")?;