Skip to content

Commit

Permalink
📝 add check for use statement
Browse files Browse the repository at this point in the history
  • Loading branch information
ValKmjolnir committed Oct 31, 2023
1 parent 88e4b86 commit 4757dd2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/nasal_codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,13 @@ void codegen::repl_mode_info_output_gen(expr* node) {
void codegen::block_gen(code_block* node) {
for(auto tmp : node->get_expressions()) {
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_id:
if (need_repl_output && local.empty()) {
Expand Down
6 changes: 4 additions & 2 deletions tools/push.nas
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

println("[",os.time(),"] auto push, please wait...");
println("[",os.time(),"] (=.=) auto push, please wait...");

while(system("git push")!=0) {
println("[",os.time(),"] failed to push, retrying...");
println("[",os.time(),"] (ToT) failed to push, retrying...");
unix.sleep(0.5);
}

println("[",os.time(),"] (^o^) auto push complete.");
35 changes: 30 additions & 5 deletions tools/search_file.nas
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
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.");
tips();
exit(-1);
} else if (size(arg)>1) {
println("too many arguments.");
tips();
exit(-1);
}

Expand All @@ -12,28 +22,43 @@ var do_flat = func(vec) {
var bfs = [vec];
while(size(bfs)) {
var d = pop(bfs);
foreach(var f;d.files) {
foreach(var f; d.files) {
if (ishash(f)) {
append(bfs,f);
continue;
}
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;
}

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);
if (pos == -1) {
continue;
}
count += 1;
var begin = substr(f, 0, pos);
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).");

0 comments on commit 4757dd2

Please sign in to comment.