diff options
author | Kyle Gunger <kgunger12@gmail.com> | 2024-07-21 02:53:02 -0400 |
---|---|---|
committer | Kyle Gunger <kgunger12@gmail.com> | 2024-07-21 02:53:02 -0400 |
commit | 7d6b6dfc10c549238ceb11b0a01b3e440508cec4 (patch) | |
tree | 9f5b4b5ae7e94afe8406bc59814d6a6cbcd9bd01 | |
parent | 0c04a61ef15f02eadc24d46b9527e0afb74040a4 (diff) |
semi-broken file imports
-rw-r--r-- | tnslc/parse/ast.tnsl | 58 | ||||
-rw-r--r-- | tnslc/parse/tokenizer.tnsl | 13 |
2 files changed, 63 insertions, 8 deletions
diff --git a/tnslc/parse/ast.tnsl b/tnslc/parse/ast.tnsl index 86788e7..cdd0ae2 100644 --- a/tnslc/parse/ast.tnsl +++ b/tnslc/parse/ast.tnsl @@ -32,10 +32,11 @@ struct Node { ~Node cur = self.sub.get(i) cur`.end() ;/ + self.sub.end() ;/ ;/ -/; _ast_root_loop (~utils.File fin, ~Node mod, Token first) +/; _ast_block (~utils.File fin, ~Node mod, Token first) ;/ /; _ast_module (~utils.File fin, ~Node mod, Token first) @@ -54,15 +55,64 @@ struct Node { out.init(t, tmp.data) tmp = produce_next_token(fin, tmp) - _ast_root_loop(fin, ~out, tmp) + /; loop (tmp.eq(";/\0") !== true) + /; if (tmp.eq("import\0")) + first = produce_next_token(fin, tmp) + tmp.end() + tmp = first + + ~uint8 path = utils.unquote_str(tmp.data) + utils.File _import = fin`.relative(path) + _delete(path) + path = _import.path.to_cstr('/') + + _printf("Importing ./\0") + _printf(path) + _printf("\n\0") + _delete(path) + + _ast_file(~_import, mod) + _import.end() + + ;; else + first = produce_next_token(fin, tmp) + tmp.end() + tmp = first + ;/ + ;/ + mod`.sub.push(~out) ;/ /; _ast_file (~utils.File fin, ~Node mod) fin`.open() - Token tok = produce_first_token(fin) - _ast_root_loop(fin, mod, tok) + Token tmp = produce_first_token(fin) + Token first + /; loop (tmp._type !== TTYPE_ERR) + /; if (tmp.eq("import\0")) + first = produce_next_token(fin, tmp) + tmp.end() + tmp = first + + ~uint8 path = utils.unquote_str(tmp.data) + utils.File _import = fin`.relative(path) + _delete(path) + path = _import.path.to_cstr('/') + + _printf("Importing ./\0") + _printf(path) + _printf("\n\0") + _delete(path) + + _ast_file(~_import, mod) + _import.end() + ;; else + first = produce_next_token(fin, tmp) + tmp.end() + tmp = first + ;/ + ;/ fin`.close() ;/ diff --git a/tnslc/parse/tokenizer.tnsl b/tnslc/parse/tokenizer.tnsl index 0df0ef8..c2ef091 100644 --- a/tnslc/parse/tokenizer.tnsl +++ b/tnslc/parse/tokenizer.tnsl @@ -84,12 +84,12 @@ uint MAX_MULTI = 3 uint8 ch = fin`.read() - /; loop (fin`.at_end == false && is_reserved(ch) == false && is_whitespace(ch) == false) + /; loop (ch !== 0 && is_reserved(ch) == false && is_whitespace(ch) == false) tmp.push(~ch) ch = fin`.read() ;/ - /; if (fin`.at_end == false) + /; if (ch !== 0) fin`.unread() ;/ @@ -262,7 +262,10 @@ uint MAX_MULTI = 3 bool base = false /; if (ch == '0') ch = fin`.read() - /; if (is_reserved(ch) == false && is_whitespace(ch) == false && is_numeric(ch) == false) + /; if (ch == 0) + out.data = tmp.as_cstr() + return out + ;; else if (is_reserved(ch) == false && is_whitespace(ch) == false && is_numeric(ch) == false) base = true tmp.push(~ch) ;/ @@ -271,7 +274,9 @@ uint MAX_MULTI = 3 bool decimal = false /; loop (bool run = true; run == true && fin`.at_end == false) ch = fin`.read() - /; if (decimal == false && ch == '.') + /; if (ch == 0) + run = false + ;; else if (decimal == false && ch == '.') decimal = true tmp.push(~ch) ;; else if (is_reserved(ch) == true || is_whitespace(ch) == true) |