commit 292dd96f4d6187222402949fc6dad2935dc71b61
parent 7f3283f2e743611463be7f1fe7b1bf0d92a78f24
Author: Joe Finney <me@spxtr.net>
Date: Sun, 10 Mar 2024 14:23:14 +0000
Make bufio::newscanner's maxread parameter optional.
Signed-off-by: Joe Finney <me@spxtr.net>
Diffstat:
19 files changed, 28 insertions(+), 39 deletions(-)
diff --git a/bufio/scanner.ha b/bufio/scanner.ha
@@ -29,12 +29,16 @@ export type scanner = struct {
// Creates a new [[scanner]] which will allocate and maintain a read buffer for
// efficient reading of files. The scanner will read ahead only up to maxread
-// bytes, which can be [[types::SIZE_MAX]] if no limit is required. The user
-// must free resources associated with the scanner using [[finish]] after use.
+// bytes, which defaults to [[types::SIZE_MAX]] if no limit is required. The
+// user must free resources associated with the scanner using [[finish]] after
+// use.
//
// Reads from the scanner will return [[errors::overflow]] if maxread is
// reached.
-export fn newscanner(src: io::handle, maxread: size) scanner = {
+export fn newscanner(
+ src: io::handle,
+ maxread: size = types::SIZE_MAX,
+) scanner = {
return scanner {
stream = &scanner_vtable,
src = src,
diff --git a/cmd/genoiddb/main.ha b/cmd/genoiddb/main.ha
@@ -8,7 +8,6 @@ use io;
use os;
use strconv;
use strings;
-use types;
type entry = struct {
name: str,
@@ -49,7 +48,7 @@ export fn main() void = {
};
fn parse_oids() []entry = {
- let s = bufio::newscanner(os::stdin, types::SIZE_MAX);
+ let s = bufio::newscanner(os::stdin);
defer bufio::finish(&s);
let oids: []entry = [];
diff --git a/cmd/harec/main.ha b/cmd/harec/main.ha
@@ -12,7 +12,6 @@ use hare::types;
use hare::unit;
use io;
use os;
-use types::{SIZE_MAX};
export fn main() void = {
let usage: []getopt::help = [
@@ -72,7 +71,7 @@ export fn main() void = {
static let buf: [os::BUFSZ]u8 = [0...];
let bufin = bufio::init(input, buf, []);
defer io::close(&bufin)!;
- let sc = bufio::newscanner(&bufin, SIZE_MAX);
+ let sc = bufio::newscanner(&bufin);
defer bufio::finish(&sc);
let lexer = lex::init(&sc, cmd.args[i]);
diff --git a/cmd/haredoc/doc/tty.ha b/cmd/haredoc/doc/tty.ha
@@ -9,7 +9,6 @@ use io;
use memio;
use os;
use strings;
-use types;
let no_color: bool = false;
@@ -43,7 +42,7 @@ export fn emit_tty(ctx: *context) (void | error) = {
case let readme: io::file =>
let rbuf: [os::BUFSZ]u8 = [0...];
let readme = bufio::init(readme, rbuf, []);
- let sc = bufio::newscanner(&readme, types::SIZE_MAX);
+ let sc = bufio::newscanner(&readme);
defer bufio::finish(&sc);
for (let line => bufio::scan_line(&sc)?) {
firstline = false;
diff --git a/cmd/haredoc/main.ha b/cmd/haredoc/main.ha
@@ -18,7 +18,6 @@ use os::exec;
use path;
use strconv;
use strings;
-use types;
const help: []getopt::help = [
"reads and formats Hare documentation",
@@ -263,7 +262,7 @@ fn doc(name: str, cmd: *getopt::command) (void | error) = {
// as a valid identifier.
fn parseident(in: str) ((ast::ident, bool) | void) = {
let buf = memio::fixed(strings::toutf8(in));
- let sc = bufio::newscanner(&buf, types::SIZE_MAX);
+ let sc = bufio::newscanner(&buf);
defer bufio::finish(&sc);
let lexer = lex::init(&sc, "<string>");
let success = false;
diff --git a/cmd/haretype/main.ha b/cmd/haretype/main.ha
@@ -14,7 +14,6 @@ use memio;
use os;
use path;
use strings;
-use types::{SIZE_MAX};
fn typeinfo(
store: *types::typestore,
@@ -26,7 +25,7 @@ fn typeinfo(
} else {
let stream = memio::fixed(strings::toutf8(s));
defer io::close(&stream)!;
- let sc = bufio::newscanner(&stream, SIZE_MAX);
+ let sc = bufio::newscanner(&stream);
defer bufio::finish(&sc);
let lexer = lex::init(&sc, "-");
const atype = parse::_type(&lexer)?;
diff --git a/cmd/ioctlgen/main.ha b/cmd/ioctlgen/main.ha
@@ -13,7 +13,6 @@ use memio;
use os;
use regex;
use strings;
-use types::{SIZE_MAX};
let ioctlre: regex::regex = regex::regex { ... };
let typedefre: regex::regex = regex::regex { ... };
@@ -87,7 +86,7 @@ export fn main() void = {
fn loadtype(store: *types::typestore) void = {
let tee = io::tee(os::stdin, os::stdout);
- let sc = bufio::newscanner(&tee, SIZE_MAX);
+ let sc = bufio::newscanner(&tee);
defer bufio::finish(&sc);
let lex = lex::init(&sc, "<ioctl>");
const decl = match (parse::decl(&lex)) {
@@ -109,7 +108,7 @@ fn loadtype(store: *types::typestore) void = {
fn parseioctl(store: *types::typestore, d: dir, params: str) ioctl = {
let buf = memio::fixed(strings::toutf8(params));
- let sc = bufio::newscanner(&buf, SIZE_MAX);
+ let sc = bufio::newscanner(&buf);
defer bufio::finish(&sc);
let lex = lex::init(&sc, "<ioctl>");
diff --git a/cmd/parsechk/main.ha b/cmd/parsechk/main.ha
@@ -10,7 +10,6 @@ use hare::parse;
use io;
use os;
use path;
-use types;
export fn main() void = {
let buf = path::init()!;
@@ -43,7 +42,7 @@ fn iter(buf: *path::buffer, status: *int) void = {
fn parse(path: str, status: *int) void = {
const f = os::open(path)!;
defer io::close(f)!;
- let sc = bufio::newscanner(f, types::SIZE_MAX);
+ let sc = bufio::newscanner(f);
defer bufio::finish(&sc);
let lexer = lex::init(&sc, path);
match (parse::subunit(&lexer)) {
diff --git a/hare/module/deps.ha b/hare/module/deps.ha
@@ -14,7 +14,6 @@ use os;
use path;
use sort;
use strings;
-use types;
// A hare module.
export type module = struct {
@@ -39,7 +38,7 @@ export fn parse_deps(files: str...) ([]ast::ident | error) = {
};
defer io::close(handle)!;
- let sc = bufio::newscanner(handle, types::SIZE_MAX);
+ let sc = bufio::newscanner(handle);
defer bufio::finish(&sc);
let lexer = lex::init(&sc, file);
let imports = parse::imports(&lexer)?;
diff --git a/hare/parse/+test/ident_test.ha b/hare/parse/+test/ident_test.ha
@@ -9,11 +9,10 @@ use io;
use io::{mode};
use memio;
use strings;
-use types;
fn ident_test(in: str, expected: ast::ident, extra: ltok...) void = {
let buf = memio::fixed(strings::toutf8(in));
- let sc = bufio::newscanner(&buf, types::SIZE_MAX);
+ let sc = bufio::newscanner(&buf);
defer bufio::finish(&sc);
let lexer = lex::init(&sc, "<test>");
diff --git a/hare/parse/+test/loc.ha b/hare/parse/+test/loc.ha
@@ -9,11 +9,10 @@ use io;
use io::{mode};
use memio;
use strings;
-use types;
fn expr_testloc(srcs: str...) void = for (let i = 0z; i < len(srcs); i += 1) {
let buf = memio::fixed(strings::toutf8(srcs[i]));
- let sc = bufio::newscanner(&buf, types::SIZE_MAX);
+ let sc = bufio::newscanner(&buf);
defer bufio::finish(&sc);
let lexer = lex::init(&sc, "<test>");
let exp = match (expr(&lexer)) {
@@ -76,7 +75,7 @@ fn expr_testloc(srcs: str...) void = for (let i = 0z; i < len(srcs); i += 1) {
// We want to check the location of nested expressions, so this can't
// use expr_testloc
let buf = memio::fixed(strings::toutf8("foo: bar: baz"));
- let sc = bufio::newscanner(&buf, types::SIZE_MAX);
+ let sc = bufio::newscanner(&buf);
defer bufio::finish(&sc);
let lexer = lex::init(&sc, "<test>");
let exp = match (expr(&lexer)) {
@@ -101,7 +100,7 @@ fn expr_testloc(srcs: str...) void = for (let i = 0z; i < len(srcs); i += 1) {
fn type_testloc(srcs: str...) void = for (let i = 0z; i < len(srcs); i += 1) {
let buf = memio::fixed(strings::toutf8(srcs[i]));
- let sc = bufio::newscanner(&buf, types::SIZE_MAX);
+ let sc = bufio::newscanner(&buf);
defer bufio::finish(&sc);
let lexer = lex::init(&sc, "<test>");
let typ = match (_type(&lexer)) {
diff --git a/hare/parse/+test/roundtrip.ha b/hare/parse/+test/roundtrip.ha
@@ -30,7 +30,7 @@ fn roundtrip_reparse(src: str) void = {
fn _roundtrip(src: str) str = {
let buf = memio::fixed(strings::toutf8(src));
- let sc = bufio::newscanner(&buf, types::SIZE_MAX);
+ let sc = bufio::newscanner(&buf);
defer bufio::finish(&sc);
let lexer = lex::init(&sc, "<test>", lex::flag::COMMENTS);
let u = ast::subunit {
diff --git a/hare/parse/+test/unit_test.ha b/hare/parse/+test/unit_test.ha
@@ -74,7 +74,7 @@ fn tup_to_import(tup: import_tuple) ast::import = ast::import {
"export fn main() void = void;";
let buf = memio::fixed(strings::toutf8(in));
- let sc = bufio::newscanner(&buf, types::SIZE_MAX);
+ let sc = bufio::newscanner(&buf);
defer bufio::finish(&sc);
let lexer = lex::init(&sc, "<test>");
let mods = imports(&lexer)!;
diff --git a/hare/parse/doc/doc.ha b/hare/parse/doc/doc.ha
@@ -9,7 +9,6 @@ use hare::parse;
use io;
use memio;
use strings;
-use types;
// A representation of a complete haredoc document.
export type doc = [](paragraph | list | code_sample);
@@ -40,7 +39,7 @@ export fn strerror(err: error) const str = lex::strerror(err);
// the top-left corner of the document, for accurate locations in error messages
// (e.g. declaration documentation starts at col=3; READMEs start at col=1).
export fn parse(in: io::handle, start: lex::location) (doc | error) = {
- let sc = bufio::newscanner(in, types::SIZE_MAX);
+ let sc = bufio::newscanner(in);
defer bufio::finish(&sc);
match (_parse(&sc)) {
diff --git a/hare/parse/ident.ha b/hare/parse/ident.ha
@@ -7,7 +7,6 @@ use hare::lex;
use hare::lex::{ltok};
use memio;
use strings;
-use types;
// Parses a single identifier, possibly with a trailing ::, i.e. 'foo::bar::'.
// Returns the identifier and whether there's a trailing ::.
@@ -52,7 +51,7 @@ export fn ident(lexer: *lex::lexer) (ast::ident | error) = {
// caller needn't provide a lexer instance.
export fn identstr(in: str) (ast::ident | error) = {
let in = memio::fixed(strings::toutf8(in));
- let sc = bufio::newscanner(&in, types::SIZE_MAX);
+ let sc = bufio::newscanner(&in);
defer bufio::finish(&sc);
let lexer = lex::init(&sc, "<string>");
let ret = ident(&lexer);
diff --git a/hare/types/+test.ha b/hare/types/+test.ha
@@ -13,7 +13,7 @@ use types;
fn parse_type(in: str) ast::_type = {
let buf = memio::fixed(strings::toutf8(in));
- let sc = bufio::newscanner(&buf, types::SIZE_MAX);
+ let sc = bufio::newscanner(&buf);
defer bufio::finish(&sc);
let lex = lex::init(&sc, "<test>");
return parse::_type(&lex)!;
diff --git a/hare/unit/+test.ha b/hare/unit/+test.ha
@@ -9,11 +9,10 @@ use hare::types;
use io;
use memio;
use strings;
-use types::{SIZE_MAX};
fn parse_expr(src: str) *ast::expr = {
let stream = memio::fixed(strings::toutf8(src));
- let sc = bufio::newscanner(&stream, SIZE_MAX);
+ let sc = bufio::newscanner(&stream);
defer bufio::finish(&sc);
let lexer = lex::init(&sc, "<test>");
return alloc(parse::expr(&lexer)!);
diff --git a/mime/system.ha b/mime/system.ha
@@ -8,7 +8,6 @@ use fs;
use io;
use os;
use strings;
-use types;
// Path to the system MIME database.
export def SYSTEM_DB: str = "/etc/mime.types";
@@ -22,7 +21,7 @@ fn load_systemdb() (void | fs::error | io::error | utf8::invalid) = {
const file = os::open(SYSTEM_DB)?;
defer io::close(file)!;
- let sc = bufio::newscanner(file, types::SIZE_MAX);
+ let sc = bufio::newscanner(file);
defer bufio::finish(&sc);
for (let line => bufio::scan_line(&sc)?) {
diff --git a/wordexp/wordexp.ha b/wordexp/wordexp.ha
@@ -8,7 +8,6 @@ use io;
use os;
use os::exec;
use strings;
-use types;
// Flags applicable to a [[wordexp]] operation.
export type flag = enum uint {
@@ -42,7 +41,7 @@ export fn wordexp(s: str, flags: flag) ([]str | error) = {
const child = exec::start(&cmd)!;
io::close(wr)!;
- const scan = bufio::newscanner(rd, types::SIZE_MAX);
+ const scan = bufio::newscanner(rd);
defer bufio::finish(&scan);
match (bufio::scan_string(&scan, "\0")?) {