From 95133360ee35f42ec277b12c88150b29936d4943 Mon Sep 17 00:00:00 2001 From: 0x4261756D <–38735823+0x4261756D@users.noreply.github.com> Date: Mon, 6 Feb 2023 16:03:48 +0100 Subject: [PATCH] Make imports work on all OSes --- src/main.rs | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) 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