diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-09 16:32:34 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-09 16:32:34 +0100 |
| commit | a4a68fdb178722e23e007b1f6bf72474caae4e97 (patch) | |
| tree | f014b783d301c9ceb878c783ba2b7b2054772cfe | |
| parent | 92092ccc245269e0c3a864d06f7e382a5bb9d8b0 (diff) | |
| download | tools.nes-a4a68fdb178722e23e007b1f6bf72474caae4e97.tar.gz tools.nes-a4a68fdb178722e23e007b1f6bf72474caae4e97.zip | |
Rename SourceInfo::working_directory to directory
Also documented the struct as it is exported.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
| -rw-r--r-- | crates/nasm/src/main.rs | 4 | ||||
| -rw-r--r-- | lib/xixanta/src/assembler.rs | 4 | ||||
| -rw-r--r-- | lib/xixanta/src/lib.rs | 8 | ||||
| -rw-r--r-- | lib/xixanta/src/parser.rs | 7 |
4 files changed, 13 insertions, 10 deletions
diff --git a/crates/nasm/src/main.rs b/crates/nasm/src/main.rs index 561e305..0f65fbf 100644 --- a/crates/nasm/src/main.rs +++ b/crates/nasm/src/main.rs @@ -50,7 +50,7 @@ fn main() -> Result<()> { input = Box::new(File::open(file)?); SourceInfo { - working_directory: path + directory: path .parent() .with_context(|| String::from("Failed to find directory for given file"))? .to_path_buf(), @@ -60,7 +60,7 @@ fn main() -> Result<()> { None => { input = Box::new(std::io::stdin()); SourceInfo { - working_directory: std::env::current_dir() + directory: std::env::current_dir() .with_context(|| String::from("Could not fetch current directory"))? .to_path_buf(), name: "<stdin>".to_string(), diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs index 99f76d9..c52c36c 100644 --- a/lib/xixanta/src/assembler.rs +++ b/lib/xixanta/src/assembler.rs @@ -1310,7 +1310,7 @@ impl<'a> Assembler<'a> { // `File` operations work in this way, set the current directory now. match &self.sources.get(node.source) { Some(source) => { - if let Err(e) = std::env::set_current_dir(&source.working_directory) { + if let Err(e) = std::env::set_current_dir(&source.directory) { return Err(Error { line: node.value.line, message: format!("could not move to the directory of '{}': {}", value, e), @@ -1935,7 +1935,7 @@ impl<'a> Assembler<'a> { self.sources .get(node.source) .unwrap_or(&SourceInfo { - working_directory: self.sources[0].working_directory.clone(), + directory: self.sources[0].directory.clone(), name: self.sources[0].name.clone(), }) .clone() diff --git a/lib/xixanta/src/lib.rs b/lib/xixanta/src/lib.rs index 2da8fd0..ce9be6d 100644 --- a/lib/xixanta/src/lib.rs +++ b/lib/xixanta/src/lib.rs @@ -1,16 +1,20 @@ #[macro_use] extern crate lazy_static; +/// Information for a file that has been parsed/assembled. #[derive(Clone, Debug, PartialEq)] pub struct SourceInfo { - pub working_directory: std::path::PathBuf, + /// Directory where the file is located. + pub directory: std::path::PathBuf, + + /// Friendly name for the given file. pub name: String, } impl Default for SourceInfo { fn default() -> Self { SourceInfo { - working_directory: std::env::current_dir().unwrap().to_path_buf(), + directory: std::env::current_dir().unwrap().to_path_buf(), name: "".to_string(), } } diff --git a/lib/xixanta/src/parser.rs b/lib/xixanta/src/parser.rs index 6ea23f4..2e938d3 100644 --- a/lib/xixanta/src/parser.rs +++ b/lib/xixanta/src/parser.rs @@ -59,8 +59,7 @@ impl Parser { // be initialized by the caller already). The `current_source` is simply // the one we push upon initialization. self.sources.push(SourceInfo { - working_directory: path::absolute(&source.working_directory) - .unwrap_or(source.working_directory), + directory: path::absolute(&source.directory).unwrap_or(source.directory), name: source.name, }); self.current_source = self.sources.len() - 1; @@ -631,7 +630,7 @@ impl Parser { let Some(current_source) = self.sources.get(self.current_source) else { panic!("mismatch between the number of sources and the current one"); }; - let abs_file = current_source.working_directory.join(file_path); + let abs_file = current_source.directory.join(file_path); // Validate that this is really a path that points to a file. let path = std::path::Path::new(&abs_file); @@ -680,7 +679,7 @@ impl Parser { parser.parse( file, SourceInfo { - working_directory: parent.to_path_buf(), + directory: parent.to_path_buf(), name: path.file_name().unwrap().to_str().unwrap().to_string(), }, )?; |
