Read the setup file into memory.
This commit is contained in:
parent
a7330e38e4
commit
ee02e07717
@ -1,15 +1,14 @@
|
|||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
pub trait FileAccessInterface: Debug {
|
pub trait FileAccessInterface: Debug {
|
||||||
fn read_file(&self, path: &dyn AsRef<Path>) -> Result<String, Box<dyn std::error::Error>>;
|
fn read_file(&self, path: &str) -> Result<String, std::io::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct LocalFileAccessInterface;
|
pub struct LocalFileAccessInterface;
|
||||||
|
|
||||||
impl FileAccessInterface for LocalFileAccessInterface {
|
impl FileAccessInterface for LocalFileAccessInterface {
|
||||||
fn read_file(&self, path: &dyn AsRef<Path>) -> Result<String, Box<dyn std::error::Error>> {
|
fn read_file(&self, path: &str) -> Result<String, std::io::Error> {
|
||||||
Ok(std::fs::read_to_string(path)?)
|
Ok(std::fs::read_to_string(path)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,14 @@ use nom::IResult;
|
|||||||
pub type Res<T, U> = IResult<T, U, CustomError<T>>;
|
pub type Res<T, U> = IResult<T, U, CustomError<T>>;
|
||||||
|
|
||||||
// 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.
|
// 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<I> {
|
pub enum CustomError<I> {
|
||||||
MyError(MyError<I>),
|
MyError(MyError<I>),
|
||||||
Nom(I, ErrorKind),
|
Nom(I, ErrorKind),
|
||||||
|
IO(std::io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug)]
|
||||||
pub struct MyError<I>(pub I);
|
pub struct MyError<I>(pub I);
|
||||||
|
|
||||||
impl<I> ParseError<I> for CustomError<I> {
|
impl<I> ParseError<I> for CustomError<I> {
|
||||||
@ -24,3 +25,9 @@ impl<I> ParseError<I> for CustomError<I> {
|
|||||||
other
|
other
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<I> From<std::io::Error> for CustomError<I> {
|
||||||
|
fn from(value: std::io::Error) -> Self {
|
||||||
|
CustomError::IO(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -33,6 +33,7 @@ use crate::context::ExitMatcherNode;
|
|||||||
use crate::context::GlobalSettings;
|
use crate::context::GlobalSettings;
|
||||||
use crate::context::List;
|
use crate::context::List;
|
||||||
use crate::context::RefContext;
|
use crate::context::RefContext;
|
||||||
|
use crate::error::CustomError;
|
||||||
use crate::error::Res;
|
use crate::error::Res;
|
||||||
use crate::parser::comment::comment;
|
use crate::parser::comment::comment;
|
||||||
use crate::parser::element_parser::element;
|
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);
|
let setup_file = scan_for_setup_file(input);
|
||||||
if setup_file.is_ok() {
|
if setup_file.is_ok() {
|
||||||
let (_remaining, setup_file) = setup_file.expect("If-statement proves this is okay.");
|
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::<CustomError<OrgSource<'_>>>::Failure(err.into()))?;
|
||||||
|
|
||||||
println!("TODO: Process setup_file: {}", setup_file);
|
println!("TODO: Process setup_file: {}", setup_file);
|
||||||
}
|
}
|
||||||
let (remaining, document) =
|
let (remaining, document) =
|
||||||
|
@ -318,6 +318,7 @@ impl<'s> From<CustomError<OrgSource<'s>>> for CustomError<&'s str> {
|
|||||||
match value {
|
match value {
|
||||||
CustomError::MyError(err) => CustomError::MyError(err.into()),
|
CustomError::MyError(err) => CustomError::MyError(err.into()),
|
||||||
CustomError::Nom(input, error_kind) => CustomError::Nom(input.into(), error_kind),
|
CustomError::Nom(input, error_kind) => CustomError::Nom(input.into(), error_kind),
|
||||||
|
CustomError::IO(err) => CustomError::IO(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user