diff --git a/src/parser/document.rs b/src/parser/document.rs index 3b467a2f..4f09a947 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -36,6 +36,7 @@ use crate::error::Res; use crate::parser::comment::comment; use crate::parser::element_parser::element; use crate::parser::object_parser::standard_set_object; +use crate::parser::org_source::convert_error; use crate::parser::planning::planning; use crate::parser::property_drawer::property_drawer; use crate::parser::util::blank_line; @@ -54,15 +55,26 @@ pub fn parse<'s>(input: &'s str) -> Result, String> { let initial_context = ContextElement::document_context(); let initial_context = Context::new(&global_settings, List::new(&initial_context)); let wrapped_input = OrgSource::new(input); - let ret = all_consuming(parser_with_context!(document)(&initial_context))(wrapped_input) - .map_err(|err| err.to_string()) - .map(|(_remaining, parsed_document)| parsed_document); + let ret = + all_consuming(parser_with_context!(document_org_source)(&initial_context))(wrapped_input) + .map_err(|err| err.to_string()) + .map(|(_remaining, parsed_document)| parsed_document); ret } #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[allow(dead_code)] pub fn document<'b, 'g, 'r, 's>( + context: RefContext<'b, 'g, 'r, 's>, + input: &'s str, +) -> Res<&'s str, Document<'s>> { + let (remaining, doc) = document_org_source(context, input.into()).map_err(convert_error)?; + Ok((Into::<&str>::into(remaining), doc)) +} + +#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] +#[allow(dead_code)] +fn document_org_source<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, Document<'s>> {