📝 add check for use statement

This commit is contained in:
ValKmjolnir 2023-10-31 19:53:01 +08:00
parent 88e4b86ccb
commit 4757dd220a
3 changed files with 41 additions and 8 deletions

View File

@ -1166,7 +1166,13 @@ void codegen::repl_mode_info_output_gen(expr* node) {
void codegen::block_gen(code_block* node) { void codegen::block_gen(code_block* node) {
for(auto tmp : node->get_expressions()) { for(auto tmp : node->get_expressions()) {
switch(tmp->get_type()) { switch(tmp->get_type()) {
case expr_type::ast_use: break; case expr_type::ast_use:
if (!local.empty()) {
die("module import is not allowed here.",
tmp->get_location()
);
}
break;
case expr_type::ast_null: break; case expr_type::ast_null: break;
case expr_type::ast_id: case expr_type::ast_id:
if (need_repl_output && local.empty()) { if (need_repl_output && local.empty()) {

View File

@ -1,7 +1,9 @@
println("[",os.time(),"] auto push, please wait..."); println("[",os.time(),"] (=.=) auto push, please wait...");
while(system("git push")!=0) { while(system("git push")!=0) {
println("[",os.time(),"] failed to push, retrying..."); println("[",os.time(),"] (ToT) failed to push, retrying...");
unix.sleep(0.5); unix.sleep(0.5);
} }
println("[",os.time(),"] (^o^) auto push complete.");

View File

@ -1,7 +1,17 @@
import.std.file; import.std.file;
if (size(arg)!=1) { var tips = func() {
println("usage:");
println(" nasal search_file.nas [key]");
}
if (size(arg)<1) {
println("need a key string to search files."); println("need a key string to search files.");
tips();
exit(-1);
} else if (size(arg)>1) {
println("too many arguments.");
tips();
exit(-1); exit(-1);
} }
@ -12,7 +22,7 @@ var do_flat = func(vec) {
var bfs = [vec]; var bfs = [vec];
while(size(bfs)) { while(size(bfs)) {
var d = pop(bfs); var d = pop(bfs);
foreach(var f;d.files) { foreach(var f; d.files) {
if (ishash(f)) { if (ishash(f)) {
append(bfs,f); append(bfs,f);
continue; continue;
@ -20,12 +30,12 @@ var do_flat = func(vec) {
append(flat, d.dir~"/"~f); append(flat, d.dir~"/"~f);
} }
} }
sort(flat, func(a,b){return cmp(a,b)<0}); sort(flat, func(a, b){return cmp(a, b)<0});
return flat; return flat;
} }
var count = 0; var count = 0;
foreach(var f;do_flat(file.recursive_find_files("."))) { foreach(var f; do_flat(file.recursive_find_files("."))) {
var pos = find(needle, f); var pos = find(needle, f);
if (pos == -1) { if (pos == -1) {
continue; continue;
@ -33,7 +43,22 @@ foreach(var f;do_flat(file.recursive_find_files("."))) {
count += 1; count += 1;
var begin = substr(f, 0, pos); var begin = substr(f, 0, pos);
var end = pos+size(needle)>=size(f)? "":substr(f, pos+size(needle), size(f)); var end = pos+size(needle)>=size(f)? "":substr(f, pos+size(needle), size(f));
println(begin, "\e[95;1m", needle, "\e[0m", end); var file_size = fstat(f).st_size;
var unit = "b";
if (file_size>1024) {
file_size/=1024;
unit = "kb";
}
if (file_size>1024) {
file_size/=1024;
unit = "mb";
}
if (file_size>1024) {
file_size/=1024;
unit = "gb";
}
file_size = int(file_size);
println(begin, "\e[95;1m", needle, "\e[0m", end, " | ", file_size, " ", unit);
} }
println("\n", count, " result(s)."); println("\n", count, " result(s).");