commit 3617a5d89ac8393a1b0f0cbbfda30cd1e5a8e0a1
parent f7bd44d85dba55e61b3eb0947124848583c6ac89
Author: Sebastian <sebastian@sebsite.pw>
Date: Fri, 8 Sep 2023 00:37:05 -0400
bufio: rename old scan* functions to read_*
Functions beginning with scan_ take in a scanner; functions which begin
with read_ read directly from an io::handle.
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
18 files changed, 58 insertions(+), 58 deletions(-)
diff --git a/bufio/README b/bufio/README
@@ -13,5 +13,5 @@ streams also support an "[[unread]]" operation, which allows you to "look-ahead"
at future data without consuming it from the stream.
Additionally, bufio provides several utilities for "scanning" streams, namely
-[[scantok]] et al, which require small, frequent reads, or take advantage of
+[[read_tok]] et al, which require small, frequent reads, or take advantage of
look-ahead, and thus are most efficient when paired with a bufio [[stream]].
diff --git a/bufio/scanner.ha b/bufio/scanner.ha
@@ -245,7 +245,7 @@ export fn scan_buffer(scan: *scanner) []u8 = {
};
// Reads a single byte from an [[io::handle]].
-export fn scanbyte(file: io::handle) (u8 | io::EOF | io::error) = {
+export fn read_byte(file: io::handle) (u8 | io::EOF | io::error) = {
let buf: [1]u8 = [0...];
match (io::readall(file, buf)?) {
@@ -258,11 +258,11 @@ export fn scanbyte(file: io::handle) (u8 | io::EOF | io::error) = {
// Reads a slice of bytes until the delimiter. Delimiter is not included but
// it is read from the file. The return value must be freed by the caller.
-export fn scantok(file: io::handle, delim: u8...) ([]u8 | io::EOF | io::error) = {
+export fn read_tok(file: io::handle, delim: u8...) ([]u8 | io::EOF | io::error) = {
let buf: []u8 = [];
for (true) {
- match (scanbyte(file)?) {
+ match (read_byte(file)?) {
case let res: u8 =>
if (bytes::contains(delim, res)) {
break;
@@ -282,11 +282,11 @@ export fn scantok(file: io::handle, delim: u8...) ([]u8 | io::EOF | io::error) =
// Reads a slice of bytes until a newline character (\n, 0x0A). Newline itself
// is not included but it is read from the file. The return value must be
// freed by the caller.
-export fn scanline(file: io::handle) ([]u8 | io::EOF | io::error) =
- scantok(file, '\n');
+export fn read_line(file: io::handle) ([]u8 | io::EOF | io::error) =
+ read_tok(file, '\n');
// Reads a rune from a UTF-8 stream.
-export fn scanrune(
+export fn read_rune(
file: io::handle,
) (rune | utf8::invalid | io::EOF | io::error) = {
let b: [4]u8 = [0...];
diff --git a/bufio/scanner_test+test.ha b/bufio/scanner_test+test.ha
@@ -4,46 +4,46 @@ use io;
use memio;
use strings;
-@test fn scanbyte() void = {
+@test fn read_byte() void = {
let buf = memio::fixed([1, 3, 3, 7]);
- assert(scanbyte(&buf) as u8 == 1);
- assert(scanbyte(&buf) as u8 == 3);
- assert(scanbyte(&buf) as u8 == 3);
- assert(scanbyte(&buf) as u8 == 7);
- assert(scanbyte(&buf) is io::EOF);
+ assert(read_byte(&buf) as u8 == 1);
+ assert(read_byte(&buf) as u8 == 3);
+ assert(read_byte(&buf) as u8 == 3);
+ assert(read_byte(&buf) as u8 == 7);
+ assert(read_byte(&buf) is io::EOF);
};
-@test fn scantok() void = {
+@test fn read_tok() void = {
let buf = memio::fixed([1, 3, 4, 5, 3, 7]);
- let tok = scantok(&buf, 4) as []u8;
+ let tok = read_tok(&buf, 4) as []u8;
defer free(tok);
assert(bytes::equal(tok, [1, 3]));
- let tok = scantok(&buf, 7) as []u8;
+ let tok = read_tok(&buf, 7) as []u8;
defer free(tok);
assert(bytes::equal(tok, [5, 3]));
- assert(scantok(&buf, 1) is io::EOF);
+ assert(read_tok(&buf, 1) is io::EOF);
};
-@test fn scanline() void = {
+@test fn read_line() void = {
let helloworld = strings::toutf8("hello\nworld");
let buf = memio::fixed(helloworld);
- let line = scanline(&buf) as []u8;
+ let line = read_line(&buf) as []u8;
defer free(line);
assert(bytes::equal(line, strings::toutf8("hello")));
- let line = scanline(&buf) as []u8;
+ let line = read_line(&buf) as []u8;
defer free(line);
assert(bytes::equal(line, strings::toutf8("world")));
- assert(scanline(&buf) is io::EOF);
+ assert(read_line(&buf) is io::EOF);
};
-@test fn scanrune() void = {
+@test fn read_rune() void = {
let in = memio::fixed([
0xE3, 0x81, 0x93, 0xE3, 0x82, 0x93, 0xE3, 0x81,
0xAB, 0xE3, 0x81, 0xA1, 0xE3, 0x81, 0xAF, 0x00,
@@ -55,7 +55,7 @@ use strings;
for (let i = 0z; i < len(expected); i += 1) {
let want = expected[i];
- match (scanrune(&in)) {
+ match (read_rune(&in)) {
case let r: rune =>
assert(want is rune && want as rune == r);
case io::EOF =>
diff --git a/cmd/harec/errors.ha b/cmd/harec/errors.ha
@@ -26,13 +26,13 @@ fn printerr_syntax(err: lex::syntax) void = {
let line = 1u;
for (line < location.line) {
- let r = bufio::scanrune(file) as rune;
+ let r = bufio::read_rune(file) as rune;
if (r == '\n') {
line += 1u;
};
};
- let line = bufio::scanline(file) as []u8;
+ let line = bufio::read_line(file) as []u8;
defer free(line);
let line = strings::fromutf8_unsafe(line);
fmt::errorfln("{}:{}:{}: syntax error: {}",
diff --git a/cmd/haredoc/doc/hare.ha b/cmd/haredoc/doc/hare.ha
@@ -21,7 +21,7 @@ export fn emit_hare(ctx: *context) (void | error) = {
case let readme: io::file =>
first = false;
for (true) {
- match (bufio::scanline(readme)?) {
+ match (bufio::read_line(readme)?) {
case io::EOF =>
break;
case let b: []u8 =>
diff --git a/cmd/haredoc/doc/tty.ha b/cmd/haredoc/doc/tty.ha
@@ -23,7 +23,7 @@ export fn emit_tty(ctx: *context) (void | error) = {
match (ctx.readme) {
case let readme: io::file =>
- for (true) match (bufio::scanline(readme)?) {
+ for (true) match (bufio::read_line(readme)?) {
case io::EOF =>
break;
case let b: []u8 =>
diff --git a/cmd/ioctlgen/main.ha b/cmd/ioctlgen/main.ha
@@ -39,7 +39,7 @@ export fn main() void = {
defer types::store_free(store);
for (true) {
- const line = match (bufio::scanline(os::stdin)!) {
+ const line = match (bufio::read_line(os::stdin)!) {
case io::EOF =>
break;
case let line: []u8 =>
diff --git a/encoding/pem/pem.ha b/encoding/pem/pem.ha
@@ -85,7 +85,7 @@ export fn next(dec: *decoder) ((str, pemdecoder) | io::EOF | io::error) = {
for (true) {
// XXX: This can be improved following
// https://todo.sr.ht/~sircmpwn/hare/562
- const line = match (bufio::scanline(&dec.in)?) {
+ const line = match (bufio::read_line(&dec.in)?) {
case io::EOF =>
return io::EOF;
case let line: []u8 =>
@@ -144,7 +144,7 @@ fn pem_read(st: *io::stream, buf: []u8) (size | io::EOF | io::error) = {
yield;
};
- const line = match (bufio::scanline(st.in)?) {
+ const line = match (bufio::read_line(st.in)?) {
case io::EOF =>
return io::EOF;
case let line: []u8 =>
diff --git a/format/ini/scan.ha b/format/ini/scan.ha
@@ -52,7 +52,7 @@ export fn entry_finish(ent: entry) void = {
// lifetime of the entry or its fields respectively.
export fn next(sc: *scanner) (entry | io::EOF | error) = {
for (true) {
- const line = match (bufio::scanline(sc.in)?) {
+ const line = match (bufio::read_line(sc.in)?) {
case let b: []u8 =>
yield strings::fromutf8(b)?;
case io::EOF =>
diff --git a/hare/parse/doc/doc.ha b/hare/parse/doc/doc.ha
@@ -41,7 +41,7 @@ export fn parse(in: io::handle) parser = {
};
export fn scan(par: *parser) (token | void) = {
- const rn = match (bufio::scanrune(&par.src)!) {
+ const rn = match (bufio::read_rune(&par.src)!) {
case let rn: rune =>
yield rn;
case io::EOF =>
@@ -86,7 +86,7 @@ fn scantext(par: *parser) (token | void) = {
// TODO: Collapse whitespace
const buf = memio::dynamic();
for (true) {
- const rn = match (bufio::scanrune(&par.src)!) {
+ const rn = match (bufio::read_rune(&par.src)!) {
case io::EOF =>
break;
case let rn: rune =>
@@ -98,7 +98,7 @@ fn scantext(par: *parser) (token | void) = {
break;
case '\n' =>
memio::appendrune(&buf, rn)!;
- const rn = match (bufio::scanrune(&par.src)!) {
+ const rn = match (bufio::read_rune(&par.src)!) {
case io::EOF =>
break;
case let rn: rune =>
@@ -124,7 +124,7 @@ fn scantext(par: *parser) (token | void) = {
};
fn scanref(par: *parser) (token | void) = {
- match (bufio::scanrune(&par.src)!) {
+ match (bufio::read_rune(&par.src)!) {
case io::EOF =>
return;
case let rn: rune =>
@@ -132,7 +132,7 @@ fn scanref(par: *parser) (token | void) = {
abort();
};
};
- match (bufio::scanrune(&par.src)!) {
+ match (bufio::read_rune(&par.src)!) {
case io::EOF =>
return;
case let rn: rune =>
@@ -146,11 +146,11 @@ fn scanref(par: *parser) (token | void) = {
defer io::close(&buf)!;
// TODO: Handle invalid syntax here
for (true) {
- match (bufio::scanrune(&par.src)!) {
+ match (bufio::read_rune(&par.src)!) {
case let rn: rune =>
switch (rn) {
case ']' =>
- bufio::scanrune(&par.src) as rune; // ]
+ bufio::read_rune(&par.src) as rune; // ]
break;
case =>
memio::appendrune(&buf, rn)!;
@@ -166,7 +166,7 @@ fn scanref(par: *parser) (token | void) = {
fn scansample(par: *parser) (token | void) = {
let nws = 0z;
for (true) {
- match (bufio::scanrune(&par.src)!) {
+ match (bufio::read_rune(&par.src)!) {
case io::EOF =>
return;
case let rn: rune =>
@@ -188,7 +188,7 @@ fn scansample(par: *parser) (token | void) = {
let cont = true;
let buf = memio::dynamic();
for (cont) {
- const rn = match (bufio::scanrune(&par.src)!) {
+ const rn = match (bufio::read_rune(&par.src)!) {
case io::EOF =>
break;
case let rn: rune =>
@@ -204,7 +204,7 @@ fn scansample(par: *parser) (token | void) = {
// Consume whitespace
for (let i = 0z; i < nws) {
- match (bufio::scanrune(&par.src)!) {
+ match (bufio::read_rune(&par.src)!) {
case io::EOF =>
break;
case let rn: rune =>
@@ -232,7 +232,7 @@ fn scansample(par: *parser) (token | void) = {
};
fn scanlist(par: *parser) (token | void) = {
- match (bufio::scanrune(&par.src)!) {
+ match (bufio::read_rune(&par.src)!) {
case io::EOF =>
return void;
case let rn: rune =>
@@ -240,7 +240,7 @@ fn scanlist(par: *parser) (token | void) = {
abort();
};
};
- const rn = match (bufio::scanrune(&par.src)!) {
+ const rn = match (bufio::read_rune(&par.src)!) {
case io::EOF =>
return void;
case let rn: rune =>
diff --git a/mime/system.ha b/mime/system.ha
@@ -23,7 +23,7 @@ fn load_systemdb() (void | fs::error | io::error) = {
const strm = bufio::init(file, buf, []);
for (true) {
- const line = match (bufio::scanline(&strm)) {
+ const line = match (bufio::read_line(&strm)) {
case let bytes: []u8 =>
yield match (strings::fromutf8(bytes)) {
case utf8::invalid =>
diff --git a/regex/regex.ha b/regex/regex.ha
@@ -703,7 +703,7 @@ fn search(
return res;
};
- const r_or_end = bufio::scanrune(handle)!;
+ const r_or_end = bufio::read_rune(handle)!;
if (r_or_end is rune) {
last_bytesize = utf8::runesz(r_or_end as rune);
};
diff --git a/time/chrono/leapsec.ha b/time/chrono/leapsec.ha
@@ -63,7 +63,7 @@ fn parse_utc_leapsecs(
leapsecs: *[](i64, i64),
) (void | encoding::utf8::invalid | io::error) = {
for (true) {
- const line = match (bufio::scanline(h)) {
+ const line = match (bufio::read_line(h)) {
case let err: io::error =>
return err;
case io::EOF =>
diff --git a/unix/hosts/hosts.ha b/unix/hosts/hosts.ha
@@ -54,7 +54,7 @@ export fn iter(in: io::handle) iterator = iterator {
// Returns the next host line as a [[host]] type.
export fn next(it: *iterator) (host | void | error) = for (true) {
- const line = match (bufio::scanline(it.handle)) {
+ const line = match (bufio::read_line(it.handle)) {
case io::EOF =>
return void;
case let line: []u8 =>
@@ -66,7 +66,7 @@ export fn next(it: *iterator) (host | void | error) = for (true) {
};
const scanner = memio::fixed(line);
- const tok = match (bufio::scantok(&scanner, ' ', '\t')?) {
+ const tok = match (bufio::read_tok(&scanner, ' ', '\t')?) {
case io::EOF =>
return void;
case let tok: []u8 =>
@@ -77,7 +77,7 @@ export fn next(it: *iterator) (host | void | error) = for (true) {
let names: []str = [];
for (true) {
- const tok = match (bufio::scantok(&scanner, ' ', '\t')?) {
+ const tok = match (bufio::read_tok(&scanner, ' ', '\t')?) {
case io::EOF =>
break;
case let tok: []u8 =>
diff --git a/unix/passwd/group.ha b/unix/passwd/group.ha
@@ -24,7 +24,7 @@ export type grent = struct {
// Reads a Unix-like group entry from an [[io::handle]]. The caller must free
// the return value using [[grent_finish]].
export fn nextgr(in: io::handle) (grent | io::EOF | io::error | invalid) = {
- let line = match (bufio::scanline(in)?) {
+ let line = match (bufio::read_line(in)?) {
case let ln: []u8 =>
yield ln;
case io::EOF =>
@@ -52,7 +52,7 @@ export fn nextgr(in: io::handle) (grent | io::EOF | io::error | invalid) = {
};
return grent {
- // Borrows the return value of bufio::scanline
+ // Borrows the return value of bufio::read_line
name = fields[0],
password = fields[1],
gid = gid,
diff --git a/unix/passwd/passwd.ha b/unix/passwd/passwd.ha
@@ -30,7 +30,7 @@ export type pwent = struct {
// Reads a Unix-like password entry from an [[io::handle]]. The caller must free
// the return value using [[pwent_finish]].
export fn nextpw(in: io::handle) (pwent | io::EOF | io::error | invalid) = {
- let line = match (bufio::scanline(in)?) {
+ let line = match (bufio::read_line(in)?) {
case io::EOF =>
return io::EOF;
case let ln: []u8 =>
@@ -65,7 +65,7 @@ export fn nextpw(in: io::handle) (pwent | io::EOF | io::error | invalid) = {
};
return pwent {
- // Borrows the return value of bufio::scanline
+ // Borrows the return value of bufio::read_line
username = fields[0],
password = fields[1],
uid = uid,
@@ -79,7 +79,7 @@ export fn nextpw(in: io::handle) (pwent | io::EOF | io::error | invalid) = {
// Frees resources associated with a [[pwent]].
export fn pwent_finish(ent: *pwent) void = {
// pwent fields are sliced from one allocated string returned by
- // bufio::scanline. Freeing the first field frees the entire string in
+ // bufio::read_line. Freeing the first field frees the entire string in
// one go.
free(ent.username);
};
diff --git a/unix/resolvconf/load.ha b/unix/resolvconf/load.ha
@@ -28,7 +28,7 @@ export fn load() []ip::addr = {
defer io::close(file)!;
for (true) {
- const line = match (bufio::scanline(file)) {
+ const line = match (bufio::read_line(file)) {
case io::EOF =>
break;
case let line: []u8 =>
@@ -40,7 +40,7 @@ export fn load() []ip::addr = {
};
const scanner = memio::fixed(line);
- const tok = match (bufio::scantok(&scanner, ' ', '\t')!) {
+ const tok = match (bufio::read_tok(&scanner, ' ', '\t')!) {
case io::EOF =>
break;
case let tok: []u8 =>
@@ -51,7 +51,7 @@ export fn load() []ip::addr = {
continue;
};
- const tok = match (bufio::scantok(&scanner, ' ')!) {
+ const tok = match (bufio::read_tok(&scanner, ' ')!) {
case io::EOF =>
break;
case let tok: []u8 =>
diff --git a/unix/tty/pty_common.ha b/unix/tty/pty_common.ha
@@ -36,7 +36,7 @@ export fn openpty() ((io::file, io::file) | fs::error) = {
};
fmt::fprintln(pty.0, "hello, world")!;
- let s = strings::fromutf8(bufio::scanline(pty.1) as []u8)!;
+ let s = strings::fromutf8(bufio::read_line(pty.1) as []u8)!;
defer free(s);
assert(s == "hello, world");
};