From 33091112a5a5895e87278bc3064c90a7f4384160 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 4 Sep 2023 11:36:42 -0400 Subject: [PATCH] Remove OrgSource from the public document parser interface. --- src/parser/document.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/parser/document.rs b/src/parser/document.rs index 3b467a2..4f09a94 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>> {