commit bcf72531db6515e0b430d4697901c0c9103ff052
parent 167d72d81f1f6c419342972d2d5b48def11246a4
Author: Drew DeVault <sir@cmpwn.com>
Date: Wed, 24 Feb 2021 13:31:32 -0500
main.ha: scan imports
Diffstat:
M | main.ha | | | 30 | +++++++++++++++++++----------- |
1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/main.ha b/main.ha
@@ -1,5 +1,7 @@
use fmt;
+use hare::ast;
use hare::lex;
+use hare::parse;
use io;
use os;
@@ -17,18 +19,24 @@ export fn main() void = {
* => fmt::fatal("Usage: {} [<input>]", os::args[0]),
};
defer io::close(in.0);
+
let lexer = lex::lexer_init(in.0, in.1);
+ let imports = match (parse::imports(&lexer)) {
+ err: parse::error => fmt::fatal("{}", parse::errstr(err)),
+ i: []ast::import => i,
+ };
- for (true) match (lex::lex(&lexer)) {
- t: (lex::token, lex::location) => {
- let tok = t.0, loc = t.1;
- fmt::println("{}@{},{}: {4}{}{4}",
- loc.path, loc.line, loc.col,
- lex::tokstr(tok),
- if (tok is lex::name) "'" else "");
- },
- err: lex::error => fmt::fatal("{}", lex::errstr(err)),
- io::EOF => break,
- * => abort(),
+ fmt::errorln("{} has {} imports:", in.1, len(imports));
+ for (let i = 0z; i < len(imports); i += 1) {
+ let name = match (imports[i]) {
+ m: ast::import_module => m: ast::ident,
+ a: ast::import_alias => a.ident,
+ o: ast::import_objects => o.ident,
+ };
+ fmt::printf("use ");
+ for (let i = len(name): int - 1; i >= 0; i -= 1) {
+ fmt::printf("{}{}", name[i],
+ if (i != 0) "::" else ";\n");
+ };
};
};