diff --git a/src/main.rs b/src/main.rs index 205eb3c..438e359 100644 --- a/src/main.rs +++ b/src/main.rs @@ -304,33 +304,27 @@ fn resolve_imports(tokens: &mut Vec, functions: &mut Vec, file_ { if let Some(Token::StringLit(import_path, _, _)) = tokens_iter.next() { - match fs::canonicalize(format!("{}/{}", fs::canonicalize(file_path).map_err(|e| e.to_string())?.parent().unwrap_or(&PathBuf::from(".")).display(), import_path)) + let full_import_path = fs::canonicalize(file_path).map_err(|e| e.to_string())?.parent().unwrap().join(import_path); + if visited_paths.contains(&full_import_path) { - Ok(full_import_path) => + println!("--Already visited {}--", full_import_path.display()); + } + else + { + visited_paths.push(full_import_path.clone()); + let maybe_file_content = fs::read_to_string(full_import_path); + match maybe_file_content { - if visited_paths.contains(&full_import_path) + Ok(file_content) => { - println!("--Already visited {}--", full_import_path.display()); - } - else - { - visited_paths.push(full_import_path.clone()); - let maybe_file_content = fs::read_to_string(full_import_path); - match maybe_file_content - { - Ok(file_content) => - { - let mut import_tokens: Vec = tokenize(&file_content)?; - println!("--Done tokenizing the imported file at {}:{}, got {} tokens--", line, col, tokens.len()); - extract_functions(&mut import_tokens, functions, &intrinsics, debug)?; - resolve_imports(&mut import_tokens, functions, file_path, visited_paths, intrinsics, debug)?; - println!("--Now totalling {} functions--", functions.len()); - } - Err(e) => return Err(e.to_string()), - } + let mut import_tokens: Vec = tokenize(&file_content)?; + println!("--Done tokenizing the imported file at {}:{}, got {} tokens--", line, col, tokens.len()); + extract_functions(&mut import_tokens, functions, &intrinsics, debug)?; + resolve_imports(&mut import_tokens, functions, file_path, visited_paths, intrinsics, debug)?; + println!("--Now totalling {} functions--", functions.len()); } + Err(e) => return Err(e.to_string()), } - Err(e) => return Err(e.to_string()), } } else