diff --git a/src/lib.rs b/src/lib.rs index 58083c0..de1b32d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,7 @@ pub mod named; pub mod num; pub mod parse; pub mod pattern; +pub mod resolution; #[cfg(feature = "serde")] mod serde; pub mod str; diff --git a/src/resolution.rs b/src/resolution.rs new file mode 100644 index 0000000..39b1040 --- /dev/null +++ b/src/resolution.rs @@ -0,0 +1,37 @@ +use std::path::Path; +use std::sync::Arc; + +/// Powers error reporting by mapping compiler diagnostics to the specific file. +#[derive(Debug, Clone, Eq, PartialEq, Hash)] +pub struct SourceFile { + /// The name or path of the source file (e.g., "./simf/main.simf"). + name: Arc, + /// The actual text content of the source file. + content: Arc, +} + +impl From<(&Path, &str)> for SourceFile { + fn from((name, content): (&Path, &str)) -> Self { + Self { + name: Arc::from(name), + content: Arc::from(content), + } + } +} + +impl SourceFile { + pub fn new(name: &Path, content: Arc) -> Self { + Self { + name: Arc::from(name), + content, + } + } + + pub fn name(&self) -> &Path { + self.name.as_ref() + } + + pub fn content(&self) -> Arc { + self.content.clone() + } +}