aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-09 17:04:46 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-09 17:04:46 -0400
commit36572573300eaba9d0adbb63fc55067aa0fe5e0c (patch)
treeac01ab956cf245bb90ab025215a67e36dae6a3ec
parent505a188d16031adfa935d3e4063f93c5de59bf9d (diff)
Improve tool
-rw-r--r--environment.c4
-rw-r--r--examples/tomodeps.tm23
2 files changed, 16 insertions, 11 deletions
diff --git a/environment.c b/environment.c
index d6c6673c..45207da1 100644
--- a/environment.c
+++ b/environment.c
@@ -287,6 +287,7 @@ env_t *new_compilation_unit(CORD *libname)
{"from_c_string", "Text$from_str", "func(str:CString)->Text"},
{"from_codepoint_names", "Text$from_codepoint_names", "func(codepoint_names:[Text])->Text"},
{"from_codepoints", "Text$from_codepoints", "func(codepoints:[Int32])->Text"},
+ {"from_unsafe_text", "Path$cleanup", "func(text:Text)->Path"},
{"has", "Text$has", "func(text:Text, pattern:Pattern)->Bool"},
{"join", "Text$join", "func(glue:Text, pieces:[Text])->Text"},
{"lines", "Text$lines", "func(text:Text)->[Text]"},
@@ -357,7 +358,8 @@ env_t *new_compilation_unit(CORD *libname)
set_binding(namespace_env(env, "Path"), "from_unsafe_text",
new(binding_t, .type=Type(FunctionType, .args=new(arg_t, .name="text", .type=TEXT_TYPE),
.ret=Type(TextType, .lang="Path", .env=namespace_env(env, "Path"))),
- .code="(Path_t)"));
+ .code="Path$cleanup"));
+
set_binding(namespace_env(env, "Pattern"), "from_unsafe_text",
new(binding_t, .type=Type(FunctionType, .args=new(arg_t, .name="text", .type=TEXT_TYPE),
diff --git a/examples/tomodeps.tm b/examples/tomodeps.tm
index eeeffde6..209f14e0 100644
--- a/examples/tomodeps.tm
+++ b/examples/tomodeps.tm
@@ -62,9 +62,9 @@ func _build_dependency_graph(dep:Dependency, dependencies:&{Dependency:{Dependen
for dep2 in dep_deps:
_build_dependency_graph(dep2, dependencies)
-func get_dependency_graph(file:Path)->{Dependency:{Dependency}}:
+func get_dependency_graph(dep:Dependency)->{Dependency:{Dependency}}:
graph := {:Dependency:{Dependency}}
- _build_dependency_graph(Dependency.File(file:resolved()), &graph)
+ _build_dependency_graph(dep, &graph)
return graph
func _printable_name(dep:Dependency)->Text:
@@ -101,19 +101,22 @@ func draw_tree(dep:Dependency, dependencies:{Dependency:{Dependency}}):
is_child_last := (i == deps.length)
_draw_tree(child, dependencies, already_printed=&printed, is_last=is_child_last)
-func main(files:[Path]):
+func main(files:[Text]):
if files.length == 0:
exit(1, message="
Please provide at least one file!
$_USAGE
")
- for file in files:
- if not file.text_content:matches($/{..}.tm/):
- say("$\x1b[2mSkipping $file$\x1b[m")
+ for arg in files:
+ if arg:matches($/{..}.tm/):
+ path := Path.from_unsafe_text(arg):resolved()
+ dependencies := get_dependency_graph(File(path))
+ draw_tree(File(path), dependencies)
+ else if arg:matches($/{id}/):
+ dependencies := get_dependency_graph(Module(arg))
+ draw_tree(Module(arg), dependencies)
+ else:
+ say("$\x1b[2mSkipping $arg$\x1b[m")
skip
- file = file:resolved()
- dependencies := get_dependency_graph(file)
- draw_tree(Dependency.File(file), dependencies)
-