Make imports work on all OSes
This commit is contained in:
parent
5aa365c681
commit
95133360ee
38
src/main.rs
38
src/main.rs
@ -304,33 +304,27 @@ fn resolve_imports(tokens: &mut Vec<Token>, functions: &mut Vec<Function>, 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<Token> = 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<Token> = 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
|
||||
|
Reference in New Issue
Block a user