Move in_section to a util module.

This commit is contained in:
Tom Alexander 2022-12-18 03:18:43 -05:00
parent 6404e5f50e
commit 8211e1043f
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
5 changed files with 19 additions and 16 deletions

View File

@ -1,7 +1,6 @@
use crate::parser::parser_with_context::parser_with_context; use crate::parser::parser_with_context::parser_with_context;
use super::combinator::context_many_till; use super::combinator::context_many_till;
use super::document::in_section;
use super::error::CustomError; use super::error::CustomError;
use super::error::MyError; use super::error::MyError;
use super::error::Res; use super::error::Res;
@ -13,6 +12,7 @@ use super::text::text_element;
use super::text::Bold; use super::text::Bold;
use super::text::TextElement; use super::text::TextElement;
use super::token::Token; use super::token::Token;
use super::util::in_section;
use super::Context; use super::Context;
use nom::branch::alt; use nom::branch::alt;
use nom::bytes::complete::tag; use nom::bytes::complete::tag;

View File

@ -23,16 +23,3 @@ pub fn document(input: &str) -> Res<&str, Vec<Paragraph>> {
.collect(); .collect();
Ok((remaining, paragraphs)) 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
}

View File

@ -1,7 +1,6 @@
use crate::parser::parser_with_context::parser_with_context; use crate::parser::parser_with_context::parser_with_context;
use super::combinator::context_many_till; use super::combinator::context_many_till;
use super::document::in_section;
use super::error::CustomError; use super::error::CustomError;
use super::error::MyError; use super::error::MyError;
use super::error::Res; use super::error::Res;
@ -12,6 +11,7 @@ use super::text::symbol;
use super::text::text_element; use super::text::text_element;
use super::text::Link; use super::text::Link;
use super::text::TextElement; use super::text::TextElement;
use super::util::in_section;
use super::Context; use super::Context;
use nom::combinator::map; use nom::combinator::map;
use nom::combinator::recognize; use nom::combinator::recognize;

View File

@ -1,5 +1,6 @@
mod bold; mod bold;
mod combinator; mod combinator;
mod document;
mod error; mod error;
mod link; mod link;
mod list; mod list;
@ -7,7 +8,7 @@ mod paragraph;
mod parser_context; mod parser_context;
mod parser_with_context; mod parser_with_context;
mod text; mod text;
mod document;
mod token; mod token;
mod util;
pub use document::document; pub use document::document;
type Context<'r, 's> = &'r parser_context::ContextTree<'r, 's>; type Context<'r, 's> = &'r parser_context::ContextTree<'r, 's>;

15
src/parser/util.rs Normal file
View File

@ -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
}