2024-01-08 13:26:33 -08:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
pub(crate) struct Source<'src> {
|
|
|
|
pub(crate) path: PathBuf,
|
|
|
|
pub(crate) depth: u32,
|
|
|
|
pub(crate) namepath: Namepath<'src>,
|
2024-01-11 19:00:38 -08:00
|
|
|
pub(crate) working_directory: PathBuf,
|
2024-01-08 13:26:33 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'src> Source<'src> {
|
|
|
|
pub(crate) fn root(path: &Path) -> Self {
|
|
|
|
Self {
|
|
|
|
path: path.into(),
|
|
|
|
depth: 0,
|
|
|
|
namepath: Namepath::default(),
|
2024-01-11 19:00:38 -08:00
|
|
|
working_directory: path.parent().unwrap().into(),
|
2024-01-08 13:26:33 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn import(&self, path: PathBuf) -> Self {
|
|
|
|
Self {
|
|
|
|
depth: self.depth + 1,
|
|
|
|
path,
|
|
|
|
namepath: self.namepath.clone(),
|
2024-01-11 19:00:38 -08:00
|
|
|
working_directory: self.working_directory.clone(),
|
2024-01-08 13:26:33 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn module(&self, name: Name<'src>, path: PathBuf) -> Self {
|
|
|
|
Self {
|
2024-01-11 19:00:38 -08:00
|
|
|
working_directory: path.parent().unwrap().into(),
|
2024-01-08 13:26:33 -08:00
|
|
|
path,
|
|
|
|
depth: self.depth + 1,
|
|
|
|
namepath: self.namepath.join(name),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|