ed

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

commit a907f4c2d1a1f39a4656c2a4a811d7eece717458
parent c039cba602527c25f4636093189b859adefd80be
Author: Byron Torres <b@torresjrjr.com>
Date:   Mon, 15 Jan 2024 22:41:16 +0000

tidy, rename iter -> t

Diffstat:
Mcommand.ha | 23+++++++++++------------
Mparse.ha | 204++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mprint.ha | 4++--
3 files changed, 115 insertions(+), 116 deletions(-)

diff --git a/command.ha b/command.ha @@ -345,8 +345,8 @@ fn cmd_move(s: *Session, cmd: *Command) (void | Error) = { assert_nonzero(s, a)?; // TODO: parse this properly in parse.ha? - const iter = strings::iter(cmd.arg1); - const addr = match (scan_addr(&iter)) { + const t = strings::iter(cmd.arg1); + const addr = match (scan_addr(&t)) { case let a: Address => yield a; case void => @@ -491,7 +491,6 @@ fn cmd_substitute(s: *Session, cmd: *Command) (void | Error) = { if (len(results) == 0) continue; - let iter = strings::iter(s.buf.lines[n].text); let new = memio::dynamic(); defer io::close(&new)!; let start = 0z; @@ -546,8 +545,8 @@ fn cmd_copy(s: *Session, cmd: *Command) (void | Error) = { assert_nonzero(s, a)?; // TODO: parse this properly in parse.ha? - const iter = strings::iter(cmd.arg1); - const addr = match (scan_addr(&iter)) { + const t = strings::iter(cmd.arg1); + const addr = match (scan_addr(&t)) { case let a: Address => yield a; case void => @@ -628,12 +627,12 @@ fn cmd_linenumber(s: *Session, cmd: *Command) (void | Error) = { fn cmd_shellescape(s: *Session, cmd: *Command) (void | Error) = { s.warned = false; - let iter = strings::iter(cmd.arg1); + let t = strings::iter(cmd.arg1); let new = memio::dynamic(); defer io::close(&new)!; let preview = false; // handling '!!' - if (strings::next(&iter) == '!') { + if (strings::next(&t) == '!') { match (s.lastshcmd) { case void => return NoPrevShCmd; @@ -642,12 +641,12 @@ fn cmd_shellescape(s: *Session, cmd: *Command) (void | Error) = { }; preview = true; } else { - strings::prev(&iter); + strings::prev(&t); }; // handling '%' and '\%' for (true) { - match (strings::next(&iter)) { + match (strings::next(&t)) { case void => break; case let r: rune => @@ -655,12 +654,12 @@ fn cmd_shellescape(s: *Session, cmd: *Command) (void | Error) = { case => memio::appendrune(&new, r)!; case '%' => - if (strings::prev(&iter) == '\\') { - strings::next(&iter); + if (strings::prev(&t) == '\\') { + strings::next(&t); memio::appendrune(&new, '%')!; continue; } else { - strings::next(&iter); + strings::next(&t); }; if (s.buf.filename == "") diff --git a/parse.ha b/parse.ha @@ -40,12 +40,12 @@ fn parse(input: *bufio::scanner) (Command | ParseError | InteractionError) = { return io::EOF; }; - let iter = strings::iter(inputline); + let t = strings::iter(inputline); let cmd = Command{ ... }; - cmd.addrs = scan_addrs(&iter); - cmd.name = scan_cmdname(&iter)?; - let ready = parse_cmdargs(&cmd, &iter)?; + cmd.addrs = scan_addrs(&t); + cmd.name = scan_cmdname(&t)?; + let ready = parse_cmdargs(&cmd, &t)?; switch :input (cmd.name) { case => void; @@ -109,8 +109,8 @@ fn parse(input: *bufio::scanner) (Command | ParseError | InteractionError) = { break; }; - let iter = strings::iter(inputline); - let (part, seen_delim) = scan_item(&iter, cmd.delim); + let t = strings::iter(inputline); + let (part, seen_delim) = scan_item(&t, cmd.delim); // cmd.textinput holds the replacement text append(cmd.textinput, strings::dup(part)); @@ -118,14 +118,14 @@ fn parse(input: *bufio::scanner) (Command | ParseError | InteractionError) = { if (!seen_delim && strings::hassuffix(inputline, '\\')) continue; - strings::next(&iter); // skip delim - let (count, global, printmode) = scan_substitute_flags(&iter); + strings::next(&t); // skip delim + let (count, global, printmode) = scan_substitute_flags(&t); //debug("count={} global={}", count, global); cmd.count = count; cmd.flag_global = global; cmd.printmode = printmode; - scan_end_assert(&iter)?; + scan_end_assert(&t)?; break; }; @@ -138,7 +138,7 @@ fn parse(input: *bufio::scanner) (Command | ParseError | InteractionError) = { }; // TODO: remove 'bool' returns -fn parse_cmdargs(cmd: *Command, iter: *strings::iterator) (bool | ParseError) = { +fn parse_cmdargs(cmd: *Command, t: *strings::iterator) (bool | ParseError) = { switch (cmd.name) { // [ ] case NUL => @@ -146,58 +146,58 @@ fn parse_cmdargs(cmd: *Command, iter: *strings::iterator) (bool | ParseError) = // (q|Q) case 'q', 'Q' => - scan_end_assert(iter)?; + scan_end_assert(t)?; return true; // .[ <file>] case 'e', 'E', 'f', 'r', 'w' => - if (scan_blanks(iter) == 0) - match (strings::next(iter)) { + if (scan_blanks(t) == 0) + match (strings::next(t)) { case let r: rune => return r: UnexpectedSuffix; case void => return true; }; - cmd.arg1 = scan_rest(iter); + cmd.arg1 = scan_rest(t); return true; // k<x> case 'k' => - match (strings::next(iter)) { + match (strings::next(t)) { case let r: rune => cmd.suffix = r; case void => return ExpectedMark; }; - scan_end_assert(iter)?; + scan_end_assert(t)?; return true; // !<shellcmd> case '!' => - cmd.arg1 = scan_rest(iter); + cmd.arg1 = scan_rest(t); return true; // .[s] where 's' is '(l|n|p)' case 'd', 'h', 'H', 'j', 'l', 'n', 'p', 'P', 'u', '=' => - cmd.printmode = scan_printmode(iter); - scan_end_assert(iter)?; + cmd.printmode = scan_printmode(t); + scan_end_assert(t)?; return true; // .[s] case 'a', 'c', 'i' => - cmd.printmode = scan_printmode(iter); - scan_end_assert(iter)?; + cmd.printmode = scan_printmode(t); + scan_end_assert(t)?; return false; // .[s][ ]<addr> case 'm', 't' => - cmd.printmode = scan_printmode(iter); - cmd.arg1 = scan_rest(iter); + cmd.printmode = scan_printmode(t); + cmd.arg1 = scan_rest(t); return true; // ./<regex>[/] where delimiter '/' is arbitrary case 'G', 'V' => - cmd.delim = match (strings::next(iter)) { + cmd.delim = match (strings::next(t)) { case void => return ExpectedArgument; case let r: rune => @@ -207,14 +207,14 @@ fn parse_cmdargs(cmd: *Command, iter: *strings::iterator) (bool | ParseError) = yield r; }; }; - cmd.arg1 = scan_item(iter, cmd.delim).0; - strings::next(iter); // scan delimiter if exists - scan_end_assert(iter)?; + cmd.arg1 = scan_item(t, cmd.delim).0; + strings::next(t); // scan delimiter if exists + scan_end_assert(t)?; return true; // ./<regex>/<cmdlist...> case 'g', 'v' => - cmd.delim = match (strings::next(iter)) { + cmd.delim = match (strings::next(t)) { case void => return ExpectedArgument; case let r: rune => @@ -224,17 +224,17 @@ fn parse_cmdargs(cmd: *Command, iter: *strings::iterator) (bool | ParseError) = yield r; }; }; - cmd.arg1 = scan_item(iter, cmd.delim).0; - strings::next(iter); // scan delimiter if exists - cmd.arg2 = scan_rest(iter); // TODO: append to .subcmds? - if (strings::prev(iter) as rune == '\\') { + cmd.arg1 = scan_item(t, cmd.delim).0; + strings::next(t); // scan delimiter if exists + cmd.arg2 = scan_rest(t); // TODO: append to .subcmds? + if (strings::prev(t) as rune == '\\') { return false; }; return true; // s/<regex>/[<replace>[/[<flags>]]] case 's' => - cmd.delim = match (strings::next(iter)) { + cmd.delim = match (strings::next(t)) { case void => return ExpectedArgument; case let r: rune => @@ -244,30 +244,30 @@ fn parse_cmdargs(cmd: *Command, iter: *strings::iterator) (bool | ParseError) = yield r; }; }; - cmd.arg1 = scan_item(iter, cmd.delim).0; - match (strings::next(iter)) { + cmd.arg1 = scan_item(t, cmd.delim).0; + match (strings::next(t)) { case rune => void; case void => return ExpectedDelimiter; }; - append(cmd.textinput, scan_item(iter, cmd.delim).0); - match (strings::next(iter)) { + append(cmd.textinput, scan_item(t, cmd.delim).0); + match (strings::next(t)) { case rune => void; case void => - if (strings::prev(iter) == '\\') + if (strings::prev(t) == '\\') return false else return true; }; - let (count, global, printmode) = scan_substitute_flags(iter); + let (count, global, printmode) = scan_substitute_flags(t); cmd.count = count; cmd.flag_global = global; cmd.printmode = printmode; - scan_end_assert(iter)?; + scan_end_assert(t)?; return true; case '&' => - scan_end_assert(iter)?; + scan_end_assert(t)?; return true; case => @@ -275,12 +275,12 @@ fn parse_cmdargs(cmd: *Command, iter: *strings::iterator) (bool | ParseError) = }; }; -fn scan_addrs(iter: *strings::iterator) []Address = { +fn scan_addrs(t: *strings::iterator) []Address = { let addrs: []Address = []; let specialfirst = false; - scan_blanks(iter); - match (strings::next(iter)) { + scan_blanks(t); + match (strings::next(t)) { case void => return addrs; case let r: rune => @@ -300,12 +300,12 @@ fn scan_addrs(iter: *strings::iterator) []Address = { setcurrentline = true, }); case => - strings::prev(iter); + strings::prev(t); }; }; for (true) { - let addr = match (scan_addr(iter)) { + let addr = match (scan_addr(t)) { case void => yield if (specialfirst) { yield Address{ @@ -324,8 +324,8 @@ fn scan_addrs(iter: *strings::iterator) []Address = { specialfirst = false; - scan_blanks(iter); - match (strings::next(iter)) { + scan_blanks(t); + match (strings::next(t)) { case void => append(addrs, addr); break; @@ -338,7 +338,7 @@ fn scan_addrs(iter: *strings::iterator) []Address = { append(addrs, addr); case => append(addrs, addr); - strings::prev(iter); + strings::prev(t); break; }; }; @@ -349,9 +349,9 @@ fn scan_addrs(iter: *strings::iterator) []Address = { return addrs; }; -fn scan_addr(iter: *strings::iterator) (Address | void) = { - scan_blanks(iter); - let r = match (strings::next(iter)) { +fn scan_addr(t: *strings::iterator) (Address | void) = { + scan_blanks(t); + let r = match (strings::next(t)) { case void => return void; case let r: rune => @@ -366,30 +366,30 @@ fn scan_addr(iter: *strings::iterator) (Address | void) = { case '$' => yield LastLine; case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' => - strings::prev(iter); - yield scan_size(iter); + strings::prev(t); + yield scan_size(t); case '\'' => - yield scan_mark(iter); + yield scan_mark(t); case '/' => const rad = RegexAddr{ - expr = scan_item(iter, '/').0, + expr = scan_item(t, '/').0, direction = true, }; - strings::next(iter); + strings::next(t); yield rad; case '?' => const rad = RegexAddr{ - expr = scan_item(iter, '?').0, + expr = scan_item(t, '?').0, direction = false, }; - strings::next(iter); + strings::next(t); yield rad; case => - strings::prev(iter); + strings::prev(t); yield void; }; - const offs = scan_offsets(iter); + const offs = scan_offsets(t); if (addrform is void && len(offs) == 0) return void; @@ -413,25 +413,25 @@ fn scan_addr(iter: *strings::iterator) (Address | void) = { return addr; }; -fn scan_offsets(iter: *strings::iterator) []int = { +fn scan_offsets(t: *strings::iterator) []int = { let offs: []int = []; for (true) { - scan_blanks(iter); + scan_blanks(t); - match (strings::next(iter)) { + match (strings::next(t)) { case void => return offs; case let r: rune => if (r == '+') { - append(offs, scan_offset(iter)); + append(offs, scan_offset(t)); } else if (r == '-') { - append(offs, -scan_offset(iter)); + append(offs, -scan_offset(t)); } else if (ascii::isdigit(r)) { - strings::prev(iter); - append(offs, scan_size(iter): int); + strings::prev(t); + append(offs, scan_size(t): int); } else { - strings::prev(iter); + strings::prev(t); break; }; }; @@ -440,23 +440,23 @@ fn scan_offsets(iter: *strings::iterator) []int = { return offs; }; -fn scan_offset(iter: *strings::iterator) int = { - match (strings::next(iter)) { +fn scan_offset(t: *strings::iterator) int = { + match (strings::next(t)) { case void => return 1; case let r: rune => - strings::prev(iter); + strings::prev(t); if (ascii::isdigit(r)) { - return scan_size(iter): int; + return scan_size(t): int; } else { return 1; }; }; }; -fn scan_cmdname(iter: *strings::iterator) (rune | UnknownCommand) = { - scan_blanks(iter); - let r = match (strings::next(iter)) { +fn scan_cmdname(t: *strings::iterator) (rune | UnknownCommand) = { + scan_blanks(t); + let r = match (strings::next(t)) { case void => return NUL; case let r: rune => @@ -475,8 +475,8 @@ fn scan_cmdname(iter: *strings::iterator) (rune | UnknownCommand) = { }; }; -fn scan_printmode(iter: *strings::iterator) PrintMode = { - let r = match (strings::next(iter)) { +fn scan_printmode(t: *strings::iterator) PrintMode = { + let r = match (strings::next(t)) { case void => return PrintMode::NONE; case let r: rune => @@ -491,16 +491,16 @@ fn scan_printmode(iter: *strings::iterator) PrintMode = { case 'l' => return PrintMode::LIST; case => - strings::prev(iter); + strings::prev(t); return PrintMode::NONE; }; }; -fn scan_rest(iter: *strings::iterator) str = { +fn scan_rest(t: *strings::iterator) str = { // TODO: just use [[strings::iterstr]]? let rs: []rune = []; for (true) { - match (strings::next(iter)) { + match (strings::next(t)) { case void => break; case let r: rune => @@ -510,18 +510,18 @@ fn scan_rest(iter: *strings::iterator) str = { return strings::trim(strings::fromrunes(rs)); }; -fn scan_item(iter: *strings::iterator, delim: rune) (str, bool) = { +fn scan_item(t: *strings::iterator, delim: rune) (str, bool) = { let rs: []rune = []; let seen_delim = false; for (true) { - let r = match (strings::next(iter)) { + let r = match (strings::next(t)) { case void => break; case let r: rune => yield r; }; if (r == '\\') { - match (strings::next(iter)) { + match (strings::next(t)) { case void => break; // TODO: Error here? how? case let r: rune => @@ -535,7 +535,7 @@ fn scan_item(iter: *strings::iterator, delim: rune) (str, bool) = { }; } else if (r == delim) { seen_delim = true; - strings::prev(iter); + strings::prev(t); break; }; append(rs, r); @@ -543,8 +543,8 @@ fn scan_item(iter: *strings::iterator, delim: rune) (str, bool) = { return (strings::fromrunes(rs), seen_delim); }; -fn scan_mark(iter: *strings::iterator) rune = { - match (strings::next(iter)) { +fn scan_mark(t: *strings::iterator) rune = { + match (strings::next(t)) { case void => abort(); // TODO: aborts? case let r: rune => @@ -556,13 +556,13 @@ fn scan_mark(iter: *strings::iterator) rune = { }; }; -fn scan_substitute_flags(iter: *strings::iterator) (size, bool, PrintMode) = { +fn scan_substitute_flags(t: *strings::iterator) (size, bool, PrintMode) = { let count = 0z; let global = false; let printmode = PrintMode::NONE; for (true) { - let r = match (strings::next(iter)) { + let r = match (strings::next(t)) { case void => break; case let r: rune => @@ -571,8 +571,8 @@ fn scan_substitute_flags(iter: *strings::iterator) (size, bool, PrintMode) = { switch (r) { case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' => - strings::prev(iter); - count = scan_size(iter); + strings::prev(t); + count = scan_size(t); case 'g' => global = true; case 'p' => @@ -589,11 +589,11 @@ fn scan_substitute_flags(iter: *strings::iterator) (size, bool, PrintMode) = { return (count, global, printmode); }; -fn scan_size(iter: *strings::iterator) size = { - let begin = *iter; +fn scan_size(t: *strings::iterator) size = { + let begin = *t; // reimplement this function using another iterator for (true) { - let r = match (strings::next(iter)) { + let r = match (strings::next(t)) { case void => break; case let r: rune => @@ -601,12 +601,12 @@ fn scan_size(iter: *strings::iterator) size = { }; if (!ascii::isdigit(r)) { - strings::prev(iter); + strings::prev(t); break; }; }; - let num = strings::slice(&begin, iter); + let num = strings::slice(&begin, t); // TODO: return void instead? if (num == "") { @@ -621,15 +621,15 @@ fn scan_size(iter: *strings::iterator) size = { }; }; -fn scan_blanks(iter: *strings::iterator) size = { +fn scan_blanks(t: *strings::iterator) size = { let sz = 0z; // runes, not bytes for (true) { - match (strings::next(iter)) { + match (strings::next(t)) { case void => break; case let r: rune => if (!ascii::isblank(r)) { - strings::prev(iter); + strings::prev(t); break; }; sz += 1; @@ -638,9 +638,9 @@ fn scan_blanks(iter: *strings::iterator) size = { return sz; }; -fn scan_end_assert(iter: *strings::iterator) (void | TrailingCharacters) = { - scan_blanks(iter); - match (strings::next(iter)) { +fn scan_end_assert(t: *strings::iterator) (void | TrailingCharacters) = { + scan_blanks(t); + match (strings::next(t)) { case rune => return TrailingCharacters; case void => diff --git a/print.ha b/print.ha @@ -45,11 +45,11 @@ fn printlist(buf: *Buffer, a: size, b: size) (size | io::error) = { fn printlistline(text: str) (size | io::error) = { // TODO: handle wrapping (see ed(1) > list command) - const iter = strings::iter(text); + const t = strings::iter(text); let sz = 0z; for (true) { - const r = match (strings::next(&iter)) { + const r = match (strings::next(&t)) { case void => break; case let r: rune =>