ed

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

commit 3419b64db4530d3ca383a5d7e2d1418a3aebd2ed
parent 5d5c690c2845eb85b51ebeda80fc3e7aa1923bd7
Author: Byron Torres <b@torresjrjr.com>
Date:   Sun, 25 Jun 2023 04:30:11 +0100

PascalCase types

Diffstat:
Maddress.ha | 38+++++++++++++++++++-------------------
Mbuffer.ha | 24++++++++++++------------
Mcommand.ha | 142++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mexecute.ha | 32++++++++++++++++----------------
Mmain.ha | 48++++++++++++++++++++++++------------------------
Mparse.ha | 102++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mutil.ha | 12++++++------
7 files changed, 199 insertions(+), 199 deletions(-)

diff --git a/address.ha b/address.ha @@ -1,71 +1,71 @@ use regex; -type address = struct { - addrtype: addresstype, +type Address = struct { + addrtype: AddressType, lineoffset: int, setcurrentline: bool, }; -type addresstype = (size | currentline | lastline | rune | regexaddr); +type AddressType = (size | CurrentLine | LastLine | rune | RegexAddr); // The dot '.' address. -type currentline = void; +type CurrentLine = void; // The dollar '$' address. -type lastline = void; +type LastLine = void; // Regular expression search. /forward/ is true, ?backward? is false. -type regexaddr = struct { +type RegexAddr = struct { expr: str, direction: bool, }; // The address was invalid. -type invalidaddress = !void; +type InvalidAddress = !void; // A regular expression search found no match. -type nomatch = !void; +type NoMatch = !void; -fn addr_nextline(buf: *buffer, n: size) size = { +fn addr_nextline(buf: *Buffer, n: size) size = { if (len(buf.lines) - 1 == n) { return n; }; return n + 1; }; -fn addr_prevline(buf: *buffer, n: size) size = { +fn addr_prevline(buf: *Buffer, n: size) size = { if (n == 0 || n == 1) { return n; }; return n - 1; }; -fn addr_linenum(buf: *buffer, n: size) (size | invalidaddress) = { +fn addr_linenum(buf: *Buffer, n: size) (size | InvalidAddress) = { if (n >= len(buf.lines)) { - return invalidaddress; + return InvalidAddress; }; return n; }; -fn addr_lastline(buf: *buffer) size = { +fn addr_lastline(buf: *Buffer) size = { return len(buf.lines) - 1z; }; -fn addr_mark(buf: *buffer, mark: rune) (size | invalidaddress) = { +fn addr_mark(buf: *Buffer, mark: rune) (size | InvalidAddress) = { for (let n = 1z; n < len(buf.lines); n += 1) { const l = buf.lines[n]; if (l.mark == mark) { return n; }; }; - return invalidaddress; + return InvalidAddress; }; fn addr_regex( - buf: *buffer, - rad: regexaddr, + buf: *Buffer, + rad: RegexAddr, start: size, -) (size | nomatch | regex::error) = { +) (size | NoMatch | regex::error) = { const length = len(buf.lines); // TODO: use BRE, not ERE. const re = regex::compile(rad.expr)?; defer regex::finish(&re); @@ -85,5 +85,5 @@ fn addr_regex( }; }; - return nomatch; + return NoMatch; }; diff --git a/buffer.ha b/buffer.ha @@ -3,21 +3,21 @@ use fmt; use io; use strings; -type buffer = struct { +type Buffer = struct { filename: str, - lines: []*line, - trash: []*line, + lines: []*Line, + trash: []*Line, cursor: size, modified: bool, }; -type line = struct { +type Line = struct { text: str, mark: rune, globalmark: bool, }; -fn buf_insert(buf: *buffer, n: size, ls: *line...) void = { +fn buf_insert(buf: *Buffer, n: size, ls: *Line...) void = { debug("buf_insert(n={}), len(ls)={}", n, len(ls)); // for (let i = 0z; i < len(ls); i += 1) { // debug("buf_insert(): ls[{}].text='{}'", i, ls[i].text); @@ -25,7 +25,7 @@ fn buf_insert(buf: *buffer, n: size, ls: *line...) void = { insert(buf.lines[n], ls...); }; -fn buf_deleteall(buf: *buffer) void = { +fn buf_deleteall(buf: *Buffer) void = { // buf_wipetrash(buf); if (len(buf.lines) > 1) { @@ -34,7 +34,7 @@ fn buf_deleteall(buf: *buffer) void = { }; }; -fn buf_delete(buf: *buffer, a: size, b: size) void = { +fn buf_delete(buf: *Buffer, a: size, b: size) void = { debug("buf_delete(a={}, b={})", a, b); // buf_wipetrash(buf); @@ -42,11 +42,11 @@ fn buf_delete(buf: *buffer, a: size, b: size) void = { delete(buf.lines[a..b+1]); }; -fn buf_read(buf: *buffer, src: io::handle, a: size) (size, size) = { +fn buf_read(buf: *Buffer, src: io::handle, a: size) (size, size) = { // TODO: don't call this here, call it at a higher level // buf_wipetrash(buf); - let ls: []*line = []; + let ls: []*Line = []; let sz = 0z; for (true) { const bytes = match (bufio::scanline(src)) { @@ -61,7 +61,7 @@ fn buf_read(buf: *buffer, src: io::handle, a: size) (size, size) = { sz += len(bytes) + 1; // TODO: handle newlines better const text = strings::fromutf8(bytes)!; - append(ls, alloc(line { text = text, ... })); + append(ls, alloc(Line { text = text, ... })); }; insert(buf.lines[a + 1], ls...); @@ -69,7 +69,7 @@ fn buf_read(buf: *buffer, src: io::handle, a: size) (size, size) = { return (sz, lenls); }; -fn buf_write(buf: *buffer, dest: io::handle, a: size, b: size) size = { +fn buf_write(buf: *Buffer, dest: io::handle, a: size, b: size) size = { let sz = 0z; for (let n = a; n <= b; n += 1) { sz += fmt::fprintln(dest, buf.lines[n].text)!; @@ -77,7 +77,7 @@ fn buf_write(buf: *buffer, dest: io::handle, a: size, b: size) size = { return sz; }; -fn buf_wipetrash(buf: *buffer) void = { +fn buf_wipetrash(buf: *Buffer) void = { for (let i = 0z; i < len(buf.trash); i += 1) { free(buf.trash[i].text); free(buf.trash[i]); diff --git a/command.ha b/command.ha @@ -8,50 +8,50 @@ use regex; use strings; use strio; -type command = struct { - addrs: []address, +type Command = struct { + addrs: []Address, linenums: []size, cmdname: rune, - printmode: printmode, + printmode: PrintMode, arg: str, arg2: str, arg3: str, input: []str, - subcmds: []command, + subcmds: []Command, }; -type commandfn = *fn(*session, *command) (void | error); +type CommandFn = *fn(*Session, *Command) (void | Error); -type printmode = enum { +type PrintMode = enum { NONE, LIST, NUMBER, PRINT, }; -type error = !( - invalidaddress - | unexpectedaddress - | invaliddestination - | nofilename - | buffermodified - | nomatch - | noprevshcmd +type Error = !( + InvalidAddress + | UnexpectedAddress + | InvalidDestination + | NoFilename + | BufferModified + | NoMatch + | NoPrevShCmd | regex::error | fs::error ); -type unexpectedaddress = !void; +type UnexpectedAddress = !void; -type invaliddestination = !void; +type InvalidDestination = !void; -type nofilename = !void; +type NoFilename = !void; -type buffermodified = !void; +type BufferModified = !void; -type noprevshcmd = !void; +type NoPrevShCmd = !void; -fn lookupcmd(name: rune) commandfn = { +fn lookupcmd(name: rune) CommandFn = { switch (name) { case 'a' => return &cmd_append; case 'c' => return &cmd_change; @@ -86,11 +86,11 @@ fn lookupcmd(name: rune) commandfn = { }; }; -fn cmd_append(s: *session, cmd: *command) (void | error) = { +fn cmd_append(s: *Session, cmd: *Command) (void | Error) = { const n = get_linenum(cmd.linenums, s.buf.cursor); for (let i = 0z; i < len(cmd.input); i += 1) { - const l = alloc(line { text = cmd.input[i], ... }); + const l = alloc(Line { text = cmd.input[i], ... }); debug("cmd_append(): l.text={}", l.text); buf_insert(&s.buf, n + 1 + i, l); }; @@ -98,7 +98,7 @@ fn cmd_append(s: *session, cmd: *command) (void | error) = { s.buf.cursor = n + len(cmd.input); }; -fn cmd_change(s: *session, cmd: *command) (void | error) = { +fn cmd_change(s: *Session, cmd: *Command) (void | Error) = { const (a, b) = get_range( s, &cmd.linenums, @@ -115,7 +115,7 @@ fn cmd_change(s: *session, cmd: *command) (void | error) = { buf_delete(&s.buf, a, b); for (let i = 0z; i < len(cmd.input); i += 1) { - const l = alloc(line { text = cmd.input[i], ... }); + const l = alloc(Line { text = cmd.input[i], ... }); debug("cmd_append(): l.text={}", l.text); buf_insert(&s.buf, a + i, l); }; @@ -131,7 +131,7 @@ fn cmd_change(s: *session, cmd: *command) (void | error) = { }; }; -fn cmd_delete(s: *session, cmd: *command) (void | error) = { +fn cmd_delete(s: *Session, cmd: *Command) (void | Error) = { const (a, b) = get_range( s, &cmd.linenums, @@ -150,12 +150,12 @@ fn cmd_delete(s: *session, cmd: *command) (void | error) = { }; }; -fn cmd_edit(s: *session, cmd: *command) (void | error) = { +fn cmd_edit(s: *Session, cmd: *Command) (void | Error) = { assert_noaddrs(s, cmd.linenums)?; if (s.buf.modified && !s.warned) { - s.warned = true; // TODO: reset this every command somehow - return buffermodified; + s.warned = true; // TODO: reset this every Command somehow + return BufferModified; }; const fname = if (len(cmd.arg) != 0) { @@ -164,7 +164,7 @@ fn cmd_edit(s: *session, cmd: *command) (void | error) = { } else if (len(s.buf.filename) != 0) { yield s.buf.filename; } else { - return nofilename; + return NoFilename; }; const h = match (os::open(fname)) { @@ -183,31 +183,31 @@ fn cmd_edit(s: *session, cmd: *command) (void | error) = { s.buf.cursor = len(s.buf.lines) - 1; }; -fn cmd_edit_forced(s: *session, cmd: *command) (void | error) = void; +fn cmd_edit_forced(s: *Session, cmd: *Command) (void | Error) = void; -fn cmd_filename(s: *session, cmd: *command) (void | error) = { +fn cmd_filename(s: *Session, cmd: *Command) (void | Error) = { assert_noaddrs(s, cmd.linenums)?; if (len(cmd.arg) != 0) { s.buf.filename = cmd.arg; }; if (len(s.buf.filename) == 0) { - return nofilename; + return NoFilename; }; fmt::println(s.buf.filename)!; }; -fn cmd_global(s: *session, cmd: *command) (void | error) = void; +fn cmd_global(s: *Session, cmd: *Command) (void | Error) = void; -fn cmd_global_manual(s: *session, cmd: *command) (void | error) = void; +fn cmd_global_manual(s: *Session, cmd: *Command) (void | Error) = void; -fn cmd_help(s: *session, cmd: *command) (void | error) = { +fn cmd_help(s: *Session, cmd: *Command) (void | Error) = { assert_noaddrs(s, cmd.linenums)?; if (s.lasterror != "") { fmt::println(s.lasterror)!; }; }; -fn cmd_helpmode(s: *session, cmd: *command) (void | error) = { +fn cmd_helpmode(s: *Session, cmd: *Command) (void | Error) = { assert_noaddrs(s, cmd.linenums)?; s.helpmode = !s.helpmode; if (s.helpmode && s.lasterror != "") { @@ -215,12 +215,12 @@ fn cmd_helpmode(s: *session, cmd: *command) (void | error) = { }; }; -fn cmd_insert(s: *session, cmd: *command) (void | error) = { +fn cmd_insert(s: *Session, cmd: *Command) (void | Error) = { const n = get_linenum(cmd.linenums, s.buf.cursor); const n = if (n == 0) 1z else n; for (let i = 0z; i < len(cmd.input); i += 1) { - const l = alloc(line { text = cmd.input[i], ... }); + const l = alloc(Line { text = cmd.input[i], ... }); debug("cmd_append(): l.text={}", l.text); buf_insert(&s.buf, n + i, l); }; @@ -232,7 +232,7 @@ fn cmd_insert(s: *session, cmd: *command) (void | error) = { }; }; -fn cmd_join(s: *session, cmd: *command) (void | error) = { +fn cmd_join(s: *Session, cmd: *Command) (void | Error) = { const (a, b) = get_range( s, &cmd.linenums, @@ -256,7 +256,7 @@ fn cmd_join(s: *session, cmd: *command) (void | error) = { }; const newtext = strings::concat(ls...); - const newline = alloc(line { + const newline = alloc(Line { text = newtext, mark = mark, ... @@ -266,7 +266,7 @@ fn cmd_join(s: *session, cmd: *command) (void | error) = { buf_insert(&s.buf, a, newline); }; -fn cmd_mark(s: *session, cmd: *command) (void | error) = { +fn cmd_mark(s: *Session, cmd: *Command) (void | Error) = { const n = get_linenum(cmd.linenums, s.buf.cursor); assert_nonzero(s, n)?; @@ -303,7 +303,7 @@ fn cmd_mark(s: *session, cmd: *command) (void | error) = { s.buf.lines[n].mark = mark; }; -fn cmd_list(s: *session, cmd: *command) (void | error) = { +fn cmd_list(s: *Session, cmd: *Command) (void | Error) = { const (a, b) = get_range( s, &cmd.linenums, @@ -317,7 +317,7 @@ fn cmd_list(s: *session, cmd: *command) (void | error) = { s.buf.cursor = b; }; -fn cmd_move(s: *session, cmd: *command) (void | error) = { +fn cmd_move(s: *Session, cmd: *Command) (void | Error) = { const (a, b) = get_range( s, &cmd.linenums, @@ -329,21 +329,21 @@ fn cmd_move(s: *session, cmd: *command) (void | error) = { // TODO: parse this properly in parse.ha? const iter = strings::iter(cmd.arg); const n = match (scan_addr(&iter)) { - case let addr: address => + case let addr: Address => const n = match (exec_addr(s, addr)) { case let n: size => yield n; - case invalidaddress => - return invaliddestination; + case InvalidAddress => + return InvalidDestination; }; yield n + 1; // like insert case void => - return invalidaddress; + return InvalidAddress; }; debug("cmd_move(): n={}", n); if (a < n && n <= b) { - return invaliddestination; + return InvalidDestination; }; if (n == b + 1) { @@ -363,7 +363,7 @@ fn cmd_move(s: *session, cmd: *command) (void | error) = { s.buf.cursor = dest - 1 + len(ls); }; -fn cmd_number(s: *session, cmd: *command) (void | error) = { +fn cmd_number(s: *Session, cmd: *Command) (void | Error) = { const (a, b) = get_range( s, &cmd.linenums, @@ -377,7 +377,7 @@ fn cmd_number(s: *session, cmd: *command) (void | error) = { s.buf.cursor = b; }; -fn cmd_print(s: *session, cmd: *command) (void | error) = { +fn cmd_print(s: *Session, cmd: *Command) (void | Error) = { const (a, b) = get_range( s, &cmd.linenums, @@ -390,16 +390,16 @@ fn cmd_print(s: *session, cmd: *command) (void | error) = { s.buf.cursor = b; }; -fn cmd_prompt(s: *session, cmd: *command) (void | error) = { +fn cmd_prompt(s: *Session, cmd: *Command) (void | Error) = { assert_noaddrs(s, cmd.linenums)?; s.promptmode = !s.promptmode; }; -fn cmd_quit(s: *session, cmd: *command) (void | error) = void; +fn cmd_quit(s: *Session, cmd: *Command) (void | Error) = void; -fn cmd_quit_forced(s: *session, cmd: *command) (void | error) = void; +fn cmd_quit_forced(s: *Session, cmd: *Command) (void | Error) = void; -fn cmd_read(s: *session, cmd: *command) (void | error) = { +fn cmd_read(s: *Session, cmd: *Command) (void | Error) = { const n = get_linenum(cmd.linenums, s.buf.cursor); const fname = if (len(cmd.arg) != 0) { s.buf.filename = cmd.arg; @@ -408,7 +408,7 @@ fn cmd_read(s: *session, cmd: *command) (void | error) = { yield if (len(s.buf.filename) != 0) { yield s.buf.filename; } else { - return nofilename; + return NoFilename; }; }; @@ -422,7 +422,7 @@ fn cmd_read(s: *session, cmd: *command) (void | error) = { s.buf.cursor = len(s.buf.lines) - 1; }; -fn cmd_substitute(s: *session, cmd: *command) (void | error) = { +fn cmd_substitute(s: *Session, cmd: *Command) (void | Error) = { const (a, b) = get_range( s, &cmd.linenums, @@ -458,7 +458,7 @@ fn cmd_substitute(s: *session, cmd: *command) (void | error) = { }; strio::concat(&new, strings::sub(old, rbound, strings::end))!; - let newline = alloc(line { + let newline = alloc(Line { text = strings::dup(strio::string(&new)), ... }); @@ -468,7 +468,7 @@ fn cmd_substitute(s: *session, cmd: *command) (void | error) = { }; }; -fn cmd_copy(s: *session, cmd: *command) (void | error) = { +fn cmd_copy(s: *Session, cmd: *Command) (void | Error) = { const (a, b) = get_range( s, &cmd.linenums, @@ -480,15 +480,15 @@ fn cmd_copy(s: *session, cmd: *command) (void | error) = { // TODO: parse this properly in parse.ha? const iter = strings::iter(cmd.arg); const dest = match (scan_addr(&iter)) { - case let addr: address => + case let addr: Address => yield 1 + (match (exec_addr(s, addr)) { case let n: size => yield n; - case invalidaddress => - return invaliddestination; + case InvalidAddress => + return InvalidDestination; }); case void => - return invalidaddress; + return InvalidAddress; }; debug("cmd_copy(): dest={}", dest); @@ -498,13 +498,13 @@ fn cmd_copy(s: *session, cmd: *command) (void | error) = { s.buf.cursor = dest - 1 + len(ls); }; -fn cmd_undo(s: *session, cmd: *command) (void | error) = void; +fn cmd_undo(s: *Session, cmd: *Command) (void | Error) = void; -fn cmd_invglobal(s: *session, cmd: *command) (void | error) = void; +fn cmd_invglobal(s: *Session, cmd: *Command) (void | Error) = void; -fn cmd_invglobal_manual(s: *session, cmd: *command) (void | error) = void; +fn cmd_invglobal_manual(s: *Session, cmd: *Command) (void | Error) = void; -fn cmd_write(s: *session, cmd: *command) (void | error) = { +fn cmd_write(s: *Session, cmd: *Command) (void | Error) = { const (a, b) = get_range( s, &cmd.linenums, @@ -520,7 +520,7 @@ fn cmd_write(s: *session, cmd: *command) (void | error) = { yield if (len(s.buf.filename) != 0) { yield s.buf.filename; } else { - return nofilename; + return NoFilename; }; }; @@ -543,12 +543,12 @@ fn cmd_write(s: *session, cmd: *command) (void | error) = { }; }; -fn cmd_linenumber(s: *session, cmd: *command) (void | error) = { +fn cmd_linenumber(s: *Session, cmd: *Command) (void | Error) = { const n = get_linenum(cmd.linenums, addr_lastline(&s.buf)); fmt::println(n)!; }; -fn cmd_shellescape(s: *session, cmd: *command) (void | error) = { +fn cmd_shellescape(s: *Session, cmd: *Command) (void | Error) = { let iter = strings::iter(cmd.arg); let new = strio::dynamic(); defer io::close(&new)!; let preview = false; @@ -557,7 +557,7 @@ fn cmd_shellescape(s: *session, cmd: *command) (void | error) = { if (strings::next(&iter) == '!') { match (s.prev_shcmd) { case void => - return noprevshcmd; + return NoPrevShCmd; case let s: str => strio::concat(&new, s)!; }; @@ -612,7 +612,7 @@ fn cmd_shellescape(s: *session, cmd: *command) (void | error) = { s.prev_shcmd = shcmdline; }; -fn cmd_null(s: *session, cmd: *command) (void | error) = { +fn cmd_null(s: *Session, cmd: *Command) (void | Error) = { const n = get_linenum( cmd.linenums, addr_nextline(&s.buf, s.buf.cursor), diff --git a/execute.ha b/execute.ha @@ -1,24 +1,24 @@ -// Executes the session's .cmd command. -fn execute(s: *session, cmd: *command) (void | error) = { +// Executes the Session's .cmd Command. +fn execute(s: *Session, cmd: *Command) (void | Error) = { // TODO: move this into the cmd_* functions? match (exec_addrs(s, cmd)) { case void => void; - case let err: error => + case let err: Error => delete(cmd.linenums[..]); return errormsg(s, err); }; // TODO: write finish_cmd() - // TODO: finish the command at a higher level (main()) ?. + // TODO: finish the Command at a higher level (main()) ?. defer delete(cmd.linenums[..]); match (lookupcmd(cmd.cmdname)(s, cmd)) { case void => void; - case let err: error => + case let err: Error => return errormsg(s, err); }; }; -fn exec_addrs(s: *session, cmd: *command) (void | error) = { +fn exec_addrs(s: *Session, cmd: *Command) (void | Error) = { for (let i = 0z; i < len(cmd.addrs); i += 1) { const addr = cmd.addrs[i]; let n = exec_addr(s, addr)?; @@ -37,23 +37,23 @@ fn exec_addrs(s: *session, cmd: *command) (void | error) = { }; }; -fn exec_addr(s: *session, addr: address) (size | error) = { +fn exec_addr(s: *Session, addr: Address) (size | Error) = { match (addr.addrtype) { case let n: size => return addr_linenum(&s.buf, n)?; - case currentline => + case CurrentLine => return s.buf.cursor; - case lastline => + case LastLine => return addr_lastline(&s.buf); case let m: rune => return addr_mark(&s.buf, m)?; - case let rad: regexaddr => + case let rad: RegexAddr => return addr_regex(&s.buf, rad, s.buf.cursor)?; }; }; -fn get_range(s: *session, lns: *[]size, a: size, b: size) ((size, size) | invalidaddress) = { +fn get_range(s: *Session, lns: *[]size, a: size, b: size) ((size, size) | InvalidAddress) = { debug("get_range(): len(lns)={}", len(lns)); const (a, b) = if (len(lns) == 0) { yield (a, b); @@ -64,7 +64,7 @@ fn get_range(s: *session, lns: *[]size, a: size, b: size) ((size, size) | invali }; debug("get_range(): (a, b)=({}, {})", a, b); if (a < 0 || a > b || b >= len(s.buf.lines)) { - return invalidaddress; + return InvalidAddress; }; return (a, b); }; @@ -77,14 +77,14 @@ fn get_linenum(lns: []size, n: size) size = { }; }; -fn assert_noaddrs(s: *session, lns: []size) (void | unexpectedaddress) = { +fn assert_noaddrs(s: *Session, lns: []size) (void | UnexpectedAddress) = { if (len(lns) != 0) { - return unexpectedaddress; + return UnexpectedAddress; }; }; -fn assert_nonzero(s: *session, n: size) (void | invalidaddress) = { +fn assert_nonzero(s: *Session, n: size) (void | InvalidAddress) = { if (n < 1) { - return invalidaddress; + return InvalidAddress; }; }; diff --git a/main.ha b/main.ha @@ -8,9 +8,9 @@ use os; use regex; use strings; -type session = struct { - buf: buffer, - mode: mode, +type Session = struct { + buf: Buffer, + mode: Mode, helpmode: bool, lasterror: str, suppressmode: bool, @@ -20,7 +20,7 @@ type session = struct { prev_shcmd: (str | void), }; -type mode = enum { +type Mode = enum { COMMAND, INPUT, }; @@ -35,10 +35,10 @@ export fn main() void = { const main_cmd = getopt::parse(os::args, help...); defer getopt::finish(&main_cmd); - let s = session { - buf = buffer { - lines = *alloc([ alloc(line { ... }) ]), - trash = *alloc([]: []*line), + let s = Session { + buf = Buffer { + lines = *alloc([ alloc(Line { ... }) ]), + trash = *alloc([]: []*Line), ... }, prompt = "*", @@ -46,7 +46,7 @@ export fn main() void = { ... }; - let cmd = command { ... }; + let cmd = Command { ... }; for (let i = 0z; i < len(main_cmd.opts); i += 1) { const opt = main_cmd.opts[i]; @@ -79,10 +79,10 @@ export fn main() void = { cmd_edit(&s, &cmd): void; }; - let cmd = command { ... }; + let cmd = Command { ... }; for (true) :repl { - if (s.promptmode && s.mode == mode::COMMAND) { + if (s.promptmode && s.mode == Mode::COMMAND) { fmt::error(s.prompt)!; }; @@ -106,9 +106,9 @@ export fn main() void = { }; switch (s.mode) { - case mode::COMMAND => + case Mode::COMMAND => const execnow = match (parse(&cmd, input)) { - case let e: parseerror => + case let e: ParseError => continue; // TODO: print error case let b: bool => yield b; @@ -118,14 +118,14 @@ export fn main() void = { execute(&s, &cmd): void; //cmd = command { ... }; } else { - s.mode = mode::INPUT; + s.mode = Mode::INPUT; continue; }; - case mode::INPUT => + case Mode::INPUT => if (input == ".") { execute(&s, &cmd): void; delete(cmd.input[..]); - s.mode = mode::COMMAND; + s.mode = Mode::COMMAND; continue; }; debug("repl: input={}", input); @@ -141,22 +141,22 @@ export fn main() void = { os::exit(1); }; -fn errormsg(s: *session, err: error) error = { +fn errormsg(s: *Session, err: Error) Error = { fmt::errorln('?')!; const msg = match (err) { - case invalidaddress => + case InvalidAddress => yield "Invalid address"; - case nofilename => + case NoFilename => yield "No filename"; - case buffermodified => + case BufferModified => yield "Buffer modified"; - case unexpectedaddress => + case UnexpectedAddress => yield "Unexpected address"; - case invaliddestination => + case InvalidDestination => yield "Invalid destination"; - case nomatch => + case NoMatch => yield "No match"; - case noprevshcmd => + case NoPrevShCmd => yield "No previous shell command"; case let e: regex::error => yield regex::strerror(e); diff --git a/parse.ha b/parse.ha @@ -3,32 +3,32 @@ use regex; use strconv; use strings; -type parseerror = ( - unknowncommand - | unexpectedsuffix - | trailingcharacters - | expectedargument - | expectedmark - | invaliddelimiter - | expecteddelimiter +type ParseError = ( + UnknownCommand + | UnexpectedSuffix + | TrailingCharacters + | ExpectedArgument + | ExpectedMark + | InvalidDelimiter + | ExpectedDelimiter ); -type unknowncommand = !rune; +type UnknownCommand = !rune; -type unexpectedsuffix = !rune; +type UnexpectedSuffix = !rune; -type trailingcharacters = !void; +type TrailingCharacters = !void; -type expectedargument = !void; +type ExpectedArgument = !void; -type expectedmark = !void; +type ExpectedMark = !void; -type invaliddelimiter = !void; +type InvalidDelimiter = !void; -type expecteddelimiter = !void; +type ExpectedDelimiter = !void; // Parses inputted commands. Returns true when command is ready. -fn parse(cmd: *command, input: str) (bool | parseerror) = { +fn parse(cmd: *Command, input: str) (bool | ParseError) = { const iter = strings::iter(input); cmd.addrs = scan_addrs(&iter); @@ -49,7 +49,7 @@ fn parse(cmd: *command, input: str) (bool | parseerror) = { if (scan_blanks(&iter) == 0) { match (strings::next(&iter)) { case let r: rune => - return r: unexpectedsuffix; + return r: UnexpectedSuffix; case void => return true; }; @@ -64,7 +64,7 @@ fn parse(cmd: *command, input: str) (bool | parseerror) = { case let r: rune => cmd.arg = strings::fromrunes([r]); case void => - return expectedmark; + return ExpectedMark; }; scan_end_assert(&iter)?; return true; @@ -96,10 +96,10 @@ fn parse(cmd: *command, input: str) (bool | parseerror) = { case 'G', 'V' => const delim = match (strings::next(&iter)) { case void => - return expectedargument; + return ExpectedArgument; case let r: rune => yield if (r == ' ') { - return invaliddelimiter; + return InvalidDelimiter; } else { yield r; }; @@ -113,10 +113,10 @@ fn parse(cmd: *command, input: str) (bool | parseerror) = { case 's' => const delim = match (strings::next(&iter)) { case void => - return expectedargument; + return ExpectedArgument; case let r: rune => yield if (r == ' ') { - return invaliddelimiter; + return InvalidDelimiter; } else { yield r; }; @@ -125,7 +125,7 @@ fn parse(cmd: *command, input: str) (bool | parseerror) = { match (strings::next(&iter)) { case rune => void; case void => - return expecteddelimiter; + return ExpectedDelimiter; }; cmd.arg2 = scan_item(&iter, delim); match (strings::next(&iter)) { @@ -145,8 +145,8 @@ fn parse(cmd: *command, input: str) (bool | parseerror) = { }; }; -fn scan_addrs(iter: *strings::iterator) []address = { - let addrs: []address = []; +fn scan_addrs(iter: *strings::iterator) []Address = { + let addrs: []Address = []; let specialfirst = false; scan_blanks(iter); @@ -157,15 +157,15 @@ fn scan_addrs(iter: *strings::iterator) []address = { switch (r) { case ',' => specialfirst = true; - append(addrs, address { + append(addrs, Address { addrtype = 1z, lineoffset = 0, setcurrentline = false, }); case ';' => specialfirst = true; - append(addrs, address { - addrtype = currentline, + append(addrs, Address { + addrtype = CurrentLine, lineoffset = 0, setcurrentline = true, }); @@ -178,8 +178,8 @@ fn scan_addrs(iter: *strings::iterator) []address = { let addr = match (scan_addr(iter)) { case void => yield if (specialfirst) { - yield address { - addrtype = lastline, + yield Address { + addrtype = LastLine, lineoffset = 0, ... }; @@ -188,7 +188,7 @@ fn scan_addrs(iter: *strings::iterator) []address = { } else { break; }; - case let a: address => + case let a: Address => yield a; }; @@ -219,7 +219,7 @@ fn scan_addrs(iter: *strings::iterator) []address = { return addrs; }; -fn scan_addr(iter: *strings::iterator) (address | void) = { +fn scan_addr(iter: *strings::iterator) (Address | void) = { scan_blanks(iter); let r = match (strings::next(iter)) { case void => @@ -230,25 +230,25 @@ fn scan_addr(iter: *strings::iterator) (address | void) = { // debug("scan_addr(): r={}", r); - const addrtype: (addresstype | void) = + const addrtype: (AddressType | void) = if (r == '.') { - yield currentline; + yield CurrentLine; } else if (r == '$') { - yield lastline; + yield LastLine; } else if (ascii::isdigit(r)) { strings::prev(iter); yield scan_uint(iter): size; } else if (r == '\'') { yield scan_mark(iter); } else if (r == '/') { - const rad = regexaddr { + const rad = RegexAddr { expr = scan_item(iter, '/'), direction = true, }; strings::next(iter); yield rad; } else if (r == '?') { - const rad = regexaddr { + const rad = RegexAddr { expr = scan_item(iter, '?'), direction = false, }; @@ -261,18 +261,18 @@ fn scan_addr(iter: *strings::iterator) (address | void) = { const offs = scan_offsets(iter); - const addrtype: addresstype = match (addrtype) { + const addrtype: AddressType = match (addrtype) { case void => yield if (len(offs) == 0) { return void; } else { - yield currentline; + yield CurrentLine; }; case => - yield addrtype as addresstype; + yield addrtype as AddressType; }; - let addr = address { + let addr = Address { addrtype = addrtype, lineoffset = 0, ... @@ -326,7 +326,7 @@ fn scan_offset(iter: *strings::iterator) int = { }; }; -fn scan_cmdname(iter: *strings::iterator) (rune | unknowncommand) = { +fn scan_cmdname(iter: *strings::iterator) (rune | UnknownCommand) = { scan_blanks(iter); let r = match (strings::next(iter)) { case void => @@ -343,28 +343,28 @@ fn scan_cmdname(iter: *strings::iterator) (rune | unknowncommand) = { => return r; case => - return r: unknowncommand; + return r: UnknownCommand; }; }; -fn scan_suffix(iter: *strings::iterator) printmode = { +fn scan_suffix(iter: *strings::iterator) PrintMode = { let r = match (strings::next(iter)) { case void => - return printmode::NONE; + return PrintMode::NONE; case let r: rune => yield r; }; switch (r) { case 'l' => - return printmode::LIST; + return PrintMode::LIST; case 'n' => - return printmode::NUMBER; + return PrintMode::NUMBER; case 'p' => - return printmode::PRINT; + return PrintMode::PRINT; case => strings::prev(iter); - return printmode::NONE; + return PrintMode::NONE; }; }; @@ -474,11 +474,11 @@ fn scan_blanks(iter: *strings::iterator) size = { return sz; }; -fn scan_end_assert(iter: *strings::iterator) (void | trailingcharacters) = { +fn scan_end_assert(iter: *strings::iterator) (void | TrailingCharacters) = { scan_blanks(iter); match (strings::next(iter)) { case rune => - return trailingcharacters; + return TrailingCharacters; case void => return void; }; diff --git a/util.ha b/util.ha @@ -2,11 +2,11 @@ use fmt; use io; use strings; -fn cmd_dumpbuffer(s: *session, cmd: *command) (void | error) = { +fn cmd_dumpbuffer(s: *Session, cmd: *Command) (void | Error) = { return dumpbuffer(&s.buf); }; -fn dumpbuffer(buf: *buffer) void = { +fn dumpbuffer(buf: *Buffer) void = { for (let n = 1z; n < len(buf.lines); n += 1) { fmt::printfln("{}\t{}", n, buf.lines[n].text)!; }; @@ -18,9 +18,9 @@ fn debug(fmtstr: str, args: fmt::field...) void = { fmt::errorln("\x1b[m")!; }; -type printer = *fn(*buffer, size, size) (size | io::error); +type Printer = *fn(*Buffer, size, size) (size | io::error); -fn printlns(buf: *buffer, a: size, b: size) (size | io::error) = { +fn printlns(buf: *Buffer, a: size, b: size) (size | io::error) = { let sz = 0z; for (let n = a; n <= b; n += 1) { sz += fmt::println(buf.lines[n].text)?; @@ -28,7 +28,7 @@ fn printlns(buf: *buffer, a: size, b: size) (size | io::error) = { return sz; }; -fn printnumberlns(buf: *buffer, a: size, b: size) (size | io::error) = { +fn printnumberlns(buf: *Buffer, a: size, b: size) (size | io::error) = { let sz = 0z; for (let n = a; n <= b; n += 1) { sz += fmt::printfln("{}\t{}", n, buf.lines[n].text)?; @@ -36,7 +36,7 @@ fn printnumberlns(buf: *buffer, a: size, b: size) (size | io::error) = { return sz; }; -fn printlistlns(buf: *buffer, a: size, b: size) (size | io::error) = { +fn printlistlns(buf: *Buffer, a: size, b: size) (size | io::error) = { let sz = 0z; for (let n = a; n <= b; n += 1) { sz += printlistln(buf.lines[n].text)?;