diff --git a/src/context/file_access_interface.rs b/src/context/file_access_interface.rs index ff8d9e3..a31c020 100644 --- a/src/context/file_access_interface.rs +++ b/src/context/file_access_interface.rs @@ -1,15 +1,14 @@ use std::fmt::Debug; -use std::path::Path; pub trait FileAccessInterface: Debug { - fn read_file(&self, path: &dyn AsRef) -> Result>; + fn read_file(&self, path: &str) -> Result; } #[derive(Debug, Clone)] pub struct LocalFileAccessInterface; impl FileAccessInterface for LocalFileAccessInterface { - fn read_file(&self, path: &dyn AsRef) -> Result> { + fn read_file(&self, path: &str) -> Result { Ok(std::fs::read_to_string(path)?) } } diff --git a/src/error/error.rs b/src/error/error.rs index ef61469..5a620f0 100644 --- a/src/error/error.rs +++ b/src/error/error.rs @@ -5,13 +5,14 @@ use nom::IResult; pub type Res = IResult>; // TODO: MyError probably shouldn't be based on the same type as the input type since it's used exclusively with static strings right now. -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub enum CustomError { MyError(MyError), Nom(I, ErrorKind), + IO(std::io::Error), } -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub struct MyError(pub I); impl ParseError for CustomError { @@ -24,3 +25,9 @@ impl ParseError for CustomError { other } } + +impl From for CustomError { + fn from(value: std::io::Error) -> Self { + CustomError::IO(value) + } +} diff --git a/src/parser/document.rs b/src/parser/document.rs index 4e7084d..6e03cc9 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -33,6 +33,7 @@ use crate::context::ExitMatcherNode; use crate::context::GlobalSettings; use crate::context::List; use crate::context::RefContext; +use crate::error::CustomError; use crate::error::Res; use crate::parser::comment::comment; use crate::parser::element_parser::element; @@ -82,6 +83,12 @@ fn document_org_source<'b, 'g, 'r, 's>( let setup_file = scan_for_setup_file(input); if setup_file.is_ok() { let (_remaining, setup_file) = setup_file.expect("If-statement proves this is okay."); + let setup_file_contents = context + .get_global_settings() + .file_access + .read_file(Into::<&str>::into(setup_file)) + .map_err(|err| nom::Err::>>::Failure(err.into()))?; + println!("TODO: Process setup_file: {}", setup_file); } let (remaining, document) = diff --git a/src/parser/org_source.rs b/src/parser/org_source.rs index dc2bf0c..87f93da 100644 --- a/src/parser/org_source.rs +++ b/src/parser/org_source.rs @@ -318,6 +318,7 @@ impl<'s> From>> for CustomError<&'s str> { match value { CustomError::MyError(err) => CustomError::MyError(err.into()), CustomError::Nom(input, error_kind) => CustomError::Nom(input.into(), error_kind), + CustomError::IO(err) => CustomError::IO(err), } } }