diff --git a/src/parser/citation.rs b/src/parser/citation.rs index dae8b31..e19938b 100644 --- a/src/parser/citation.rs +++ b/src/parser/citation.rs @@ -203,24 +203,21 @@ fn global_suffix_end<'r, 's>( mod tests { use super::*; use crate::parser::element_parser::element; - use crate::parser::parser_context::ContextElement; use crate::parser::parser_context::ContextTree; use crate::parser::parser_with_context::parser_with_context; use crate::parser::source::Source; #[test] fn citation_simple() { - let input = "[cite:@foo]"; + let input = OrgSource::new("[cite:@foo]"); let initial_context: ContextTree<'_, '_> = ContextTree::new(); - let document_context = - initial_context.with_additional_node(ContextElement::DocumentRoot(input)); - let paragraph_matcher = parser_with_context!(element(true))(&document_context); + let paragraph_matcher = parser_with_context!(element(true))(&initial_context); let (remaining, first_paragraph) = paragraph_matcher(input).expect("Parse first paragraph"); let first_paragraph = match first_paragraph { crate::parser::Element::Paragraph(paragraph) => paragraph, _ => panic!("Should be a paragraph!"), }; - assert_eq!(remaining, ""); + assert_eq!(Into::<&str>::into(remaining), ""); assert_eq!(first_paragraph.get_source(), "[cite:@foo]"); assert_eq!(first_paragraph.children.len(), 1); assert_eq!( diff --git a/src/parser/document.rs b/src/parser/document.rs index 09ddcd5..29dd89f 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -98,9 +98,7 @@ impl<'s> Source<'s> for Heading<'s> { pub fn document(input: &str) -> Res<&str, Document> { let initial_context: ContextTree<'_, '_> = ContextTree::new(); let wrapped_input = OrgSource::new(input); - let document_context = - initial_context.with_additional_node(ContextElement::DocumentRoot(input)); - let (remaining, document) = _document(&document_context, wrapped_input) + let (remaining, document) = _document(&initial_context, wrapped_input) .map(|(rem, out)| (Into::<&str>::into(rem), out)) .map_err(convert_error)?; { @@ -118,9 +116,9 @@ pub fn document(input: &str) -> Res<&str, Document> { .map(|rt| &rt.children) .collect(); if !all_radio_targets.is_empty() { - let document_context = document_context + let initial_context = initial_context .with_additional_node(ContextElement::RadioTarget(all_radio_targets)); - let (remaining, document) = _document(&document_context, wrapped_input) + let (remaining, document) = _document(&initial_context, wrapped_input) .map(|(rem, out)| (Into::<&str>::into(rem), out)) .map_err(convert_error)?; return Ok((remaining.into(), document)); diff --git a/src/parser/parser_context.rs b/src/parser/parser_context.rs index 7001072..1369cd9 100644 --- a/src/parser/parser_context.rs +++ b/src/parser/parser_context.rs @@ -85,19 +85,6 @@ impl<'r, 's> ContextTree<'r, 's> { )))); } - pub fn get_document_root(&self) -> Option<&'s str> { - for current_node in self.iter() { - let context_element = current_node.get_data(); - match context_element { - ContextElement::DocumentRoot(body) => { - return Some(body); - } - _ => {} - } - } - None - } - /// Indicates if elements should consume the whitespace after them. /// /// Defaults to true. @@ -121,11 +108,6 @@ impl<'r, 's> ContextTree<'r, 's> { #[derive(Debug)] pub enum ContextElement<'r, 's> { - /// Stores a reference to the entire org-mode document being parsed. - /// - /// This is used for look-behind. - DocumentRoot(&'s str), - /// Stores a parser that indicates that children should exit upon matching an exit matcher. ExitMatcherNode(ExitMatcherNode<'r>), Context(&'r str),