diff --git a/src/main.v b/src/main.v index a020b71..346684c 100644 --- a/src/main.v +++ b/src/main.v @@ -18,11 +18,17 @@ fn main() { eprintln(fp.usage()) exit(1) } + mut deps := []DependencyGraph{} for folder in folders { println('Processing ${folder} ...') dep := process_folder(folder, a_string) or { eprintln(err) continue } + deps << dep + } + output_d2(deps) or { + eprintln(err) + exit(1) } } diff --git a/src/output_d2.v b/src/output_d2.v new file mode 100644 index 0000000..252e084 --- /dev/null +++ b/src/output_d2.v @@ -0,0 +1,5 @@ +module main + +fn output_d2(deps []DependencyGraph) ![]string { + return []string{} +} diff --git a/src/process_file.v b/src/process_file.v index e2a1436..55f28b9 100644 --- a/src/process_file.v +++ b/src/process_file.v @@ -14,9 +14,12 @@ fn process_file(file string, language string) !DependencyGraph { if !os.is_file(file) { return error("not a file ${file}") } - dep := DependencyGraph{ + mut dep := DependencyGraph{ language: language, file_path: file, } + if is_haskell_file(file) { + process_file_haskell(mut dep)! + } return dep } diff --git a/src/process_file_haskell.v b/src/process_file_haskell.v new file mode 100644 index 0000000..aaa50a5 --- /dev/null +++ b/src/process_file_haskell.v @@ -0,0 +1,26 @@ +module main + +import os +import regex + +fn is_haskell_file(file string) bool { + return file.ends_with('.hs') +} + +fn process_file_haskell(mut dep &DependencyGraph) ! { + mut name := dep.file_path.split(os.path_separator) + if 'src' in name { + name.drop(name.index('src')) + } + if 'app' in name { + name.drop(name.index('app')) + } + dep.name << name.join('.') + query := r'^import (qualified)? ([\w.]+)' + mut re := regex.regex_opt(query)! + lines := os.read_file(dep.file_path)! + for imports in re.find_all_str(lines) { + dep_tmp := re.get_group_by_id(imports, 2) + dep.dependencies << dep_tmp + } +}