hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 52b8408b8b1fc745b935cf57d3ff8b42d642e6b0
parent 9654a72704224d80cd08db9410337ff0aebc83cd
Author: Autumn! <autumnull@posteo.net>
Date:   Mon,  8 May 2023 17:27:15 +0000

hare::lex: add finish()

Signed-off-by: Autumn! <autumnull@posteo.net>

Diffstat:
Mcmd/harec/main.ha | 1+
Mcmd/haredoc/main.ha | 1+
Mcmd/haretype/main.ha | 1+
Mcmd/ioctlgen/main.ha | 1+
Mhare/lex/lex.ha | 4++++
Mhare/module/scan.ha | 1+
Mhare/parse/+test/ident.ha | 4++++
Mhare/parse/+test/loc.ha | 3+++
Mhare/parse/+test/roundtrip.ha | 1+
Mhare/parse/+test/unit.ha | 1+
Mhare/parse/ident.ha | 1+
Mhare/types/+test.ha | 1+
Mhare/unit/+test.ha | 1+
13 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/cmd/harec/main.ha b/cmd/harec/main.ha @@ -74,6 +74,7 @@ export fn main() void = { defer io::close(&bufin)!; let lexer = lex::init(&bufin, cmd.args[i]); + defer lex::finish(&lexer); let su = match (parse::subunit(&lexer)) { case let err: parse::error => printerr(err); diff --git a/cmd/haredoc/main.ha b/cmd/haredoc/main.ha @@ -239,6 +239,7 @@ export fn main() void = { fn parseident(in: str) (ast::ident | parse::error) = { const buf = bufio::fixed(strings::toutf8(in), io::mode::READ); const lexer = lex::init(&buf, "<string>"); + defer lex::finish(&lexer); let ident: []str = []; // TODO: errdefer let z = 0z; for (true) { diff --git a/cmd/haretype/main.ha b/cmd/haretype/main.ha @@ -24,6 +24,7 @@ fn typeinfo( const stream = bufio::fixed(strings::toutf8(s), io::mode::READ); defer io::close(&stream)!; const lexer = lex::init(&stream, "-"); + defer lex::finish(&lexer); const atype = parse::_type(&lexer)?; defer ast::type_finish(atype); const typ = types::lookup(store, &atype)?; diff --git a/cmd/ioctlgen/main.ha b/cmd/ioctlgen/main.ha @@ -85,6 +85,7 @@ export fn main() void = { fn loadtype(store: *types::typestore) void = { const tee = io::tee(os::stdin, os::stdout); const lex = lex::init(&tee, "<ioctl>"); + defer lex::finish(&lex); const decl = match (parse::decl(&lex)) { case let err: parse::error => fmt::fatal("Error parsing type declaration:", diff --git a/hare/lex/lex.ha b/hare/lex/lex.ha @@ -78,6 +78,10 @@ export fn init(in: io::handle, path: str, flags: flags...) lexer = { }; }; +export fn finish(lex: *lexer) void = { + bufio::finish(&lex.in); +}; + // Returns the current value of the comment buffer, or empty string if unset (or // if [[flags::COMMENTS]] was not enabled for this lexer). export fn comment(lex: *lexer) str = lex.comment; diff --git a/hare/module/scan.ha b/hare/module/scan.ha @@ -366,6 +366,7 @@ fn scan_file( if (ftype == filetype::HARE) { let tee = io::tee(f, &sha); let lexer = lex::init(&tee, path); + defer lex::finish(&lexer); let imports = match (parse::imports(&lexer)) { case let im: []ast::import => yield im; diff --git a/hare/parse/+test/ident.ha b/hare/parse/+test/ident.ha @@ -13,6 +13,7 @@ use strings; const in = "foo"; let buf = bufio::fixed(strings::toutf8(in), mode::READ); let lexer = lex::init(&buf, "<test>"); + defer lex::finish(&lexer); let ident = ident(&lexer) as ast::ident; defer ast::ident_free(ident); assert(len(ident) == 1); @@ -25,6 +26,7 @@ use strings; const in = "foo::bar"; let buf = bufio::fixed(strings::toutf8(in), mode::READ); let lexer = lex::init(&buf, "<test>"); + defer lex::finish(&lexer); let ident = ident(&lexer) as ast::ident; defer ast::ident_free(ident); assert(len(ident) == 2); @@ -37,6 +39,7 @@ use strings; const in = "foo::bar::baz"; let buf = bufio::fixed(strings::toutf8(in), mode::READ); let lexer = lex::init(&buf, "<test>"); + defer lex::finish(&lexer); let ident = ident(&lexer) as ast::ident; defer ast::ident_free(ident); assert(len(ident) == 3); @@ -50,6 +53,7 @@ use strings; const in = "foo::bar;"; let buf = bufio::fixed(strings::toutf8(in), mode::READ); let lexer = lex::init(&buf, "<test>"); + defer lex::finish(&lexer); let ident = ident(&lexer) as ast::ident; defer ast::ident_free(ident); assert(len(ident) == 2); diff --git a/hare/parse/+test/loc.ha b/hare/parse/+test/loc.ha @@ -14,6 +14,7 @@ use strings; fn expr_testloc(srcs: str...) void = for (let i = 0z; i < len(srcs); i += 1) { let buf = bufio::fixed(strings::toutf8(srcs[i]), mode::READ); let lexer = lex::init(&buf, "<test>"); + defer lex::finish(&lexer); let exp = match (expr(&lexer)) { case let exp: ast::expr => yield exp; @@ -78,6 +79,7 @@ fn expr_testloc(srcs: str...) void = for (let i = 0z; i < len(srcs); i += 1) { // use expr_testloc let buf = bufio::fixed(strings::toutf8("foo: bar: baz"), mode::READ); let lexer = lex::init(&buf, "<test>"); + defer lex::finish(&lexer); let exp = match (expr(&lexer)) { case let exp: ast::expr => yield exp; @@ -101,6 +103,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 = bufio::fixed(strings::toutf8(srcs[i]), mode::READ); let lexer = lex::init(&buf, "<test>"); + defer lex::finish(&lexer); let typ = match (_type(&lexer)) { case let typ: ast::_type => yield typ; diff --git a/hare/parse/+test/roundtrip.ha b/hare/parse/+test/roundtrip.ha @@ -16,6 +16,7 @@ use strio; fn roundtrip(src: str) void = { let buf = bufio::fixed(strings::toutf8(src), mode::READ); let lexer = lex::init(&buf, "<test>", lex::flags::COMMENTS); + defer lex::finish(&lexer); let u = ast::subunit { imports = [], decls: []ast::decl = match (decls(&lexer)) { diff --git a/hare/parse/+test/unit.ha b/hare/parse/+test/unit.ha @@ -77,6 +77,7 @@ fn tup_to_import(tup: import_tuple) ast::import = ast::import { "export fn main() void = void;"; let buf = bufio::fixed(strings::toutf8(in), mode::READ); let lexer = lex::init(&buf, "<test>"); + defer lex::finish(&lexer); let mods = imports(&lexer)!; defer for (let i = 0z; i < len(mods); i += 1) { ast::import_finish(mods[i]); diff --git a/hare/parse/ident.ha b/hare/parse/ident.ha @@ -47,5 +47,6 @@ export fn ident(lexer: *lex::lexer) (ast::ident | error) = { export fn identstr(in: str) (ast::ident | error) = { const buf = bufio::fixed(strings::toutf8(in), io::mode::READ); const lexer = lex::init(&buf, "<string>"); + defer lex::finish(&lexer); return ident(&lexer); }; diff --git a/hare/types/+test.ha b/hare/types/+test.ha @@ -16,6 +16,7 @@ use fmt; fn parse_type(in: str) ast::_type = { let buf = bufio::fixed(strings::toutf8(in), io::mode::READ); let lex = lex::init(&buf, "<test>"); + defer lex::finish(&lex); return parse::_type(&lex)!; }; diff --git a/hare/unit/+test.ha b/hare/unit/+test.ha @@ -12,6 +12,7 @@ use strings; fn parse_expr(src: str) *ast::expr = { const stream = bufio::fixed(strings::toutf8(src), io::mode::READ); const lexer = lex::init(&stream, "<test>"); + defer lex::finish(&lexer); return alloc(parse::expr(&lexer)!); };