diff --git a/src/parser/bold.rs b/src/parser/bold.rs index 9492c0a..7f0052c 100644 --- a/src/parser/bold.rs +++ b/src/parser/bold.rs @@ -1,7 +1,6 @@ use crate::parser::parser_with_context::parser_with_context; use super::combinator::context_many_till; -use super::document::in_section; use super::error::CustomError; use super::error::MyError; use super::error::Res; @@ -13,6 +12,7 @@ use super::text::text_element; use super::text::Bold; use super::text::TextElement; use super::token::Token; +use super::util::in_section; use super::Context; use nom::branch::alt; use nom::bytes::complete::tag; diff --git a/src/parser/document.rs b/src/parser/document.rs index 2cbe311..27af25f 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -23,16 +23,3 @@ pub fn document(input: &str) -> Res<&str, Vec> { .collect(); Ok((remaining, paragraphs)) } - -pub fn in_section<'s, 'r, 'x>(context: Context<'r, 's>, section_name: &'x str) -> bool { - for thing in context.iter() { - match thing.get_data() { - ContextElement::ExitMatcherNode(_) => {} - ContextElement::PreviousElementNode(_) => {} - ContextElement::Context(name) if *name == section_name => return true, - ContextElement::Context(_) => {} - ContextElement::StartOfParagraph => {} // TODO: If we specialize this to bold then this would be a good spot to stop scanning - } - } - false -} diff --git a/src/parser/link.rs b/src/parser/link.rs index ac31888..e7b39ad 100644 --- a/src/parser/link.rs +++ b/src/parser/link.rs @@ -1,7 +1,6 @@ use crate::parser::parser_with_context::parser_with_context; use super::combinator::context_many_till; -use super::document::in_section; use super::error::CustomError; use super::error::MyError; use super::error::Res; @@ -12,6 +11,7 @@ use super::text::symbol; use super::text::text_element; use super::text::Link; use super::text::TextElement; +use super::util::in_section; use super::Context; use nom::combinator::map; use nom::combinator::recognize; diff --git a/src/parser/mod.rs b/src/parser/mod.rs index f3f80d7..7e0fd1d 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -1,5 +1,6 @@ mod bold; mod combinator; +mod document; mod error; mod link; mod list; @@ -7,7 +8,7 @@ mod paragraph; mod parser_context; mod parser_with_context; mod text; -mod document; mod token; +mod util; pub use document::document; type Context<'r, 's> = &'r parser_context::ContextTree<'r, 's>; diff --git a/src/parser/util.rs b/src/parser/util.rs new file mode 100644 index 0000000..c06fb3e --- /dev/null +++ b/src/parser/util.rs @@ -0,0 +1,15 @@ +use super::parser_context::ContextElement; +use super::Context; + +pub fn in_section<'s, 'r, 'x>(context: Context<'r, 's>, section_name: &'x str) -> bool { + for thing in context.iter() { + match thing.get_data() { + ContextElement::ExitMatcherNode(_) => {} + ContextElement::PreviousElementNode(_) => {} + ContextElement::Context(name) if *name == section_name => return true, + ContextElement::Context(_) => {} + ContextElement::StartOfParagraph => {} // TODO: If we specialize this to bold then this would be a good spot to stop scanning + } + } + false +}