aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2025-01-09 16:32:34 +0100
committerMiquel Sabaté Solà <mikisabate@gmail.com>2025-01-09 16:32:34 +0100
commita4a68fdb178722e23e007b1f6bf72474caae4e97 (patch)
treef014b783d301c9ceb878c783ba2b7b2054772cfe /lib/xixanta
parent92092ccc245269e0c3a864d06f7e382a5bb9d8b0 (diff)
downloadtools.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>
Diffstat (limited to 'lib/xixanta')
-rw-r--r--lib/xixanta/src/assembler.rs4
-rw-r--r--lib/xixanta/src/lib.rs8
-rw-r--r--lib/xixanta/src/parser.rs7
3 files changed, 11 insertions, 8 deletions
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(),
},
)?;