hare

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

commit 0f219a2173222ad8dc113e68df557daf82aebeaa
parent 607eb193e4f36252debbf1507d81efe0b51636b8
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed, 24 Feb 2021 09:26:48 -0500

main.ha: accept a file name as input

Diffstat:
Mmain.ha | 16+++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/main.ha b/main.ha @@ -4,7 +4,21 @@ use io; use os; export fn main() void = { - let lexer = lex::lexer_init(os::stdin, "<stdin>"); + let in: (*io::stream, str) = switch (len(os::args)) { + 1 => (os::stdin, "<stdin>"), + 2 => { + let fd = match (os::open(os::args[1])) { + err: io::error => fmt::fatal("Error opening '{}': {}", + os::args[1], io::errstr(err)), + fd: *io::stream => fd, + }; + (fd, os::args[1]); + }, + * => fmt::fatal("Usage: {} [<input>]", os::args[0]), + }; + defer io::close(in.0); + let lexer = lex::lexer_init(in.0, in.1); + for (true) match (lex::lex(&lexer)) { t: (lex::token, lex::location) => { let tok = t.0, loc = t.1;