Skip to content

Commit

Permalink
Add some parsing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Saverio976 committed Jan 29, 2024
1 parent 5749bd1 commit f79bfb5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
5 changes: 5 additions & 0 deletions src/output_d2.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module main

fn output_d2(deps []DependencyGraph) ![]string {
return []string{}
}
5 changes: 4 additions & 1 deletion src/process_file.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
26 changes: 26 additions & 0 deletions src/process_file_haskell.v
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit f79bfb5

Please sign in to comment.